Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: anrok <> credit_notes model changes #2558

Merged
merged 8 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/credit_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CreditNote < ApplicationRecord
has_many :applied_taxes, class_name: 'CreditNote::AppliedTax', dependent: :destroy
has_many :taxes, through: :applied_taxes
has_many :integration_resources, as: :syncable
has_many :error_details, as: :owner, dependent: :destroy

has_one_attached :file

Expand Down
11 changes: 6 additions & 5 deletions app/models/credit_note/applied_tax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppliedTax < ApplicationRecord
include PaperTrailTraceable

belongs_to :credit_note
belongs_to :tax
belongs_to :tax, optional: true

monetize :amount_cents
monetize :base_amount_cents, with_model_currency: :amount_currency
Expand All @@ -29,13 +29,14 @@ class AppliedTax < ApplicationRecord
# created_at :datetime not null
# updated_at :datetime not null
# credit_note_id :uuid not null
# tax_id :uuid not null
# tax_id :uuid
#
# Indexes
#
# index_credit_notes_taxes_on_credit_note_id (credit_note_id)
# index_credit_notes_taxes_on_credit_note_id_and_tax_id (credit_note_id,tax_id) UNIQUE
# index_credit_notes_taxes_on_tax_id (tax_id)
# index_credit_notes_taxes_on_credit_note_id (credit_note_id)
# index_credit_notes_taxes_on_credit_note_id_and_tax_code (credit_note_id,tax_code) UNIQUE
# index_credit_notes_taxes_on_tax_code (tax_code)
# index_credit_notes_taxes_on_tax_id (tax_id)
#
# Foreign Keys
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ChangeTaxIdNullOnCreditNoteAppliedTaxes < ActiveRecord::Migration[7.1]
def change
change_column_null :credit_notes_taxes, :tax_id, true
end
end
12 changes: 12 additions & 0 deletions db/migrate/20240910111203_update_indexes_for_credit_notes_taxes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

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

def change
remove_index :credit_notes_taxes, %i[credit_note_id tax_id], unique: true, algorithm: :concurrently

add_index :credit_notes_taxes, :tax_code, algorithm: :concurrently
add_index :credit_notes_taxes, %i[credit_note_id tax_code], unique: true, algorithm: :concurrently
end
end
annvelents marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions db/schema.rb

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

5 changes: 5 additions & 0 deletions spec/models/credit_note/applied_tax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
RSpec.describe CreditNote::AppliedTax, type: :model do
subject(:applied_tax) { create(:credit_note_applied_tax) }

describe 'associations' do
it { is_expected.to belong_to(:credit_note) }
it { is_expected.to belong_to(:tax).optional }
end

it_behaves_like 'paper_trail traceable'
end
1 change: 1 addition & 0 deletions spec/models/credit_note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
it_behaves_like 'paper_trail traceable'

it { is_expected.to have_many(:integration_resources) }
it { is_expected.to have_many(:error_details) }

describe 'sequential_id' do
let(:invoice) { create(:invoice) }
Expand Down