new vat rate overwrite olds one in e-invoice

This commit is contained in:
Oleg Hasjanov 2024-01-12 09:42:29 +02:00
parent bd12a73898
commit 209bfb6715
3 changed files with 11 additions and 6 deletions

2
.gitignore vendored
View file

@ -17,3 +17,5 @@
.rubocop.yml .rubocop.yml
/lib/tasks/mock.rake /lib/tasks/mock.rake
.DS_Store
/node_modules

View file

@ -1,15 +1,18 @@
class Invoice class Invoice
class VatRateCalculator 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 @registry = registry
@registrar = registrar @registrar = registrar
@current_year = current_year
end end
def calculate def calculate
if registrar.vat_liable_locally?(registry) if registrar.vat_liable_locally?(registry)
registry.vat_rate current_year > 2023 ? registry.vat_rate : OLD_VAT_RATE
else else
registrar.vat_rate || 0 registrar.vat_rate || 0
end end

View file

@ -99,7 +99,7 @@ class Registrar < ApplicationRecord # rubocop:disable Metrics/ClassLength
buyer_email: billing_email, buyer_email: billing_email,
buyer_vat_no: vat_no, buyer_vat_no: vat_no,
reference_no: reference_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, monthly_invoice: true,
metadata: { items: remove_line_duplicates(summary['invoice_lines']) }, metadata: { items: remove_line_duplicates(summary['invoice_lines']) },
total: 0 total: 0
@ -325,8 +325,8 @@ class Registrar < ApplicationRecord # rubocop:disable Metrics/ClassLength
!vat_liable_locally? !vat_liable_locally?
end end
def calculate_vat_rate def calculate_vat_rate(current_year: Time.zone.today.year)
::Invoice::VatRateCalculator.new(registrar: self).calculate ::Invoice::VatRateCalculator.new(registrar: self, current_year: current_year).calculate
end end
def remove_line_duplicates(invoice_lines, lines: []) def remove_line_duplicates(invoice_lines, lines: [])