Commit 6a54348
committed
[FIX] account: fix "group By" tax reports with analytics
Issue:
When having two lines on an invoice with the same tax and different analytic distribution, the base value is doubled on the tax report.
Steps to reproduce:
- Create a new taxe on sales (eg 10%)
- Make sure the option "Analytic Accounting" is ticked in the settings
- Create an invoice with a line, add the tax on it and change the analytic distribution
- Do the same for another invoice with another analytic distribution
- Confirm the invoices
- Go to the tax report
- Select the report "Group By: Account > Tax"
- On the report the "Net" amount is only the one of the first invoice, the tax amount is correct
Cause:
The bug appeared after this [commit](odoo-dev/enterprise@9a7142e) which fixed another issue with analytics. Now several lines with the same tax can be returned by the query if they have different analytics.
This was used to avoid having the base amount doubled on the invoice when several lines from the same move had with different analytics: there is a line for each analytic but they all have the same base, in the end the base amounts was doubled for each different analytic. Now the query returns multiple lines but as they all have the same key the base amounts are not added together.
This fixes the previous issue when several lines from the same move but with different analytics were added but it creates another issue when different invoices have the same tax and different analytic because these lines also have the same key. This result in only the base amount of the first invoice to be taken into account.
Solution:
The previous fix was incorrect.
The correct fix is to not join the lines when there are two tax lines.
To do this the [condition](https://github.com/odoo/odoo/blob/cf8d38205c09a2724f41907fa07c5f23ff2d46a3/addons/account/models/account_move_line_tax_details.py#L153) in the query needs to be the same as the [condition](https://github.com/odoo/odoo/blob/cf8d38205c09a2724f41907fa07c5f23ff2d46a3/addons/account/models/account_move_line.py#L984) that will duplicate the lines in python.
The check on `use_in_tax_closing` was missing so we add it.
opw-4766421
closes odoo#220684
X-original-commit: 029a33d
Related: odoo/enterprise#91082
Signed-off-by: Laurent Smet (las) <las@odoo.com>
Signed-off-by: Mathieu Coutant (mcou) <mcou@odoo.com>1 parent 29d01c7 commit 6a54348
1 file changed
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
403 | 402 | | |
404 | 403 | | |
405 | 404 | | |
| |||
470 | 469 | | |
471 | 470 | | |
472 | 471 | | |
473 | | - | |
474 | 472 | | |
475 | 473 | | |
476 | 474 | | |
| |||
0 commit comments