Skip to content

Commit

Permalink
[FIX] account_invoice_pricelist: float division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ferran-S73 committed Nov 7, 2022
1 parent e0b382e commit 8e268bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions account_invoice_pricelist/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
return product[field_name] * uom_factor * cur_factor, currency_id

def _calculate_discount(self, base_price, final_price):
if not base_price:
return 0.0
discount = (base_price - final_price) / base_price * 100
if (discount < 0 and base_price > 0) or (discount > 0 and base_price < 0):
discount = 0.0
Expand Down
11 changes: 10 additions & 1 deletion account_invoice_pricelist/tests/test_account_move_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hashlib
import inspect

from odoo.tests import common
from odoo.tests import Form, common

from odoo.addons.sale.models.sale import SaleOrderLine as upstream

Expand Down Expand Up @@ -53,6 +53,9 @@ def setUpClass(cls):
cls.product = cls.env["product.template"].create(
{"name": "Product Test", "list_price": 100.00}
)
cls.product_0 = cls.env["product.template"].create(
{"name": "Product Test 2", "list_price": 0.00}
)
cls.sale_pricelist = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist",
Expand Down Expand Up @@ -316,3 +319,9 @@ def test_upstream_file_hash(self):
func = inspect.getsource(upstream._get_real_price_currency).encode()
func_hash = hashlib.md5(func).hexdigest()
self.assertIn(func_hash, VALID_HASHES)

def test_add_line_price_0(self):
inv_form = Form(self.invoice)
with inv_form.invoice_line_ids.new() as inv_line:
inv_line.product_id = self.product_0.product_variant_ids[0]
self.assertEqual(inv_line.discount, 0.0)

0 comments on commit 8e268bb

Please sign in to comment.