Commit ff812ffd authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: reduce the precision of the discount price

The idea is to reduce the risk of bad precision when building the related accounting transactions
parent 305e6a50
......@@ -133,12 +133,17 @@ if (subscription_request.getPrice() != 0) and (0 < unused_day_count):
stop_date=next_period_date,
**open_order_edit_kw
)
price = -subscription_request.getPrice() * (unused_day_count / (next_period_date - start_date))
precision = context.getQuantityPrecisionFromResource(subscription_request.getPriceCurrencyValue())
# Use currency precision to reduce the float length
price = float(('%%0.%sf' % precision) % price)
discount_service = portal.restrictedTraverse('service_module/slapos_discount')
sale_packing_list.newContent(
portal_type="Sale Packing List Line",
resource_value=discount_service,
quantity=unused_day_count / (next_period_date - start_date),
price=-subscription_request.getPrice(),
# Use a quantity of 1 to be able to count how many discount were distributed
quantity=1,
price=price,
quantity_unit_value=discount_service.getQuantityUnitValue(),
base_contribution_list=discount_service.getBaseContributionList(),
use=discount_service.getUse(),
......
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