diff --git a/addons/l10n_es_edi_facturae/models/account_move.py b/addons/l10n_es_edi_facturae/models/account_move.py index 82cc8cea038..2fc9c206bfb 100644 --- a/addons/l10n_es_edi_facturae/models/account_move.py +++ b/addons/l10n_es_edi_facturae/models/account_move.py @@ -192,10 +192,18 @@ class AccountMove(models.Model): continue invoice_line_values = {} - price_before_discount = line.currency_id.round(line.price_subtotal / (1 - line.discount / 100.0)) + tax_base_before_discount = self.env['account.tax']._convert_to_tax_base_line_dict( + base_line=line, + currency=line.currency_id, + taxes=line.tax_ids, + price_unit=line.price_unit, + quantity=line.quantity, + ) + tax_before_discount = self.env['account.tax']._compute_taxes([tax_base_before_discount]) + price_before_discount = sum(to_update['price_subtotal'] for _dummy, to_update in tax_before_discount['base_lines_to_update']) discount = max(0., (price_before_discount - line.price_subtotal)) surcharge = abs(min(0., (price_before_discount - line.price_subtotal))) - totals['total_gross_amount'] += line.price_subtotal + totals['total_gross_amount'] += price_before_discount totals['total_general_discounts'] += discount totals['total_general_surcharges'] += surcharge base_line = self.env['account.tax']._convert_to_tax_base_line_dict( diff --git a/addons/l10n_es_edi_facturae/tests/test_edi_xml.py b/addons/l10n_es_edi_facturae/tests/test_edi_xml.py index f79f7bff684..3f8dc943f81 100644 --- a/addons/l10n_es_edi_facturae/tests/test_edi_xml.py +++ b/addons/l10n_es_edi_facturae/tests/test_edi_xml.py @@ -234,3 +234,20 @@ class TestEdiFacturaeXmls(AccountEdiTestCommon): with file_open("l10n_es_edi_facturae/tests/data/expected_refund_document.xml", "rt") as f: expected_xml = lxml.etree.fromstring(f.read().encode()) self.assertXmlTreeEqual(lxml.etree.fromstring(generated_file), expected_xml) + + def test_discount_100_percent(self): + """ Create an invoice with a 100% discount """ + with freeze_time(self.frozen_today), \ + patch(f"{self.certificate_module}.fields.datetime.now", lambda x=None: self.frozen_today), \ + patch(f"{self.certificate_module}.sha1", lambda x: sha1()): + invoice = self.create_invoice( + partner_id=self.partner_a.id, + move_type='out_invoice', + invoice_line_ids=[{'product_id': self.product_a.id, 'price_unit': 1000.0, 'discount': 100.0, 'quantity': 2}], + ) + invoice.action_post() + wizard = self.create_send_and_print(invoice) + result = wizard.action_send_and_print() + + self.assertEqual(result['type'], 'ir.actions.act_url') + self.assertEqual(invoice.invoice_line_ids[0].price_subtotal, 0.0)