[FIX] l10n_it_edi: Generate correct XML for negative invoice lines
When creating an invoice with a positive line and a negative line, with different taxes, the DatiRiepilogo node for the tax of the negative line contained positive amounts when they should be negative. This is because we were applying `abs()` too naively in the XML template and in the code of _l10n_it_edi_prepare_fatturapa_tax_details. This bugfix commit changes the logic to no longer use abs(). opw-3316300 closes odoo/odoo#122982 X-original-commit: 0241e96fe12401f0891efc00f840e03d0c0219fd Signed-off-by: Quentin De Paoli <qdp@odoo.com> Signed-off-by: Antoine Dupuis (andu) <andu@odoo.com>
This commit is contained in:
@@ -175,8 +175,8 @@
|
||||
<Imposta t-out="format_monetary(balance_multiplicator * tax_line['tax_amount'], currency)"/>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<ImponibileImporto t-out="format_monetary(abs(tax_line['base_amount']), currency)"/>
|
||||
<Imposta t-out="format_monetary(abs(tax_line['tax_amount']), currency)"/>
|
||||
<ImponibileImporto t-out="format_monetary(tax_line['base_amount'], currency)"/>
|
||||
<Imposta t-out="format_monetary(tax_line['tax_amount'], currency)"/>
|
||||
</t>
|
||||
<EsigibilitaIVA t-if="not has_exoneration or kind_exoneration == 'N6'" t-out="tax.l10n_it_vat_due_date"/>
|
||||
<RiferimentoNormativo t-if="tax.l10n_it_law_reference" t-out="format_alphanumeric(tax.l10n_it_law_reference, 100)"/>
|
||||
@@ -219,4 +219,3 @@
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class AccountMove(models.Model):
|
||||
})
|
||||
return invoice_lines
|
||||
|
||||
def _l10n_it_edi_prepare_fatturapa_tax_details(self, tax_details, reverse_charge_refund=False):
|
||||
def _l10n_it_edi_prepare_fatturapa_tax_details(self, tax_details):
|
||||
""" Returns a list of dictionaries passed to the template for the invoice lines (DatiRiepilogo)
|
||||
"""
|
||||
tax_lines = []
|
||||
@@ -131,10 +131,6 @@ class AccountMove(models.Model):
|
||||
tax_dict['rounding'] = base_amount - (tax_amount * 100 / tax_rate)
|
||||
tax_dict['base_amount'] = base_amount - tax_dict['rounding']
|
||||
|
||||
if not reverse_charge_refund:
|
||||
tax_dict['base_amount'] = abs(tax_dict['base_amount'])
|
||||
tax_dict['tax_amount'] = abs(tax_dict['tax_amount'])
|
||||
|
||||
tax_line_dict = {
|
||||
'tax': tax,
|
||||
'rounding': tax_dict.get('rounding', False),
|
||||
@@ -251,7 +247,7 @@ class AccountMove(models.Model):
|
||||
) if convert_to_euros and conversion_line else None
|
||||
|
||||
invoice_lines = self._l10n_it_edi_prepare_fatturapa_line_details(reverse_charge_refund, is_downpayment, convert_to_euros)
|
||||
tax_lines = self._l10n_it_edi_prepare_fatturapa_tax_details(tax_details, reverse_charge_refund)
|
||||
tax_lines = self._l10n_it_edi_prepare_fatturapa_tax_details(tax_details)
|
||||
|
||||
# Reduce downpayment views to a single recordset
|
||||
downpayment_moves = [l.get('downpayment_moves', self.env['account.move']) for l in invoice_lines]
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<Divisa>EUR</Divisa>
|
||||
<Data>2022-03-24</Data>
|
||||
<Numero>INV/2022/00001</Numero>
|
||||
<ImportoTotaleDocumento>854.49</ImportoTotaleDocumento>
|
||||
<ImportoTotaleDocumento>799.49</ImportoTotaleDocumento>
|
||||
</DatiGeneraliDocumento>
|
||||
</DatiGenerali>
|
||||
<DatiBeniServizi>
|
||||
@@ -82,19 +82,33 @@
|
||||
<PrezzoTotale>-100.00</PrezzoTotale>
|
||||
<AliquotaIVA>22.00</AliquotaIVA>
|
||||
</DettaglioLinee>
|
||||
<DettaglioLinee>
|
||||
<NumeroLinea>3</NumeroLinea>
|
||||
<Descrizione>negative_line_different_tax</Descrizione>
|
||||
<Quantita>1.00</Quantita>
|
||||
<PrezzoUnitario>-50.000000</PrezzoUnitario>
|
||||
<PrezzoTotale>-50.00</PrezzoTotale>
|
||||
<AliquotaIVA>10.00</AliquotaIVA>
|
||||
</DettaglioLinee>
|
||||
<DatiRiepilogo>
|
||||
<AliquotaIVA>22.00</AliquotaIVA>
|
||||
<ImponibileImporto>700.40</ImponibileImporto>
|
||||
<Imposta>154.09</Imposta>
|
||||
<EsigibilitaIVA>I</EsigibilitaIVA>
|
||||
</DatiRiepilogo>
|
||||
<DatiRiepilogo>
|
||||
<AliquotaIVA>10.00</AliquotaIVA>
|
||||
<ImponibileImporto>-50.00</ImponibileImporto>
|
||||
<Imposta>-5.00</Imposta>
|
||||
<EsigibilitaIVA>I</EsigibilitaIVA>
|
||||
</DatiRiepilogo>
|
||||
</DatiBeniServizi>
|
||||
<DatiPagamento>
|
||||
<CondizioniPagamento>TP02</CondizioniPagamento>
|
||||
<DettaglioPagamento>
|
||||
<ModalitaPagamento>MP05</ModalitaPagamento>
|
||||
<DataScadenzaPagamento>2022-03-24</DataScadenzaPagamento>
|
||||
<ImportoPagamento>854.49</ImportoPagamento>
|
||||
<ImportoPagamento>799.49</ImportoPagamento>
|
||||
<CodicePagamento>INV/2022/00001</CodicePagamento>
|
||||
</DettaglioPagamento>
|
||||
</DatiPagamento>
|
||||
|
||||
@@ -298,6 +298,13 @@ class TestItEdiExport(TestItEdi):
|
||||
self._assert_export_invoice(invoice, 'invoice_zero_percent_taxes.xml')
|
||||
|
||||
def test_invoice_negative_price(self):
|
||||
tax_10 = self.env['account.tax'].create({
|
||||
'name': '10% tax',
|
||||
'amount': 10.0,
|
||||
'amount_type': 'percent',
|
||||
'company_id': self.company.id,
|
||||
})
|
||||
|
||||
invoice = self.env['account.move'].with_company(self.company).create({
|
||||
'move_type': 'out_invoice',
|
||||
'invoice_date': '2022-03-24',
|
||||
@@ -315,6 +322,11 @@ class TestItEdiExport(TestItEdi):
|
||||
'price_unit': -100.0,
|
||||
'tax_ids': [Command.set(self.default_tax.ids)],
|
||||
}),
|
||||
Command.create({
|
||||
'name': 'negative_line_different_tax',
|
||||
'price_unit': -50.0,
|
||||
'tax_ids': [Command.set(tax_10.ids)],
|
||||
}),
|
||||
],
|
||||
})
|
||||
invoice.action_post()
|
||||
|
||||
Reference in New Issue
Block a user