From c9c50a92a0dfa239b1bae059684a100753305eee Mon Sep 17 00:00:00 2001 From: guva-odoo Date: Fri, 15 Dec 2023 17:17:12 +0000 Subject: [PATCH] [FIX] account, analytic: add analytic distribution, remove precompute Related to https://github.com/odoo/enterprise/pull/52648 we add the analytic distributino to the move vals for the exchange diff move. We also remove the precompute on the fields, manual backport of https://github.com/odoo/odoo/commit/b9047febf3c4d67ce409f9f1dba8a9cc7c7165fe opw-3603668 closes odoo/odoo#147332 X-original-commit: 41b38f1dc7df824e6c09e66e293e82f2823915aa Related: odoo/enterprise#53322 Signed-off-by: Habib Ayob (ayh) Signed-off-by: Guillaume Vanleynseele (guva) --- addons/account/models/account_move_line.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index f5c8abdd147..9c96ee36f88 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -2561,7 +2561,7 @@ class AccountMoveLine(models.Model): return partials - def _prepare_exchange_difference_move_vals(self, amounts_list, company=None, exchange_date=None): + def _prepare_exchange_difference_move_vals(self, amounts_list, company=None, exchange_date=None, **kwargs): """ Prepare values to create later the exchange difference journal entry. The exchange difference journal entry is there to fix the debit/credit of lines when the journal items are fully reconciled in foreign currency. @@ -2625,8 +2625,8 @@ class AccountMoveLine(models.Model): exchange_line_account = income_exchange_account sequence = len(move_vals['line_ids']) - move_vals['line_ids'] += [ - Command.create({ + line_vals = [ + { 'name': _('Currency exchange rate difference'), 'debit': -amount_residual if amount_residual < 0.0 else 0.0, 'credit': amount_residual if amount_residual > 0.0 else 0.0, @@ -2635,8 +2635,8 @@ class AccountMoveLine(models.Model): 'currency_id': line.currency_id.id, 'partner_id': line.partner_id.id, 'sequence': sequence, - }), - Command.create({ + }, + { 'name': _('Currency exchange rate difference'), 'debit': amount_residual if amount_residual > 0.0 else 0.0, 'credit': -amount_residual if amount_residual < 0.0 else 0.0, @@ -2645,8 +2645,13 @@ class AccountMoveLine(models.Model): 'currency_id': line.currency_id.id, 'partner_id': line.partner_id.id, 'sequence': sequence + 1, - }), + }, ] + + if kwargs.get('exchange_analytic_distribution'): + line_vals[1].update({'analytic_distribution': kwargs['exchange_analytic_distribution']}) + + move_vals['line_ids'] += [Command.create(vals) for vals in line_vals] to_reconcile.append((line, sequence)) return {'move_values': move_vals, 'to_reconcile': to_reconcile}