internetee / auction_center

Estonian Internet Foundation's software for auctioning domain names
Other
6 stars 4 forks source link

changed vat rate calculation logic #1194

Closed OlegPhenomenon closed 8 months ago

OlegPhenomenon commented 9 months ago

What does this PR address?

The issue here is related to the method override of the vat_rate column in the invoice table. It is expected that each invoice will have its unique vat_rate depending on the country associated with the user's billing profile, whether the user is an organization or an individual. However, due to the presence of the vat_rate method in the invoice model's code, it overrides the existing column, preventing data from being stored in the column and making the values dynamic. Additionally, since the Estonian income tax has been changed, these tax rate changes would also affect old invoices created before 2024.

To resolve this, it is necessary to eliminate this method and ensure that each invoice stores its own value so that changes in the tax rate do not affect old invoices.

What do I need to know? In this PR, I have also included a rake task that allows you to go through all the accounts that do not have a vat rate and assign them a value. Ideally, this should be a separate PR and I will make it, because first the commands that assign the necessary values for the accounts are executed, and only then the current PR is deployed in production. This will help avoid errors, but for testing purposes, to simplify this PR, it also includes such a command: rake invoices:assign_invoices_vat_rate

What does this command do?

How to test?

vohmar commented 8 months ago

if billing profile country code is EE and invoice date is less than 2024 then vat_rate must always be 0,2. Currently all Estonian companies get vat_rate of 0,0 that is incorrect.

In one instance 0,0 rate was set on invoice with EE billing profile but no VAT code. This result is inconsistent with other results, but not sure what is different here (invoice id 284, billing profile id 3) @ staging other invoices with with the same billing profile have the same issue