From f3170f7f1fcc0a44818c2951d0eb58720efe4e25 Mon Sep 17 00:00:00 2001 From: fd-oerp Date: Fri, 6 Dec 2024 14:56:44 -0500 Subject: [PATCH] [FIX] account_invoice_fixed_discount: Fixed devision by zero error to v17.0 --- .../models/account_move_line.py | 6 +++++- .../tests/test_account_fixed_discount.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/account_invoice_fixed_discount/models/account_move_line.py b/account_invoice_fixed_discount/models/account_move_line.py index 0ee54909957..557710f1b4f 100644 --- a/account_invoice_fixed_discount/models/account_move_line.py +++ b/account_invoice_fixed_discount/models/account_move_line.py @@ -82,4 +82,8 @@ def _get_discount_from_fixed_discount(self): currency = self.currency_id or self.company_id.currency_id if float_is_zero(self.discount_fixed, precision_rounding=currency.rounding): return 0.0 - return (self.discount_fixed / self.price_unit) * 100 + return ( + (self.price_unit != 0) + and ((self.discount_fixed) / self.price_unit) * 100 + or 0.00 + ) diff --git a/account_invoice_fixed_discount/tests/test_account_fixed_discount.py b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py index e6272931b21..4b857642345 100644 --- a/account_invoice_fixed_discount/tests/test_account_fixed_discount.py +++ b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py @@ -144,3 +144,14 @@ def test_04_base_line_set_to_none(self): price_unit=10, currency=1, ) + + def test_05_fixed_discount_without_price(self): + """Tests fixed discount with 0 unit price.""" + with Form(self.invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + line.quantity = 1.0 + line.price_unit = 0.0 + line.discount_fixed = 50.0 + self.assertEqual(self.invoice.invoice_line_ids.discount, 0.0) + self.assertEqual(self.invoice.invoice_line_ids.price_subtotal, 0.0) + self.assertEqual(self.invoice.amount_total, 0.0)