Commit 9af12423 authored by Jérome Perrin's avatar Jérome Perrin

trade: prevent ZeroDivisionError for 0 quantity when using base_price_per_slice

parent b2e93a3f
Pipeline #38757 passed with stage
in 0 seconds
......@@ -24,16 +24,19 @@ result = context.getPriceParameterDict(context=movement, **kw)
if result["slice_base_price"]:
total_price = 0.
quantity = movement.getQuantity()
sliced_base_price_list = zip(result["slice_base_price"], result["slice_quantity_range"])
for slice_price, slice_range in sliced_base_price_list:
slice_min, slice_max = slice_range
if slice_max is None:
slice_max = quantity + 1
if slice_min == 0:
slice_min = 1
priced_quantity = min(slice_max - 1, quantity) - (slice_min - 1)
total_price += priced_quantity * slice_price
result["base_price"] = total_price / quantity
if quantity:
sliced_base_price_list = zip(result["slice_base_price"], result["slice_quantity_range"])
for slice_price, slice_range in sliced_base_price_list:
slice_min, slice_max = slice_range
if slice_max is None:
slice_max = quantity + 1
if slice_min == 0:
slice_min = 1
priced_quantity = min(slice_max - 1, quantity) - (slice_min - 1)
total_price += priced_quantity * slice_price
result["base_price"] = total_price / quantity
else:
result["base_price"] = 0.
base_price = result["base_price"]
if base_price in (None, ""):
......
......@@ -1338,6 +1338,7 @@ class TestResource(ERP5TypeTestCase):
{'quantity': 21, 'price': 198./21, 'total_price': 198.},
{'quantity': 22, 'price': 206./22, 'total_price': 206.},
{'quantity': 25, 'price': 230./25, 'total_price': 230.},
{'quantity': 0., 'price': 0., 'total_price': 0.},
]:
_test(**case)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment