Skip to content

Commit

Permalink
Feat: issue credit note on credit invoice - db change (#2676)
Browse files Browse the repository at this point in the history
## Context

Now we don't allow creation of credit notes on prepaid credits. We want
to implement this possibility.
When credits will be issued, we'll be creating a voiding outbound
wallet_transaction. Currently we're tracking the outbound wallet
transactions. To support this behaviour we'll need to add credit_note_id
to the wallet transaction

## Description

Added credit_note_id to wallet_transaction
  • Loading branch information
annvelents authored Oct 14, 2024
1 parent c64d89b commit 849c4d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/models/wallet_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class WalletTransaction < ApplicationRecord
include PaperTrailTraceable

belongs_to :wallet

# these two relationships are populated only for outbound transactions
belongs_to :invoice, optional: true
belongs_to :credit_note, optional: true

STATUSES = [
:pending,
Expand Down Expand Up @@ -53,16 +56,19 @@ class WalletTransaction < ApplicationRecord
# transaction_type :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# credit_note_id :uuid
# invoice_id :uuid
# wallet_id :uuid not null
#
# Indexes
#
# index_wallet_transactions_on_invoice_id (invoice_id)
# index_wallet_transactions_on_wallet_id (wallet_id)
# index_wallet_transactions_on_credit_note_id (credit_note_id)
# index_wallet_transactions_on_invoice_id (invoice_id)
# index_wallet_transactions_on_wallet_id (wallet_id)
#
# Foreign Keys
#
# fk_rails_... (credit_note_id => credit_notes.id)
# fk_rails_... (invoice_id => invoices.id)
# fk_rails_... (wallet_id => wallets.id)
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AddReferenceToCreditNoteFromWalletTransaction < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
add_reference :wallet_transactions, :credit_note, type: :uuid, null: true, index: {algorithm: :concurrently}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddForeignKeyConstraintToCreditNoteIdAtWalletTransaction < ActiveRecord::Migration[7.1]
def change
add_foreign_key :wallet_transactions, :credit_notes, validate: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ChangeValidateOnForeignKeyFromWalletTransactionToCreditNote < ActiveRecord::Migration[7.1]
def change
validate_foreign_key :wallet_transactions, :credit_notes
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 849c4d7

Please sign in to comment.