diff --git a/app/models/invoice.rb b/app/models/invoice.rb index ae28071e7..ebc87287b 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -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 diff --git a/lib/tasks/assign_invoices_vat_rate.rake b/lib/tasks/assign_invoices_vat_rate.rake index 1d23c1131..edabfb37c 100644 --- a/lib/tasks/assign_invoices_vat_rate.rake +++ b/lib/tasks/assign_invoices_vat_rate.rake @@ -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