Skip to content

Commit

Permalink
Merge PR OCA#3125 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed May 18, 2024
2 parents 2a94901 + de42e7d commit 02d4878
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sale_fixed_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ def _get_discount_from_fixed_discount(self):
if not self.discount_fixed:
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
)

def _prepare_invoice_line(self, **optional_values):
res = super()._prepare_invoice_line(**optional_values)
Expand Down
10 changes: 10 additions & 0 deletions sale_fixed_discount/tests/test_sale_fixed_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ def test_03_fixed_discount_invoice(self):
self.sale._create_invoices()

self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0)

def test_04_fixed_discount_without_price(self):
with Form(self.sale) as sale_order:
with sale_order.order_line.edit(0) as line:
line.product_uom_qty = 1.0
line.price_unit = 0.0
line.discount_fixed = 50.0
self.assertEqual(line.discount, 0.0)
self.assertEqual(line.price_subtotal, 0.0)
self.assertEqual(self.sale.amount_total, 0.0)

0 comments on commit 02d4878

Please sign in to comment.