Skip to content

Commit

Permalink
allowed recalculate tax only for payable invoices, updated rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Hasjanov authored and Oleg Hasjanov committed Jan 3, 2024
1 parent 6c41256 commit cc610a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def deposit

def recalculate_vat_rate
return if billing_profile_id == billing_profile_id_was
return unless payable?

self.vat_rate = assign_vat_rate
end
Expand Down
8 changes: 4 additions & 4 deletions lib/tasks/assign_invoices_vat_rate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace :invoices do
batch_invoices.where('created_at >= ?', '2024-01-01').update_all(vat_rate: 0.22)
end

Invoice.where(vat_rate: nil).where.not(vat_code: nil).in_batches do |batch_invoices|
batch_invoices.update_all(vat_rate: 0.0)
end

Invoice.where.not(country_code: 'EE').where(vat_rate: nil).in_batches do |batch_invoices|
batch_invoices.each do |invoice|
invoice.update(vat_rate: Countries.vat_rate_from_alpha2_code(invoice.country_code))
end
end

Invoice.where(vat_rate: nil).where.not(vat_code: nil).in_batches do |batch_invoices|
batch_invoices.update_all(vat_rate: 0.0)
end
end
end

0 comments on commit cc610a1

Please sign in to comment.