Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][l10n_it_fatturapa_out] fix case the invois is a credit not #19

Open
wants to merge 4 commits into
base: 14.0-imp-l10n_it_fatturapa_out-eur-from-journal
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions l10n_it_fatturapa_out/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ 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-esc="format_monetary(fpa_to_eur(line.price_subtotal, record), euro)"
t-if="line.credit > 0"
t-esc="format_monetary(fpa_to_eur(line.price_subtotal, line=line, field='credit'), euro)"
/>
<PrezzoTotale
t-if="not line.credit > 0"
t-esc="format_monetary(fpa_to_eur(line.price_subtotal, line=line, field='debit'), euro)"
/>
<AliquotaIVA
t-if="not line_is_section_note"
Expand Down Expand Up @@ -215,36 +220,15 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
>
<TipoDato>Valuta</TipoDato>
<RiferimentoTesto t-esc="line.currency_id.name" />
<RiferimentoNumero t-esc="format_price(line, original_currency=True)" />
<RiferimentoNumero
t-esc="format_monetary(line.price_subtotal, line.currency_id)"
/>
<RiferimentoData t-esc="format_date(record.date)" />
</AltriDatiGestionali>
</DettaglioLinee>
</t>
</template>

<template id="account_invoice_line_it_dati_riepilogo">
<t t-translation="off">
<t t-set="tax" t-value="tax_line.tax_line_id" />
<DatiRiepilogo>
<!--2.2.2-->
<AliquotaIVA t-esc="format_numbers(tax.amount)" />
<Natura t-if="tax.kind_id.code" t-esc="tax.kind_id.code" />
<!-- <SpeseAccessorie t-esc=""/>-->
<!-- <Arrotondamento t-esc=""/>-->
<ImponibileImporto
t-esc="format_monetary(fpa_to_eur(tax_line.tax_base_amount, record), euro)"
/>
<Imposta
t-esc="format_monetary(fpa_to_eur(tax_line.price_total, record), euro)"
/>
<EsigibilitaIVA t-if="tax.payability" t-esc="tax.payability" />
<RiferimentoNormativo
t-if="tax.law_reference"
t-esc="encode_for_export(tax.law_reference, 100)"
/>
</DatiRiepilogo>
</t>
</template>
<template id="account_invoice_it_FatturaPA_sede">
<t t-translation="off">
<t t-set="indirizzo"><t
Expand Down Expand Up @@ -560,7 +544,7 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
/>
<ImportoTotaleDocumento
t-if="not record.company_id.xml_divisa_value == 'keep_orig'"
t-esc="format_numbers_two(fpa_to_eur(get_importo_totale(record), record))"
t-esc="format_numbers_two(fpa_to_eur(get_importo_totale(record), invoice=record))"
/>
<!-- <Arrotondamento t-esc=""/>-->
<t t-foreach="get_causale(record)" t-as="causale">
Expand Down Expand Up @@ -604,10 +588,10 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
<!-- <SpeseAccessorie t-esc=""/>-->
<!-- <Arrotondamento t-esc=""/>-->
<ImponibileImporto
t-esc="format_monetary(fpa_to_eur(tax_data['ImponibileImporto'], record), euro)"
t-esc="format_monetary(tax_data['ImponibileImporto'], euro)"
/>
<Imposta
t-esc="format_monetary(fpa_to_eur(tax_data['Imposta'], record), euro)"
t-esc="format_monetary(tax_data['Imposta'], euro)"
/>
<EsigibilitaIVA
t-if="tax_data.get('EsigibilitaIVA', False)"
Expand Down Expand Up @@ -652,7 +636,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-esc="format_numbers_two(fpa_to_eur(payment.amount_currency or payment.debit, record))"
t-esc="format_numbers_two(fpa_to_eur(payment.amount_currency or payment.debit, invoice=record))"
/>

<!-- <CodUfficioPostale t-esc=""/>-->
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out/tests/data/IT06363391001_00015.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<AltriDatiGestionali>
<TipoDato>Valuta</TipoDato>
<RiferimentoTesto>USD</RiferimentoTesto>
<RiferimentoNumero>14.00000</RiferimentoNumero>
<RiferimentoNumero>14.00</RiferimentoNumero>
<RiferimentoData>2021-12-16</RiferimentoData>
</AltriDatiGestionali>
</DettaglioLinee>
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out/tests/data/IT06363391001_00015a.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<AltriDatiGestionali>
<TipoDato>Valuta</TipoDato>
<RiferimentoTesto>USD</RiferimentoTesto>
<RiferimentoNumero>14.00000</RiferimentoNumero>
<RiferimentoNumero>14.00</RiferimentoNumero>
<RiferimentoData>2021-12-16</RiferimentoData>
</AltriDatiGestionali>
</DettaglioLinee>
Expand Down
21 changes: 17 additions & 4 deletions l10n_it_fatturapa_out/wizard/efattura.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,21 @@ def format_price(line, sign=1, original_currency=False):
# e quantity (vd. format_quantity)
if line.quantity < 0:
res = -res

# 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)

price = sign * res
if (
line.move_id.move_type == "out_refund"
and price > 0
and line.move_id.rc_purchase_invoice_id
):
price = price * -1

# XXX arrotondamento?
res = "{prezzo:.{precision}f}".format(
prezzo=sign * res, precision=price_precision
prezzo=price, precision=price_precision
)
return res

Expand Down Expand Up @@ -191,11 +198,17 @@ def get_payments(invoice):
wiz = self.env["wizard.export.fatturapa"]
return wiz.getPayments(invoice)

def fpa_to_eur(amount, invoice):
def fpa_to_eur(amount, invoice=None, line=None, field=None):
if not invoice and not line:
return amount
if line and line.move_id:
invoice = line.move_id
currency = invoice.currency_id
euro = self.env.ref("base.EUR")
if currency == euro:
return amount
if line and field and field in line._fields is not None:
return line[field] if amount > 0 else -line[field]
return currency._convert(
amount, euro, invoice.company_id, invoice.date, False
)
Expand Down
14 changes: 11 additions & 3 deletions l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _key(tax_id):
"Natura": tax_line_id.kind_id.code,
# 'Arrotondamento':'',
"ImponibileImporto": tax_id.tax_base_amount,
"Imposta": tax_id.price_total,
"Imposta": abs(tax_id.balance),
"EsigibilitaIVA": tax_line_id.payability,
}
if tax_line_id.law_reference:
Expand All @@ -163,12 +163,20 @@ def _key(tax_id):
key = _key(tax_id)
if key in out_computed:
continue

if invoice.move_type == "out_invoice":
ImponibileImporto = line.credit - line.debit
elif invoice.move_type == "out_refund":
ImponibileImporto = line.debit - line.credit
else:
ImponibileImporto = 0.0

if key not in out:
out[key] = {
"AliquotaIVA": aliquota,
"Natura": tax_id.kind_id.code,
# 'Arrotondamento':'',
"ImponibileImporto": line.price_subtotal,
"ImponibileImporto": ImponibileImporto,
"Imposta": 0.0,
"EsigibilitaIVA": tax_id.payability,
}
Expand All @@ -177,7 +185,7 @@ def _key(tax_id):
tax_id.law_reference, 100
)
else:
out[key]["ImponibileImporto"] += line.price_subtotal
out[key]["ImponibileImporto"] += ImponibileImporto
out[key]["Imposta"] += 0.0
out.update(out_computed)
return out
Expand Down
21 changes: 17 additions & 4 deletions l10n_it_fatturapa_out_rc/views/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
</xpath>
<xpath expr="//DatiRiepilogo/ImponibileImporto" position="replace">
<ImponibileImporto
t-esc="format_monetary(fpa_to_eur(get_sign(record) * tax_data['ImponibileImporto'], record), euro)"
t-esc="format_monetary(get_sign(record) * tax_data['ImponibileImporto'], euro)"
/>
</xpath>
<xpath expr="//DatiRiepilogo/Imposta" position="replace">
<Imposta
t-esc="format_monetary(get_sign(record) * tax_data['Imposta'], currency)"
t-esc="format_monetary(get_sign(record) * tax_data['Imposta'], euro)"
/>
</xpath>
</template>
Expand All @@ -74,9 +74,22 @@
t-esc="format_price(line, get_sign(line.move_id))"
/>
</xpath>
<xpath expr="//PrezzoTotale" position="replace">
<xpath
expr="//PrezzoTotale[@t-if='line.credit &gt; 0']"
position="replace"
>
<PrezzoTotale
t-if="line.credit > 0"
t-esc="format_monetary(fpa_to_eur(get_sign(line.move_id) * line.price_subtotal, line=line, field='credit'), euro)"
/>
</xpath>
<xpath
expr="//PrezzoTotale[@t-if='not line.credit &gt; 0']"
position="replace"
>
<PrezzoTotale
t-esc="format_monetary(fpa_to_eur(get_sign(line.move_id) * line.price_subtotal, record), euro)"
t-if="not line.credit > 0"
t-esc="format_monetary(fpa_to_eur(get_sign(line.move_id) * line.price_subtotal, line=line, field='debit'), euro)"
/>
</xpath>
</template>
Expand Down