Skip to content

Commit

Permalink
Merge pull request #2640 from internetee/new-vat-rate-overwrite-old-one
Browse files Browse the repository at this point in the history
new vat rate overwrite olds one in e-invoice
  • Loading branch information
vohmar authored Jan 18, 2024
2 parents 7a9bdfb + 209bfb6 commit 84ba938
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
.rubocop.yml
/lib/tasks/mock.rake

.DS_Store
/node_modules
9 changes: 6 additions & 3 deletions app/models/invoice/vat_rate_calculator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/models/registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: [])
Expand Down

0 comments on commit 84ba938

Please sign in to comment.