Skip to content

Commit

Permalink
FIX l10n_it_fatturapa_out and l10n_it_fatturapa_out_rc avoiding to co…
Browse files Browse the repository at this point in the history
…nvert to EUR tax_base_amount as it is already in company currency (currency_field='company_currency_id')

Note: tests are not using tax_base_amount to compute ImponibileImporto (they use line.price_subtotal) because it is empty, while it sould not

Steps:

 - Configure reverse charge for extra UE suppliers
 - Create an USD invoice, with 1 line,  with fiscal position for extra UE suppliers
 - Confirm
 - Generate XML from self invocie

Observed: "Totale imponibile" is different from "Prezzo unitario"

FIX l10n_it_fatturapa_out_rc in multi currency: use the supplier invoice date

REF fpa_to_eur using move line currency_rate when available
  • Loading branch information
eLBati committed Feb 27, 2024
1 parent 3377cc3 commit 752d3f9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
29 changes: 4 additions & 25 deletions l10n_it_fatturapa_out/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
<PrezzoTotale
t-out="format_monetary(fpa_to_eur(line.price_subtotal, record), euro)"
t-out="format_monetary(fpa_to_eur(line.price_subtotal, record, line.currency_rate), euro)"
/>
<AliquotaIVA
t-if="not line_is_section_note"
Expand Down Expand Up @@ -219,27 +219,6 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
</DettaglioLinee>
</template>

<template id="account_invoice_line_it_dati_riepilogo">
<t t-set="tax" t-value="tax_line.tax_line_id" />
<DatiRiepilogo>
<!--2.2.2-->
<AliquotaIVA t-out="format_numbers(tax.amount)" />
<Natura t-if="tax.kind_id.code" t-out="tax.kind_id.code" />
<!-- <SpeseAccessorie t-out=""/>-->
<!-- <Arrotondamento t-out=""/>-->
<ImponibileImporto
t-out="format_monetary(fpa_to_eur(tax_line.tax_base_amount, record), euro)"
/>
<Imposta
t-out="format_monetary(fpa_to_eur(tax_line.price_total, record), euro)"
/>
<EsigibilitaIVA t-if="tax.payability" t-out="tax.payability" />
<RiferimentoNormativo
t-if="tax.law_reference"
t-out="encode_for_export(tax.law_reference, 100)"
/>
</DatiRiepilogo>
</template>
<template id="account_invoice_it_FatturaPA_sede">
<t t-set="indirizzo"><t
t-if="partner_id.street2"
Expand Down Expand Up @@ -599,10 +578,10 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
<!-- <SpeseAccessorie t-out=""/>-->
<!-- <Arrotondamento t-out=""/>-->
<ImponibileImporto
t-out="format_monetary(fpa_to_eur(tax_data['ImponibileImporto'], record), euro)"
t-out="format_monetary(tax_data['ImponibileImporto'], euro)"
/>
<Imposta
t-out="format_monetary(fpa_to_eur(tax_data['Imposta'], record), euro)"
t-out="format_monetary(tax_data['Imposta'], euro)"
/>
<EsigibilitaIVA
t-if="tax_data.get('EsigibilitaIVA', False)"
Expand Down Expand Up @@ -647,7 +626,7 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
/>
<ImportoPagamento
t-if="not record.company_id.xml_divisa_value == 'keep_orig'"
t-out="format_numbers_two(fpa_to_eur(payment.amount_currency or payment.debit, record))"
t-out="format_numbers_two(fpa_to_eur(payment.amount_currency or payment.debit, record, payment.currency_rate))"
/>

<!-- <CodUfficioPostale t-out=""/>-->
Expand Down
20 changes: 12 additions & 8 deletions l10n_it_fatturapa_out/wizard/efattura.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
23 changes: 17 additions & 6 deletions l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -87,20 +87,26 @@ 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(
lambda line: line.account_id.account_type
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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_oss/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
t-out="tax_data['Natura']"
/>
<ImponibileImporto
t-out="format_monetary(fpa_to_eur(tax_data['ImponibileImporto'], record), euro)"
t-out="format_monetary(tax_data['ImponibileImporto'], euro)"
/>
<Imposta>0.00</Imposta>
<EsigibilitaIVA
Expand Down
4 changes: 2 additions & 2 deletions l10n_it_fatturapa_out_rc/views/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</xpath>
<xpath expr="//DatiRiepilogo/ImponibileImporto" position="attributes">
<attribute name="t-out">
format_monetary(fpa_to_eur(get_sign(record) * tax_data['ImponibileImporto'], record), euro)
format_monetary(get_sign(record) * tax_data['ImponibileImporto'], euro)
</attribute>
</xpath>
<xpath expr="//DatiRiepilogo/Imposta" position="attributes">
Expand All @@ -66,7 +66,7 @@
</xpath>
<xpath expr="//PrezzoTotale" position="attributes">
<attribute name="t-out">
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)
</attribute>
</xpath>
</template>
Expand Down

0 comments on commit 752d3f9

Please sign in to comment.