-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1194 from internetee/refactor-vat-rate-logic
changed vat rate calculation logic
- Loading branch information
Showing
7 changed files
with
138 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace :invoices do | ||
desc 'Assign vat rate to invoices what have vat rate of nil' | ||
task assign_invoices_vat_rate: :environment do | ||
Invoice.where(vat_rate: [nil, 0.0], country_code: 'EE').in_batches do |batch_invoices| | ||
batch_invoices.where('created_at < ?', '2024-01-01').update_all(vat_rate: 0.2) | ||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters