Merge pull request #2640 from internetee/new-vat-rate-overwrite-old-one

new vat rate overwrite olds one in e-invoice
This commit is contained in:
Timo Võhmar 2024-01-18 17:59:58 +02:00 committed by GitHub
commit 84ba938847
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 6 deletions

2
.gitignore vendored
View file

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

View file

@ -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

View file

@ -99,7 +99,7 @@ class Registrar < ApplicationRecord # rubocop:disable Metrics/ClassLength
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 @@ class Registrar < ApplicationRecord # rubocop:disable Metrics/ClassLength
!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: [])