Skip to content

Commit 6a54348

Browse files
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

File tree

addons/account/models/account_move_line_tax_details.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _get_query_tax_details(self, table_references, search_condition, fallback=Tr
149149
OR (tax.tax_exigibility = 'on_payment' AND tax.cash_basis_transition_account_id IS NOT NULL)
150150
)
151151
AND (
152-
(tax.analytic IS NOT TRUE)
152+
(tax.analytic IS NOT TRUE AND tax_rep.use_in_tax_closing IS TRUE)
153153
OR (base_line.analytic_distribution IS NULL AND account_move_line.analytic_distribution IS NULL)
154154
OR base_line.analytic_distribution = account_move_line.analytic_distribution
155155
)
@@ -399,7 +399,6 @@ def _get_query_tax_details(self, table_references, search_condition, fallback=Tr
399399
tax_line.tax_line_id AS tax_id,
400400
tax_line.group_tax_id,
401401
tax_line.tax_repartition_line_id,
402-
tax_line.analytic_distribution,
403402
404403
tax_line.company_id,
405404
tax_line.display_type AS display_type,
@@ -470,7 +469,6 @@ def _get_query_tax_details(self, table_references, search_condition, fallback=Tr
470469
sub.tax_line_id,
471470
sub.display_type,
472471
sub.src_line_id,
473-
sub.analytic_distribution,
474472
475473
sub.tax_id,
476474
sub.group_tax_id,

0 commit comments

Comments
 (0)