From 255c63ff26369d490be7cb53635006cc0fe18c93 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Wed, 28 Apr 2021 09:01:49 +0000 Subject: [PATCH] [FIX] account: cash basis taxes: generate correct exchange difference when using the same cash basis taxes on multiple lines To reproduce the bug: 1) Create a cash basis tax for 42% 2) Make an invoice with two lines at 100$, each using this tax 3) Post and register full payment of the invoice ==> An exchange difference has been generated, doing +100 -100. One of its two line has tax_ids set, while the other does not. This makes the base amount shown in the generic tax report wrong: 100 instead of 200. Actually, this exchange difference entry shouldn't have existed in the first place, as there is no rounding issue to compensate for here. It happens because the grouping keys computed for the two base lines are the same, and the second line overwrites the totals of the first one instead of adding them to its own. closes odoo/odoo#70283 X-original-commit: 60770f0b99bedd3dcb695e2191dc83c45ef0b594 Related: odoo/enterprise#18107 Signed-off-by: Laurent Smet Signed-off-by: oco-odoo --- addons/account/models/account_move.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index c3a372b2509..023b64404dd 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -4546,10 +4546,17 @@ class AccountMoveLine(models.Model): continue grouping_key = self.env['account.partial.reconcile']._get_cash_basis_base_line_grouping_key_from_record(line, account=account_to_fix) - account_vals_to_fix[grouping_key] = { - **vals, - 'account_id': account_to_fix.id, - } + + if grouping_key not in account_vals_to_fix: + account_vals_to_fix[grouping_key] = { + **vals, + 'account_id': account_to_fix.id, + } + else: + # Multiple base lines could share the same key, if the same + # cash basis tax is used alone on several lines of the invoices + account_vals_to_fix[grouping_key]['debit'] += vals['debit'] + account_vals_to_fix[grouping_key]['credit'] += vals['credit'] # ========================================================================== # Subtract the balance of all previously generated cash basis journal entries