Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net amount calculated incorrectly #44219

Open
barredterra opened this issue Nov 19, 2024 · 7 comments · Fixed by #44226 or #44231
Open

Net amount calculated incorrectly #44219

barredterra opened this issue Nov 19, 2024 · 7 comments · Fixed by #44226 or #44231
Assignees
Labels

Comments

@barredterra
Copy link
Collaborator

barredterra commented Nov 19, 2024

Information about bug

On a Sales Invoice containing items with different tax rates, the tax net amount is not calculated correctly.

Item Tax Template "7 %":

item_tax_templat_7

Item Tax Template "19 %":

item_tax_tenplate_19

Sales Invoice:

sales_invoice

Expected: The net amount per tax row is displayed as 100.
Actual: The net amount per tax row is displayed as 200.

Module

accounts

Version

develop

Installation method

None

Relevant log output / Stack trace / Full Error Message.

Likely introduced by #43372

@barredterra barredterra changed the title Net rate calculated incorrectly Net amount calculated incorrectly Nov 19, 2024
@blaggacao
Copy link
Collaborator

blaggacao commented Nov 19, 2024

Investigating...

At least item_wise_tax_detail is correct.

In [4]: for t in si.taxes:
   ...:     print(t.net_amount, t.item_wise_tax_detail)
   ...:
18403.36 {"ALMBOT1050": {"tax_rate": 19.0, "tax_amount": 1596.64, "net_amount": 8403.36}, "ARAN500": {"tax_rate": 0.0, "tax_amount": 0.0, "net_amount": 10000.0}}
18403.36 {"ALMBOT1050": {"tax_rate": 0.0,  "tax_amount": 0.0,     "net_amount": 8403.36}, "ARAN500": {"tax_rate": 0.0, "tax_amount": 0.0, "net_amount": 10000.0}}

With a new logger the issue becomes clearer:

2024-11-19 15:16:35,518 DEBUG erpnext.controllers.taxes_and_totals Item 0 - ALMBOT1050
2024-11-19 15:16:35,518 DEBUG erpnext.controllers.taxes_and_totals   Tax/Charge 0 - IVA @ 19
2024-11-19 15:16:35,519 DEBUG erpnext.controllers.taxes_and_totals   INIT : net_amount: 16806.722689075632   tax_amount: 3193.27731092437
2024-11-19 15:16:35,519 DEBUG erpnext.controllers.taxes_and_totals   FINAL: net_amount: 16806.72             tax_amount: 3193.28
2024-11-19 15:16:35,519 DEBUG erpnext.controllers.taxes_and_totals   Tax/Charge 1 - 240805 - IVA Descontable
2024-11-19 15:16:35,521 DEBUG erpnext.controllers.taxes_and_totals   INIT : net_amount: 16806.722689075632   tax_amount: 0.0
2024-11-19 15:16:35,521 DEBUG erpnext.controllers.taxes_and_totals   FINAL: net_amount: 16806.72             tax_amount: 0.0
2024-11-19 15:16:35,521 DEBUG erpnext.controllers.taxes_and_totals   Tax/Charge 2 - Gastos de personal (fijo)
2024-11-19 15:16:35,521 DEBUG erpnext.controllers.taxes_and_totals   INIT : net_amount: 16806.722689075632   tax_amount: 10.071942677915228
2024-11-19 15:16:35,521 DEBUG erpnext.controllers.taxes_and_totals   FINAL: net_amount: 16806.72             tax_amount: 10.07
2024-11-19 15:16:35,522 DEBUG erpnext.controllers.taxes_and_totals Item 1 - ARAN500
2024-11-19 15:16:35,522 DEBUG erpnext.controllers.taxes_and_totals   Tax/Charge 0 - IVA @ 19
2024-11-19 15:16:35,522 DEBUG erpnext.controllers.taxes_and_totals   INIT : net_amount: 100000.0             tax_amount: 0.0
2024-11-19 15:16:35,523 DEBUG erpnext.controllers.taxes_and_totals   FINAL: net_amount: 100000.0             tax_amount: 0.0
2024-11-19 15:16:35,525 DEBUG erpnext.controllers.taxes_and_totals   Tax/Charge 1 - 240805 - IVA Descontable
2024-11-19 15:16:35,525 DEBUG erpnext.controllers.taxes_and_totals   INIT : net_amount: 100000.0             tax_amount: 0.0
2024-11-19 15:16:35,525 DEBUG erpnext.controllers.taxes_and_totals   FINAL: net_amount: 100000.0             tax_amount: 0.0
2024-11-19 15:16:35,525 DEBUG erpnext.controllers.taxes_and_totals   Tax/Charge 2 - Gastos de personal (fijo)
2024-11-19 15:16:35,525 DEBUG erpnext.controllers.taxes_and_totals   INIT : net_amount: 100000.0             tax_amount: 59.9280589335956
2024-11-19 15:16:35,526 DEBUG erpnext.controllers.taxes_and_totals   FINAL: net_amount: 100000.0             tax_amount: 59.93

blaggacao added a commit to blaggacao/erpnext that referenced this issue Nov 19, 2024
this clarification is a human precondition to being able to fix frappe#44219
blaggacao added a commit to blaggacao/erpnext that referenced this issue Nov 19, 2024
this clarification is a human precondition to being able to fix frappe#44219
blaggacao added a commit to blaggacao/erpnext that referenced this issue Nov 19, 2024
this clarification is a human precondition to being able to fix frappe#44219
blaggacao added a commit to blaggacao/erpnext that referenced this issue Nov 19, 2024
this clarification is a human precondition to being able to fix frappe#44219
blaggacao added a commit to blaggacao/erpnext that referenced this issue Nov 19, 2024
this clarification is a human precondition to being able to fix frappe#44219
@blaggacao blaggacao reopened this Nov 19, 2024
@barredterra
Copy link
Collaborator Author

@blaggacao as far as I can tell, this issue is still unresolved:

Bildschirmfoto 2024-12-03 um 19 56 41

@barredterra barredterra reopened this Dec 3, 2024
@blaggacao
Copy link
Collaborator

blaggacao commented Dec 3, 2024

Hm, that is strange, indeed. There's an edge case that I had noted when the Account coincides in which case the attribution wasn't done correctly, but for different accounts this should have worked.

Just to confirm: this is the value after (re-)saving? Or maybe a temporary client-js calculated value?

@barredterra
Copy link
Collaborator Author

Yes, that's after saving and reloading. The tax accounts are different from each other.

@blaggacao
Copy link
Collaborator

blaggacao commented Dec 4, 2024

@barredterra I noticed that an Item, even if it only is eligible for 1776 has all tax set (the 0 value rate is not a niller here) in their item_tax_map.

Based on the presence of the key, they are ("correctly") summed into the net amount, later on. If of any help, we could test the value for null / None respectively and interpret these value as nillers in case there's a reason (which I can't see yet) to keep the keys in that dictionary.

image

The same pattern is seen in the backend debug logs after save.

==> erpnext.controllers.taxes_and_totals.log <==
2024-12-04 13:55:53,720 DEBUG erpnext.controllers.taxes_and_totals Sales Invoice (ACC-SINV-2024-00006) ...
2024-12-04 13:55:53,720 DEBUG erpnext.controllers.taxes_and_totals  Item 0: SKU001 - {'1776 - Umsatzsteuer 19 % - TCD': 19.0, '1771 - Umsatzsteuer 7 % - TCD': 0.0, '1774 - Umsatzsteuer aus innergemeinschaftlichem Erwerb 19 % - TCD': 19.0, '1772 - Umsatzsteuer aus innergemeinschaftlichem Erwerb - TCD': 0.0, '1787 - Umsatzsteuer nach § 13b UStG 19 % - TCD': 19.0, '1785 - Umsatzsteuer nach § 13b UStG - TCD': 0.0, '1576 - Abziehbare Vorsteuer 19 % - TCD': 19.0, '1571 - Abziehbare Vorsteuer 7 % - TCD': 0.0, '1574 - Abziehbare Vorsteuer aus innergemeinschaftlichem Erwerb 19 % - TCD': 19.0, '1572 - Abziehbare Vorsteuer aus innergemeinschaftlichem Erwerb - TCD': 0.0, '1577 - Abziehbare Vorsteuer nach § 13b UStG 19 % - TCD': 19.0, '1541 - Abziehbare Vorsteuer nach § 13b UStG - TCD': 0.0, '1588 - Entstandene Einfuhrumsatzsteuer - TCD': 19.0}
2024-12-04 13:55:53,727 DEBUG erpnext.controllers.taxes_and_totals   net_amount: 1000.0               tax_amount: 190.0                - Umsatzsteuer 19 %
2024-12-04 13:55:53,732 DEBUG erpnext.controllers.taxes_and_totals   net_amount: 1000.0               tax_amount: 0.0                  - Umsatzsteuer 7 %

@barredterra
Copy link
Collaborator Author

There is no way to set a tax as not applicable, apart from setting it to zero. So the dict should likely only contain accounts where the applicable rate is not 0 for the respective item.

@blaggacao
Copy link
Collaborator

blaggacao commented Dec 4, 2024

So the dict should likely only contain accounts where the applicable rate is not 0 for the respective item.

That in turn is unfortunately not possible, because 0 is a legitimate and meaningful tax rate distinct from "no tax at all".

There is no way to set a tax as not applicable, apart from setting it to zero

I looked into the DE setup and it was genuinely news to me that the system could be used in such a way, but I can see how this is a useful feature to filter taxes based on the document's general tax template.

This feature also seems to be the true semantic meaning behind disabling the Account setting "append item taxes to tax table".

Since it is, in essence an overlay data structure that was chosen to implement the feature, nil values become inherently significant. Their absence is a design flaw and shortcoming in the original implementation of that feature.

I'd suggest to modify the tax templates tables to add a check which signifies a nil value — potentially visible only if the respective accounting setting is disabled. When taxes from such templates are then assembled, this checkmark could cause them to be represented properly as nil values. Alternatively, a special sentinel value can be used (e.g. -1), but I could not think of one that is not also a legitimate rate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants