Commit c864212f authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: generate a discount on the first invoice

If the open order does not start the same day, do not ask user to pay for those missing days
parent 105ee149
...@@ -114,5 +114,33 @@ open_sale_order.OpenSaleOrder_updatePeriod() ...@@ -114,5 +114,33 @@ open_sale_order.OpenSaleOrder_updatePeriod()
open_sale_order.plan() open_sale_order.plan()
open_sale_order.validate() open_sale_order.validate()
#######################################################
# Discount
unused_day_count = current_date - start_date
if 0 < unused_day_count:
# If the open order starts before today,
# generate a discount to the user on his next invoice
sale_packing_list = portal.sale_packing_list_module.newContent(
portal_type="Sale Packing List",
title="first invoice discount for %s" % open_sale_order.getReference(),
# It should match the first open order invoice
stop_date=next_period_date,
**open_order_edit_kw
)
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(),
quantity_unit_value=discount_service.getQuantityUnitValue(),
base_contribution_list=discount_service.getBaseContributionList(),
use=discount_service.getUse(),
activate_kw=activate_kw
)
sale_packing_list.confirm()
sale_packing_list.stop()
sale_packing_list.deliver()
return open_sale_order return open_sale_order
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