Skip to content

Commit

Permalink
[ADD] supporto per la trasmissione degli importi in EUR per fatture i…
Browse files Browse the repository at this point in the history
…n valuta estera
  • Loading branch information
TheMule71 committed Jan 14, 2021
1 parent d8ad18d commit 95973e7
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
DettaglioPagamentoType,
AllegatiType,
ScontoMaggiorazioneType,
CodiceArticoloType
CodiceArticoloType,
AltriDatiGestionaliType
)
from odoo.addons.l10n_it_fatturapa.models.account import (
RELATED_DOCUMENT_TYPES)
Expand Down Expand Up @@ -90,6 +91,17 @@ class WizardExportFatturapa(models.TransientModel):
_name = "wizard.export.fatturapa"
_description = "Export E-invoice"

@api.model
def _to_EUR(self, currency, amount,
company=None,
today=fields.Date.today()):
company = company or self.env.user.company_id
euro = self.env.ref('base.EUR')
if currency == euro:

return amount
return currency._convert(amount, euro, company, today, False)

@api.model
def _domain_ir_values(self):
model_name = self.env.context.get('active_model', False)
Expand Down Expand Up @@ -539,12 +551,12 @@ def setDatiGeneraliDocumento(self, invoice, body):
_('Invoice %s does not have a number.' % invoice.display_name))

TipoDocumento = invoice.fiscal_document_type_id.code
ImportoTotaleDocumento = invoice.amount_total
ImportoTotaleDocumento = self._to_EUR(invoice.currency_id, invoice.amount_total)
if invoice.split_payment:
ImportoTotaleDocumento += invoice.amount_sp
ImportoTotaleDocumento += self._to_EUR(invoice.currency_id, invoice.amount_sp)
body.DatiGenerali.DatiGeneraliDocumento = DatiGeneraliDocumentoType(
TipoDocumento=TipoDocumento,
Divisa=invoice.currency_id.name,
Divisa=self.env.ref('base.EUR').name,
Data=invoice.date_invoice,
Numero=invoice.number,
ImportoTotaleDocumento='%.2f' % float_round(ImportoTotaleDocumento, 2))
Expand Down Expand Up @@ -659,7 +671,7 @@ def setDettaglioLinea(
aliquota = line.invoice_line_tax_ids[0].amount
AliquotaIVA = '%.2f' % float_round(aliquota, 2)
line.ftpa_line_number = line_no
prezzo_unitario = self._get_prezzo_unitario(line)
prezzo_unitario = self._to_EUR(line.currency_id, self._get_prezzo_unitario(line))
DettaglioLinea = DettaglioLineeType(
NumeroLinea=str(line_no),
Descrizione=encode_for_export(line.name, 1000),
Expand All @@ -669,8 +681,17 @@ def setDettaglioLinea(
qta=line.quantity, precision=uom_precision),
UnitaMisura=line.uom_id and (
unidecode(line.uom_id.name)) or None,
PrezzoTotale='%.2f' % float_round(line.price_subtotal, 2),
PrezzoTotale='%.2f' % float_round(self._to_EUR(line.currency_id, line.price_subtotal), 2),
AliquotaIVA=AliquotaIVA)
if line.currency_id != self.env.ref('base.EUR'):
AltriDatiGestionali = AltriDatiGestionaliType(
TipoDato="Valuta",
RiferimentoTesto=line.currency_id.name,
RiferimentoNumero=self._get_prezzo_unitario(line),
RiferimentoData=fields.Date.today()
)
DettaglioLinea.AltriDatiGestionali.append(AltriDatiGestionali)

DettaglioLinea.ScontoMaggiorazione.extend(
self.setScontoMaggiorazione(line))
if aliquota == 0.0:
Expand Down Expand Up @@ -720,8 +741,8 @@ def setDatiRiepilogo(self, invoice, body):
tax = tax_line.tax_id
riepilogo = DatiRiepilogoType(
AliquotaIVA='%.2f' % float_round(tax.amount, 2),
ImponibileImporto='%.2f' % float_round(tax_line.base, 2),
Imposta='%.2f' % float_round(tax_line.amount, 2)
ImponibileImporto='%.2f' % float_round(self._to_EUR(invoice.currency_id, tax_line.base), 2),
Imposta='%.2f' % float_round(self._to_EUR(invoice.currency_id, tax_line.amount), 2)
)
if tax.amount == 0.0:
if not tax.kind_id:
Expand Down Expand Up @@ -764,7 +785,7 @@ def setDatiPagamento(self, invoice, body):
for move_line_id in payment_line_ids:
move_line = move_line_pool.browse(move_line_id)
ImportoPagamento = '%.2f' % float_round(
move_line.amount_currency or move_line.debit, 2)
self._to_EUR(invoice.currency_id, move_line.amount_currency or move_line.debit), 2)
# Create with only mandatory fields
DettaglioPagamento = DettaglioPagamentoType(
ModalitaPagamento=(
Expand Down

0 comments on commit 95973e7

Please sign in to comment.