Skip to content

Commit

Permalink
[FIX] forward port of #2272
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMule71 committed May 8, 2021
1 parent 1c19fc3 commit ac2507d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 13 deletions.
108 changes: 108 additions & 0 deletions l10n_it_fatturapa_in/tests/data/IT01234567890_FPR15.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<q1:FatturaElettronica xmlns:q1="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2" versione="FPR12">
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
<IdPaese>IT</IdPaese>
<IdCodice>02780790107</IdCodice>
</IdTrasmittente>
<ProgressivoInvio>FPR14</ProgressivoInvio>
<FormatoTrasmissione>FPR12</FormatoTrasmissione>
<CodiceDestinatario>0000000</CodiceDestinatario>
<ContattiTrasmittente>
<Telefono>06543534343</Telefono>
<Email>[email protected]</Email>
</ContattiTrasmittente>
<PECDestinatario>[email protected]</PECDestinatario>
</DatiTrasmissione>
<CedentePrestatore>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>02780790107</IdCodice>
</IdFiscaleIVA>
<Anagrafica>
<Denominazione>YourCompany</Denominazione>
</Anagrafica>
<RegimeFiscale>RF01</RegimeFiscale>
</DatiAnagrafici>
<Sede>
<Indirizzo>Via Milano, 1</Indirizzo>
<CAP>00100</CAP>
<Comune>Roma</Comune>
<Provincia>AK</Provincia>
<Nazione>IT</Nazione>
</Sede>
<Contatti>
<Telefono>06543534343</Telefono>
<Email>[email protected]</Email>
</Contatti>
</CedentePrestatore>
<CessionarioCommittente>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>07973780013</IdCodice>
</IdFiscaleIVA>
<CodiceFiscale>07973780013</CodiceFiscale>
<Anagrafica>
<Denominazione>B2B Customer</Denominazione>
</Anagrafica>
</DatiAnagrafici>
<Sede>
<Indirizzo>Via Roma, 1</Indirizzo>
<CAP>16100</CAP>
<Comune>Genova</Comune>
<Provincia>AK</Provincia>
<Nazione>IT</Nazione>
</Sede>
</CessionarioCommittente>
</FatturaElettronicaHeader>
<FatturaElettronicaBody>
<DatiGenerali>
<DatiGeneraliDocumento>
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2020-09-30</Data>
<Numero>FPR 17/20</Numero>
<ImportoTotaleDocumento>54313.50</ImportoTotaleDocumento>
</DatiGeneraliDocumento>
</DatiGenerali>
<DatiBeniServizi>
<DettaglioLinee>
<NumeroLinea>10</NumeroLinea>
<Descrizione>Benzina S.Pb 10PPM</Descrizione>
<Quantita>4000.00000000</Quantita>
<UnitaMisura>L</UnitaMisura>
<PrezzoUnitario>1.35580114</PrezzoUnitario>
<PrezzoTotale>5423.20456</PrezzoTotale>
<AliquotaIVA>22.00</AliquotaIVA>
</DettaglioLinee>
<DettaglioLinee>
<NumeroLinea>20</NumeroLinea>
<Descrizione>Gasolio Autotrazione 10PPM</Descrizione>
<Quantita>32000.00000000</Quantita>
<UnitaMisura>L</UnitaMisura>
<PrezzoUnitario>1.22175180</PrezzoUnitario>
<PrezzoTotale>39096.05760</PrezzoTotale>
<AliquotaIVA>22.00</AliquotaIVA>
</DettaglioLinee>
<DatiRiepilogo>
<AliquotaIVA>22.00</AliquotaIVA>
<ImponibileImporto>44519.26</ImponibileImporto>
<Imposta>9794.24</Imposta>
<EsigibilitaIVA>I</EsigibilitaIVA>
</DatiRiepilogo>
</DatiBeniServizi>
<DatiPagamento>
<CondizioniPagamento>TP01</CondizioniPagamento>
<DettaglioPagamento>
<ModalitaPagamento>MP01</ModalitaPagamento>
<DataScadenzaPagamento>2021-04-21</DataScadenzaPagamento>
<ImportoPagamento>54313.50</ImportoPagamento>
<IBAN>IT59R0100003228000000000622</IBAN>
<BIC>BCITITMM</BIC>
</DettaglioPagamento>
</DatiPagamento>
</FatturaElettronicaBody>
</q1:FatturaElettronica>
18 changes: 18 additions & 0 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,24 @@ def test_45_xml_many_zeros(self):
self.assertEqual(invoice.invoice_line_ids[1].quantity, 1.0)
self.assertEqual(invoice.invoice_line_ids[1].price_subtotal, 0.0)

def test_48_xml_import(self):
# my company bank account is the same as the one in XML:
# invoice creation must not be blocked
self.env["res.partner.bank"].create(
{
"acc_number": "IT59R0100003228000000000622",
"company_id": self.env.user.company_id.id,
"partner_id": self.env.user.company_id.partner_id.id,
}
)
res = self.run_wizard("test48", "IT01234567890_FPR15.xml")
invoice_id = res.get("domain")[0][2][0]
invoice = self.invoice_model.browse(invoice_id)
self.assertTrue(
"Bank account IT59R0100003228000000000622 already exists"
in invoice.e_invoice_validation_message
)

def test_01_xml_link(self):
"""
E-invoice lines are created.
Expand Down
38 changes: 25 additions & 13 deletions l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def _addGlobalDiscount(self, invoice_id, DatiGeneraliDocumento):
).create(line_vals)
return True

def _createPaymentsLine(self, payment_id, line, partner_id):
def _createPaymentsLine(self, payment_id, line, partner_id, invoice):
details = line.DettaglioPagamento or False
if details:
PaymentModel = self.env["fatturapa.payment.detail"]
Expand Down Expand Up @@ -731,8 +731,9 @@ def _createPaymentsLine(self, payment_id, line, partner_id):
else:
bank = banks[0]
if dline.IBAN:
iban = dline.IBAN.strip()
SearchDom = [
("acc_number", "=", pretty_iban(dline.IBAN.strip())),
("acc_number", "=", pretty_iban(iban)),
("partner_id", "=", partner_id),
]
payment_bank_id = False
Expand All @@ -746,20 +747,31 @@ def _createPaymentsLine(self, payment_id, line, partner_id):
"Bank Name: %s\n"
)
% (
dline.IBAN.strip() or "",
iban or "",
dline.IstitutoFinanziario or "",
)
)
elif not payment_banks and bank:
payment_bank_id = PartnerBankModel.create(
{
"acc_number": dline.IBAN.strip(),
"partner_id": partner_id,
"bank_id": bank.id,
"bank_name": dline.IstitutoFinanziario or bank.name,
"bank_bic": dline.BIC or bank.bic,
}
).id
existing_account = PartnerBankModel.search(
[
("acc_number", "=", iban),
("company_id", "=", invoice.company_id.id),
]
)
if existing_account:
self.log_inconsistency(
_("Bank account %s already exists") % iban
)
else:
payment_bank_id = PartnerBankModel.create(
{
"acc_number": iban,
"partner_id": partner_id,
"bank_id": bank.id,
"bank_name": dline.IstitutoFinanziario or bank.name,
"bank_bic": dline.BIC or bank.bic,
}
).id
if payment_banks:
payment_bank_id = payment_banks[0].id

Expand Down Expand Up @@ -1265,7 +1277,7 @@ def set_payments_data(self, FatturaBody, invoice, partner_id):
PayDataId = PaymentDataModel.create(
{"payment_terms": term_id, "invoice_id": invoice_id}
).id
self._createPaymentsLine(PayDataId, PaymentLine, partner_id)
self._createPaymentsLine(PayDataId, PaymentLine, partner_id, invoice)

def set_withholding_tax(self, FatturaBody, invoice_data):
Withholdings = FatturaBody.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta
Expand Down

0 comments on commit ac2507d

Please sign in to comment.