[FIX] l10n_it_edi: handle negative unit price
Before this fix negative aml unit prices were systematically set to positive in the edi xml generating inconsistencies. Manual forwardport of d31d562 closes odoo/odoo#101493 Task: opw-2963947 X-original-commit: 0954550e55ce35445a198006872a12298cd77d5b Signed-off-by: Josse Colpaert <jco@odoo.com> Signed-off-by: de Wouters de Bouchout Jean-Benoît (jbw) <jbw@odoo.com>
This commit is contained in:
@@ -71,14 +71,11 @@ class AccountMove(models.Model):
|
||||
invoice_lines = []
|
||||
lines = self.invoice_line_ids.filtered(lambda l: not l.display_type in ('line_note', 'line_section'))
|
||||
for num, line in enumerate(lines):
|
||||
price_subtotal = line.balance if convert_to_euros else line.price_subtotal
|
||||
# The price_subtotal should be negative when:
|
||||
# The line has downpayment lines, but is not a downpayment (i.e. the final invoice, from which downpayment lines are subtracted) or,
|
||||
# the line is a reverse charge refund.
|
||||
if (line._get_downpayment_lines() and not is_downpayment) or reverse_charge_refund:
|
||||
price_subtotal = -abs(price_subtotal)
|
||||
else:
|
||||
price_subtotal = abs(price_subtotal)
|
||||
sign = -1 if line.move_id.is_inbound() else 1
|
||||
price_subtotal = (line.balance * sign) if convert_to_euros else line.price_subtotal
|
||||
# The price_subtotal should be inverted when the line is a reverse charge refund.
|
||||
if reverse_charge_refund:
|
||||
price_subtotal = -price_subtotal
|
||||
|
||||
# Unit price
|
||||
price_unit = 0
|
||||
|
||||
@@ -287,6 +287,24 @@ class TestItEdiExport(TestItEdi):
|
||||
],
|
||||
})
|
||||
|
||||
cls.negative_price_invoice = cls.env['account.move'].with_company(cls.company).create({
|
||||
'move_type': 'out_invoice',
|
||||
'invoice_date': datetime.date(2022, 3, 24),
|
||||
'invoice_date_due': datetime.date(2022, 3, 24),
|
||||
'partner_id': cls.italian_partner_a.id,
|
||||
'partner_bank_id': cls.test_bank.id,
|
||||
'invoice_line_ids': [
|
||||
(0, 0, {
|
||||
**cls.standard_line,
|
||||
}),
|
||||
(0, 0, {
|
||||
**cls.standard_line,
|
||||
'name': 'negative_line',
|
||||
'price_unit': -100.0,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
# post the invoices
|
||||
cls.price_included_invoice._post()
|
||||
cls.partial_discount_invoice._post()
|
||||
@@ -296,6 +314,7 @@ class TestItEdiExport(TestItEdi):
|
||||
cls.total_400_VAT_simplified_invoice._post()
|
||||
cls.pa_partner_invoice._post()
|
||||
cls.zero_tax_invoice._post()
|
||||
cls.negative_price_invoice._post()
|
||||
|
||||
cls.edi_basis_xml = cls._get_test_file_content('IT00470550013_basis.xml')
|
||||
cls.edi_simplified_basis_xml = cls._get_test_file_content('IT00470550013_simpl.xml')
|
||||
@@ -646,3 +665,44 @@ class TestItEdiExport(TestItEdi):
|
||||
)
|
||||
invoice_etree = self.with_applied_xpath(invoice_etree, "<xpath expr='.//Allegati' position='replace'/>")
|
||||
self.assertXmlTreeEqual(invoice_etree, expected_etree)
|
||||
|
||||
def test_negative_price_invoice(self):
|
||||
invoice_etree = etree.fromstring(self.edi_format._export_as_xml(self.negative_price_invoice))
|
||||
expected_etree = self.with_applied_xpath(
|
||||
etree.fromstring(self.edi_basis_xml),
|
||||
'''
|
||||
<xpath expr="//FatturaElettronicaBody//DatiBeniServizi" position="replace">
|
||||
<DatiBeniServizi>
|
||||
<DettaglioLinee>
|
||||
<NumeroLinea>1</NumeroLinea>
|
||||
<Descrizione>standard_line</Descrizione>
|
||||
<Quantita>1.00</Quantita>
|
||||
<PrezzoUnitario>800.400000</PrezzoUnitario>
|
||||
<PrezzoTotale>800.40</PrezzoTotale>
|
||||
<AliquotaIVA>22.00</AliquotaIVA>
|
||||
</DettaglioLinee>
|
||||
<DettaglioLinee>
|
||||
<NumeroLinea>2</NumeroLinea>
|
||||
<Descrizione>negative_line</Descrizione>
|
||||
<Quantita>1.00</Quantita>
|
||||
<PrezzoUnitario>-100.000000</PrezzoUnitario>
|
||||
<PrezzoTotale>-100.00</PrezzoTotale>
|
||||
<AliquotaIVA>22.00</AliquotaIVA>
|
||||
</DettaglioLinee>
|
||||
<DatiRiepilogo>
|
||||
<AliquotaIVA>22.00</AliquotaIVA>
|
||||
<ImponibileImporto>700.40</ImponibileImporto>
|
||||
<Imposta>154.09</Imposta>
|
||||
<EsigibilitaIVA>I</EsigibilitaIVA>
|
||||
</DatiRiepilogo>
|
||||
</DatiBeniServizi>
|
||||
</xpath>
|
||||
<xpath expr="//DettaglioPagamento//ImportoPagamento" position="inside">
|
||||
854.49
|
||||
</xpath>
|
||||
<xpath expr="//DatiGeneraliDocumento//ImportoTotaleDocumento" position="inside">
|
||||
854.49
|
||||
</xpath>
|
||||
''')
|
||||
invoice_etree = self.with_applied_xpath(invoice_etree, "<xpath expr='.//Allegati' position='replace'/>")
|
||||
self.assertXmlTreeEqual(invoice_etree, expected_etree)
|
||||
|
||||
Reference in New Issue
Block a user