Fix: adjust tax precise amount when issuing credit notes #2643
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
We have this issue that when we issue Invoice, we apply tax on sum of items,
but when we issue a credit note, we apply tax on each item separately.
as result, some values can be rounded in deffirent direction which result in not matching sum.
Example that our client had (all values are amount_cents):
if we apply 20% taxes on the sum of charges, we get:
but because it is in cents, when issuing the invoice, the value is rounded to
334_99
Next, when we create credit notes for this invoice, and we create a separate CN per each item:
Sum of these credit notes is
335_00
which is more than the invoice total, and we fail vthe validation, despite the fees amount is correctDescription
To help this situation, we can operate adjustments that were made when credit notes are issued.
So when we're creating CN1-3, we simply create credit notes.
when we create CN4, we are subtracting all rounding adjustments that were made for all credit notes for this invoice. in our case, we will need to subtract
0.4
cents from precise taxes amount, and then for the last credit noteCN04 = 68_33 * 1.2 = 8199.6 -0.4 = 8199.2 => 8199
and the values are matching
also removed validation on credit_note_item total amount, as it tries to predict taxes, but they are adjusted further in the credit note creation service