From 704b5b250fda56ec9b71a008dc596eb191287766 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Wed, 27 Mar 2024 20:54:54 +0000 Subject: [PATCH] [FIX] account: analytic_distribution is not reversed Create an invoice with analytic_distribution. Go to account.move.line, select the line with analytic_distribution, click on action 'Move account' validate --> Issue the analytic_distribution is not reversed closes odoo/odoo#161394 X-original-commit: e7f5bfc6a685ec9809c13290d1432888c3aad47c Signed-off-by: Laurent Smet (las) Co-authored-by: Laurent Smet (las) --- .../account/wizard/account_automatic_entry_wizard.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/account/wizard/account_automatic_entry_wizard.py b/addons/account/wizard/account_automatic_entry_wizard.py index d0d7727563b..5f1930f556c 100644 --- a/addons/account/wizard/account_automatic_entry_wizard.py +++ b/addons/account/wizard/account_automatic_entry_wizard.py @@ -7,6 +7,7 @@ from odoo.tools import groupby from collections import defaultdict from markupsafe import Markup, escape +from odoo.tools import frozendict import json class AutomaticEntryWizard(models.TransientModel): @@ -173,7 +174,12 @@ class AutomaticEntryWizard(models.TransientModel): counterpart_balances[(line.partner_id, counterpart_currency)]['amount_currency'] += counterpart_amount_currency counterpart_balances[(line.partner_id, counterpart_currency)]['balance'] += line.balance counterpart_balances[(line.partner_id, counterpart_currency)]['analytic_distribution'] = line.analytic_distribution - grouped_source_lines[(line.partner_id, line.currency_id, line.account_id)] += line + grouped_source_lines[( + line.partner_id, + line.currency_id, + line.account_id, + line.analytic_distribution and frozendict(line.analytic_distribution), + )] += line # Generate counterpart lines' vals for (counterpart_partner, counterpart_currency), counterpart_vals in counterpart_balances.items(): @@ -193,7 +199,7 @@ class AutomaticEntryWizard(models.TransientModel): }) # Generate change_account lines' vals - for (partner, currency, account), lines in grouped_source_lines.items(): + for (partner, currency, account, analytic_distribution), lines in grouped_source_lines.items(): account_balance = sum(line.balance for line in lines) if not self.company_id.currency_id.is_zero(account_balance): account_amount_currency = currency.round(sum(line.amount_currency for line in lines)) @@ -205,6 +211,7 @@ class AutomaticEntryWizard(models.TransientModel): 'partner_id': partner.id or None, 'currency_id': currency.id, 'amount_currency': (account_balance > 0 and -1 or 1) * abs(account_amount_currency), + 'analytic_distribution': analytic_distribution, }) # Get the lowest child company based on accounts used to avoid access error