From 4f624a3beadaf0fab6a586c30724352b118e898d Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 12 Jan 2024 09:42:29 +0200 Subject: [PATCH] new vat rate overwrite olds one in e-invoice --- .gitignore | 2 ++ app/models/invoice/vat_rate_calculator.rb | 9 ++++++--- app/models/registrar.rb | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index fe13542d1e..decbcede31 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ .rubocop.yml /lib/tasks/mock.rake +.DS_Store +/node_modules \ No newline at end of file diff --git a/app/models/invoice/vat_rate_calculator.rb b/app/models/invoice/vat_rate_calculator.rb index e09dcad0c0..80c0f7edb7 100644 --- a/app/models/invoice/vat_rate_calculator.rb +++ b/app/models/invoice/vat_rate_calculator.rb @@ -1,15 +1,18 @@ class Invoice class VatRateCalculator - attr_reader :registry, :registrar + OLD_VAT_RATE = 20.0 - def initialize(registry: Registry.current, registrar:) + attr_reader :registry, :registrar, :current_year + + def initialize(registry: Registry.current, current_year: Time.zone.today.year, registrar:) @registry = registry @registrar = registrar + @current_year = current_year end def calculate if registrar.vat_liable_locally?(registry) - registry.vat_rate + current_year >= 2023 ? registry.vat_rate : OLD_VAT_RATE else registrar.vat_rate || 0 end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 71dddaa7f7..540b2d4792 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -99,7 +99,7 @@ def init_monthly_invoice(summary) buyer_email: billing_email, buyer_vat_no: vat_no, reference_no: reference_no, - vat_rate: calculate_vat_rate, + vat_rate: calculate_vat_rate(current_year: summary['date'].to_date.year), monthly_invoice: true, metadata: { items: remove_line_duplicates(summary['invoice_lines']) }, total: 0 @@ -325,8 +325,8 @@ def vat_liable_in_foreign_country? !vat_liable_locally? end - def calculate_vat_rate - ::Invoice::VatRateCalculator.new(registrar: self).calculate + def calculate_vat_rate(current_year: Time.zone.today.year) + ::Invoice::VatRateCalculator.new(registrar: self, current_year: current_year).calculate end def remove_line_duplicates(invoice_lines, lines: [])