Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_invoice_fixed_discount: Fixed devision by zero error to… #1860

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion account_invoice_fixed_discount/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading