Skip to content

Commit

Permalink
Merge branch '14.0-fix-fpa_to_eur-imposta-per_pip' of git+ssh://githu…
Browse files Browse the repository at this point in the history
…b.com/efatto/l10n-italy into 14.0
  • Loading branch information
Pretecno committed Sep 27, 2024
2 parents 7b7bbc3 + 00c70f3 commit 32070d9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
27 changes: 2 additions & 25 deletions l10n_it_fatturapa_out/data/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,6 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati)
</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 @@ -604,10 +581,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
18 changes: 11 additions & 7 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 @@ -193,14 +202,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
19 changes: 14 additions & 5 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 @@ -101,7 +101,11 @@ def __init__(self, date_maturity, amount_currency, debit):
lambda line: line.account_id.user_type_id.type in ("receivable", "payable")
):
payments.append(
_Payment(line.date_maturity, line.amount_currency, line.debit)
_Payment(
line.date_maturity,
line.amount_currency,
line.debit,
)
)
return payments

Expand Down Expand Up @@ -129,6 +133,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 All @@ -141,7 +146,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": fpaToEur(tax_id.price_total, invoice, euro),
"EsigibilitaIVA": tax_line_id.payability,
}
if tax_line_id.law_reference:
Expand All @@ -168,7 +173,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
),
"Imposta": 0.0,
"EsigibilitaIVA": tax_id.payability,
}
Expand All @@ -177,7 +184,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
)
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-esc="tax_data['Natura']"
/>
<ImponibileImporto
t-esc="format_monetary(fpa_to_eur(tax_data['ImponibileImporto'], record), euro)"
t-esc="format_monetary(tax_data['ImponibileImporto'], euro)"
/>
<Imposta>0.00</Imposta>
<EsigibilitaIVA
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_rc/views/invoice_it_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</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">
Expand Down

0 comments on commit 32070d9

Please sign in to comment.