Commit f346c226 authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: WIP: stop using discount resource, and reduce the...

slapos_subscription_request: WIP: stop using discount resource, and reduce the quantity of the consumed software product / service
parent 73e9ab95
......@@ -127,7 +127,7 @@ open_sale_order.validate()
#######################################################
# Discount
unused_day_count = current_date - start_date
if (subscription_request.getPrice() != 0) and (0 < unused_day_count):
if (0 < unused_day_count):#(subscription_request.getPrice() != 0) and (0 < unused_day_count):
# If the open order starts before today,
# generate a discount to the user on his next invoice
......@@ -136,8 +136,11 @@ if (subscription_request.getPrice() != 0) and (0 < unused_day_count):
portal_type="Sale Packing List",
# It should match the first open order invoice
stop_date=next_period_date,
description='XXX unused day %s - prevision %s' % (unused_day_count, context.getQuantityPrecisionFromResource(subscription_request.getResourceValue())),
**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
......@@ -154,6 +157,64 @@ if (subscription_request.getPrice() != 0) and (0 < unused_day_count):
use=discount_service.getUse(),
activate_kw=activate_kw
)
"""
sale_packing_list_line = sale_packing_list.newContent(
portal_type="Sale Packing List Line",
resource_value=subscription_request.getResourceValue(),
variation_category_list=variation_category_list,
quantity_unit_value=subscription_request.getQuantityUnitValue(),
base_contribution_list=subscription_request.getResourceValue().getBaseContributionList(),
use=subscription_request.getResourceValue().getUse(),
activate_kw=activate_kw
)
if variation_category_list:
base_id = 'movement'
cell_key = list(sale_packing_list_line.getCellKeyList(base_id=base_id))[0]
sale_packing_list_cell = sale_packing_list_line.newCell(
base_id=base_id,
portal_type="Sale Packing List Cell",
*cell_key
)
sale_packing_list_cell.edit(
mapped_value_property_list=['price','quantity'],
predicate_category_list=cell_key,
variation_category_list=cell_key,
activate_kw=activate_kw
)
else:
sale_packing_list_cell = sale_packing_list_line
quantity = subscription_request.getQuantity() * (unused_day_count / (next_period_date - start_date))
# precision = context.getQuantityPrecisionFromResource(subscription_request.getResourceValue())
# XXX use currency precision, to ensure accounting is readable?
precision = context.getQuantityPrecisionFromResource(subscription_request.getPriceCurrencyValue())
# precision = 3
# Use currency precision to reduce the float length
quantity = float(('%%0.%sf' % precision) % quantity)
# raise NotImplementedError('%s %s -- %s' % (precision, quantity, subscription_request.getResourceValue().getBaseUnitQuantity()))
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)
sale_packing_list_cell.edit(
# Quantity is negative, to reduce the stock of the consumed product
quantity=-quantity,
price=subscription_request.getPrice(),
# quantity=1,
# price=price,
aggregate_value_list=[
subscription_request.getAggregateValue()
],
activate_kw=activate_kw
)
# """
sale_packing_list.Delivery_fixBaseContributionTaxableRate()
sale_packing_list.Base_checkConsistency()
sale_packing_list.confirm()
......
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