diff --git a/l10n_it_fatturapa_out/data/invoice_it_template.xml b/l10n_it_fatturapa_out/data/invoice_it_template.xml
index c287439a9e5e..b0fe256a25c4 100644
--- a/l10n_it_fatturapa_out/data/invoice_it_template.xml
+++ b/l10n_it_fatturapa_out/data/invoice_it_template.xml
@@ -170,7 +170,7 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
t-call="l10n_it_fatturapa_out.account_invoice_line_it_sconto_maggiorazione"
/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-->
diff --git a/l10n_it_fatturapa_out/wizard/efattura.py b/l10n_it_fatturapa_out/wizard/efattura.py
index 3d31918c1195..a891db5f7e12 100644
--- a/l10n_it_fatturapa_out/wizard/efattura.py
+++ b/l10n_it_fatturapa_out/wizard/efattura.py
@@ -33,6 +33,15 @@ def format_numbers(number):
return float_repr(number, max(2, len(cents)))
+def fpaToEur(amount, invoice, euro, rate=None):
+ currency = invoice.currency_id
+ if currency == euro:
+ return amount
+ elif rate is not None:
+ return amount * (1 / rate)
+ return currency._convert(amount, euro, invoice.company_id, invoice.date, False)
+
+
class EFatturaOut:
def get_template_values(self): # noqa: C901
"""Prepare values and helper functions for the template"""
@@ -78,7 +87,7 @@ def format_price(line, sign=1, original_currency=False):
# force EUR unless we want the original currency
if not original_currency:
- res = fpa_to_eur(res, line.move_id)
+ res = fpa_to_eur(res, line.move_id, line.currency_rate)
# XXX arrotondamento?
res = "{prezzo:.{precision}f}".format(
@@ -207,14 +216,9 @@ def get_payments(invoice):
wiz = self.env["wizard.export.fatturapa"]
return wiz.getPayments(invoice)
- def fpa_to_eur(amount, invoice):
- currency = invoice.currency_id
+ def fpa_to_eur(amount, invoice, rate=None):
euro = self.env.ref("base.EUR")
- if currency == euro:
- return amount
- return currency._convert(
- amount, euro, invoice.company_id, invoice.date, False
- )
+ return fpaToEur(amount, invoice, euro, rate)
if self.partner_id.commercial_partner_id.is_pa:
# check value code
diff --git a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
index 7278efd7f70c..1dcc0e640744 100644
--- a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
+++ b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
@@ -17,7 +17,7 @@
from odoo.addons.l10n_it_account.tools.account_tools import encode_for_export
-from .efattura import EFatturaOut, format_numbers
+from .efattura import EFatturaOut, format_numbers, fpaToEur
_logger = logging.getLogger(__name__)
@@ -87,12 +87,13 @@ def getPayments(self, invoice):
values w/o altering the original lines"""
class _Payment:
- __slots__ = "date_maturity", "amount_currency", "debit"
+ __slots__ = "date_maturity", "amount_currency", "debit", "currency_rate"
- def __init__(self, date_maturity, amount_currency, debit):
+ def __init__(self, date_maturity, amount_currency, debit, currency_rate):
self.date_maturity = date_maturity
self.amount_currency = amount_currency
self.debit = debit
+ self.currency_rate = currency_rate
payments = []
for line in invoice.line_ids.filtered(
@@ -100,7 +101,12 @@ def __init__(self, date_maturity, amount_currency, debit):
in ("asset_receivable", "liability_payable")
):
payments.append(
- _Payment(line.date_maturity, line.amount_currency, line.debit)
+ _Payment(
+ line.date_maturity,
+ line.amount_currency,
+ line.debit,
+ line.currency_rate,
+ )
)
return payments
@@ -131,6 +137,7 @@ def getAllTaxes(self, invoice):
def _key(tax_id):
return tax_id.id
+ euro = self.env.ref("base.EUR")
out_computed = {}
# existing tax lines
tax_ids = invoice.line_ids.filtered(lambda line: line.tax_line_id)
@@ -170,7 +177,9 @@ def _key(tax_id):
"AliquotaIVA": aliquota,
"Natura": tax_id.kind_id.code,
# 'Arrotondamento':'',
- "ImponibileImporto": line.price_subtotal,
+ "ImponibileImporto": fpaToEur(
+ line.price_subtotal, invoice, euro, rate=line.currency_rate
+ ),
"Imposta": 0.0,
"EsigibilitaIVA": tax_id.payability,
}
@@ -179,7 +188,9 @@ def _key(tax_id):
tax_id.law_reference, 100
)
else:
- out[key]["ImponibileImporto"] += line.price_subtotal
+ out[key]["ImponibileImporto"] += fpaToEur(
+ line.price_subtotal, invoice, euro, rate=line.currency_rate
+ )
out[key]["Imposta"] += 0.0
out.update(out_computed)
return out
diff --git a/l10n_it_fatturapa_out_oss/data/invoice_it_template.xml b/l10n_it_fatturapa_out_oss/data/invoice_it_template.xml
index 1507f819a8c3..844f94bbc5ef 100644
--- a/l10n_it_fatturapa_out_oss/data/invoice_it_template.xml
+++ b/l10n_it_fatturapa_out_oss/data/invoice_it_template.xml
@@ -26,7 +26,7 @@
t-out="tax_data['Natura']"
/>
0.00
- format_monetary(fpa_to_eur(get_sign(record) * tax_data['ImponibileImporto'], record), euro)
+ format_monetary(get_sign(record) * tax_data['ImponibileImporto'], euro)
@@ -66,7 +66,7 @@
- format_monetary(fpa_to_eur(get_sign(line.move_id) * line.price_subtotal, record), euro)
+ format_monetary(fpa_to_eur(get_sign(line.move_id) * line.price_subtotal, record, line.currency_rate), euro)