From 7a0c5bfc2cc816875ca2b6f7870406419f29e92b Mon Sep 17 00:00:00 2001 From: odooNextev Date: Thu, 27 Jun 2024 16:20:26 +0200 Subject: [PATCH] [FIX] l10n_it_reverse_charge: force amount_currency set in line values --- l10n_it_reverse_charge/models/account_move.py | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/l10n_it_reverse_charge/models/account_move.py b/l10n_it_reverse_charge/models/account_move.py index 3eb7d884f729..3b2184eb5bbc 100644 --- a/l10n_it_reverse_charge/models/account_move.py +++ b/l10n_it_reverse_charge/models/account_move.py @@ -3,6 +3,7 @@ # Copyright 2017 Lorenzo Battistini - Agile Business Group # Copyright 2017 Marco Calcagni - Dinamiche Aziendali srl # Copyright 2023 Simone Rubino - TAKOBI +# Copyright 2024 Nextev Srl from odoo import api, fields, models from odoo.exceptions import UserError @@ -180,16 +181,17 @@ def compute_rc_amount_tax_main_currency(self): The result is converted and rounded based on Company Currency because this value is used for credit/debit. """ - rc_tax_amount = self.get_tax_amount_added_for_rc() + rc_tax_amount_ic = self.get_tax_amount_added_for_rc() + rc_tax_amount_cc = 0 invoice_currency = self.currency_id company_currency = self.company_currency_id if invoice_currency != company_currency: - rc_tax_amount = invoice_currency._convert( - rc_tax_amount, company_currency, self.company_id, self.invoice_date + rc_tax_amount_cc = invoice_currency._convert( + rc_tax_amount_ic, company_currency, self.company_id, self.invoice_date ) - return rc_tax_amount + return rc_tax_amount_ic, rc_tax_amount_cc def rc_payment_vals(self, rc_type): """Values for the RC Payment Move.""" @@ -199,7 +201,7 @@ def rc_payment_vals(self, rc_type): "date": self.date, } - def _rc_line_values(self, account, credit, debit): + def _rc_line_values(self, account, credit, debit, amount_currency): """Base Values for the RC Payment Move lines.""" return { "name": self.name, @@ -207,6 +209,7 @@ def _rc_line_values(self, account, credit, debit): "debit": debit, "account_id": account.id, "currency_id": self.currency_id.id, + "amount_currency": amount_currency, } def _rc_credit_line_amounts(self, amount): @@ -230,7 +233,9 @@ def rc_payment_credit_line_vals(self, line_to_reconcile): ) account = line_to_reconcile.account_id - line_values = self._rc_line_values(account, credit, debit) + line_values = self._rc_line_values( + account, credit, debit, -line_to_reconcile.amount_currency + ) line_values.update( { "partner_id": self.partner_id.id, @@ -244,16 +249,18 @@ def rc_payment_debit_line_vals(self, line_to_reconcile, account): abs(line_to_reconcile.balance), ) - line_values = self._rc_line_values(account, credit, debit) + line_values = self._rc_line_values( + account, credit, debit, line_to_reconcile.amount_currency + ) return line_values - def rc_credit_line_vals(self, account, amount): - credit, debit = self._rc_credit_line_amounts(amount) - return self._rc_line_values(account, credit, debit) + def rc_credit_line_vals(self, account, amount_ic, amount_cc): + credit, debit = self._rc_credit_line_amounts(amount_cc) + return self._rc_line_values(account, credit, debit, -amount_ic) - def rc_debit_line_vals(self, account, amount): - credit, debit = self._rc_debit_line_amounts(amount) - line_values = self._rc_line_values(account, credit, debit) + def rc_debit_line_vals(self, account, amount_ic, amount_cc): + credit, debit = self._rc_debit_line_amounts(amount_cc) + line_values = self._rc_line_values(account, credit, debit, amount_ic) line_values.update( { "partner_id": self.partner_id.id, @@ -318,15 +325,17 @@ def _prepare_rc_invoice_payment(self, rc_invoice, rc_type): ) # Lines to be reconciled with the original supplier Invoice (self) - rc_tax_amount = self.compute_rc_amount_tax_main_currency() + rc_tax_amount_ic, rc_tax_amount_cc = self.compute_rc_amount_tax_main_currency() payment_credit_line_data = self.rc_credit_line_vals( rc_type.transitory_account_id, - rc_tax_amount, + rc_tax_amount_ic, + rc_tax_amount_cc, ) line_to_reconcile = self._rc_get_move_line_to_reconcile() payment_debit_line_data = self.rc_debit_line_vals( line_to_reconcile.account_id, - rc_tax_amount, + rc_tax_amount_ic, + rc_tax_amount_cc, ) rc_payment_data["line_ids"] = [