mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
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:
commit
84ba938847
3 changed files with 11 additions and 6 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -17,3 +17,5 @@
|
|||
.rubocop.yml
|
||||
/lib/tasks/mock.rake
|
||||
|
||||
.DS_Store
|
||||
/node_modules
|
|
@ -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
|
||||
|
|
|
@ -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: [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue