Skip to content

Commit

Permalink
[FIX] l10n_it_reverse_charge: force amount_currency set in line values
Browse files Browse the repository at this point in the history
  • Loading branch information
odooNextev committed Jun 27, 2024
1 parent b1439cd commit 643222f
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions l10n_it_reverse_charge/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(

Check warning on line 190 in l10n_it_reverse_charge/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_reverse_charge/models/account_move.py#L190

Added line #L190 was not covered by tests
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."""
Expand All @@ -199,14 +201,15 @@ 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,
"credit": credit,
"debit": debit,
"account_id": account.id,
"currency_id": self.currency_id.id,
"amount_currency": amount_currency,
}

def _rc_credit_line_amounts(self, amount):
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -277,6 +284,7 @@ def _prepare_rc_supplier_invoice_payment(self, rc_invoice, rc_type):
line_to_reconcile = self._rc_get_move_line_to_reconcile()
payment_debit_line_data = self.rc_debit_line_vals(
line_to_reconcile.account_id,
-payment_credit_line_data["amount_currency"],
payment_credit_line_data["credit"],
)
rc_payment_data["line_ids"] = [
Expand Down Expand Up @@ -318,15 +326,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"] = [
Expand Down

0 comments on commit 643222f

Please sign in to comment.