Commit 8901ea21 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: create Open Order Cell

parent ac516e90
...@@ -18,17 +18,22 @@ def storeWorkflowComment(document, comment): ...@@ -18,17 +18,22 @@ def storeWorkflowComment(document, comment):
portal.portal_workflow.doActionFor(document, 'edit_action', comment=comment) portal.portal_workflow.doActionFor(document, 'edit_action', comment=comment)
def newOpenOrder(): def newOpenOrder(start_date):
new_open_sale_order = portal.open_sale_order_module.newContent(portal_type="Open Sale Order") new_open_sale_order = portal.open_sale_order_module.newContent(portal_type="Open Sale Order")
new_open_sale_order.edit( new_open_sale_order.edit(
specialise=specialise, specialise=specialise,
effective_date=DateTime(), effective_date=DateTime(),
start_date=start_date,
# Ensure stop date value is higher than start date
# it will be updated by OpenSaleOrder_updatePeriod
stop_date=start_date + 1,
activate_kw=activate_kw, activate_kw=activate_kw,
destination=person.getRelativeUrl(), destination_value=person,
destination_decision=person.getRelativeUrl(), destination_section_value=person,
destination_decision_value=person,
title="%s SlapOS Subscription" % person.getTitle(), title="%s SlapOS Subscription" % person.getTitle(),
ledger_value=portal.portal_categories.ledger.automated, ledger_value=portal.portal_categories.ledger.automated,
source_project_value=instance_tree.getFollowUpValue(), destination_project_value=instance_tree.getFollowUpValue(),
) )
new_open_sale_order.order(activate_kw=activate_kw) new_open_sale_order.order(activate_kw=activate_kw)
...@@ -65,11 +70,6 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -65,11 +70,6 @@ if instance_tree.getCausalityState() == 'diverged':
# Let's create the open order # Let's create the open order
if is_open_order_creation_needed: if is_open_order_creation_needed:
open_sale_order = newOpenOrder()
open_order_explanation = ""
# Add lines
open_order_line = open_sale_order.newContent(portal_type="Open Sale Order Line")
hosting_subscription = portal.hosting_subscription_module.newContent( hosting_subscription = portal.hosting_subscription_module.newContent(
portal_type="Hosting Subscription", portal_type="Hosting Subscription",
...@@ -79,6 +79,11 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -79,6 +79,11 @@ if instance_tree.getCausalityState() == 'diverged':
hosting_subscription.validate() hosting_subscription.validate()
start_date = hosting_subscription.HostingSubscription_calculateSubscriptionStartDate() start_date = hosting_subscription.HostingSubscription_calculateSubscriptionStartDate()
open_sale_order = newOpenOrder(start_date)
open_order_explanation = ""
# Add lines
open_order_line = open_sale_order.newContent(portal_type="Open Sale Order Line")
# Search for matching resource # Search for matching resource
service = instance_tree.InstanceTree_getSoftwareProduct() service = instance_tree.InstanceTree_getSoftwareProduct()
if (service is None) or (service.getUse() != 'trade/sale'): if (service is None) or (service.getUse() != 'trade/sale'):
...@@ -86,9 +91,14 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -86,9 +91,14 @@ if instance_tree.getCausalityState() == 'diverged':
#assert instance_tree.getPortalType() in service.getRequiredAggregatedPortalTypeList() #assert instance_tree.getPortalType() in service.getRequiredAggregatedPortalTypeList()
resource_vcl = list(service.getVariationCategoryList(
omit_individual_variation=0))
resource_vcl.sort()
assert len(resource_vcl) != 0, service
edit_kw = { edit_kw = {
'quantity': 1,
'resource_value': service, 'resource_value': service,
'variation_category_list': resource_vcl,
'quantity_unit': service.getQuantityUnit(), 'quantity_unit': service.getQuantityUnit(),
'base_contribution_list': service.getBaseContributionList(), 'base_contribution_list': service.getBaseContributionList(),
'use': service.getUse() 'use': service.getUse()
...@@ -104,17 +114,31 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -104,17 +114,31 @@ if instance_tree.getCausalityState() == 'diverged':
open_order_line.edit( open_order_line.edit(
activate_kw=activate_kw, activate_kw=activate_kw,
title=instance_tree.getTitle(),
start_date=start_date,
# Ensure stop date value is higher than start date
# it will be updated by OpenSaleOrder_updatePeriod
stop_date=start_date + 1,
# stop_date=calculateOpenOrderLineStopDate(open_sale_order_line, # stop_date=calculateOpenOrderLineStopDate(open_sale_order_line,
# instance_tree, start_date_delta=start_date_delta), # instance_tree, start_date_delta=start_date_delta),
aggregate_value_list=[hosting_subscription, instance_tree],
**edit_kw **edit_kw
) )
base_id = 'path'
# XXX XXX XXX TODO WRONG: it should not get the first random variations
# but match the instance tree parameters instead
cell_key = list(open_order_line.getCellKeyList(base_id=base_id))[0]
open_order_cell = open_order_line.newCell(
base_id=base_id,
portal_type='Open Sale Order Cell',
*cell_key
)
open_order_cell.edit(
mapped_value_property_list=['price','quantity'],
quantity=1,
predicate_category_list=cell_key,
variation_category_list=cell_key,
aggregate_value=[
hosting_subscription,
instance_tree
],
)
open_order = open_order_line.getParentValue() open_order = open_order_line.getParentValue()
open_order.SaleOrder_applySaleTradeCondition(batch_mode=1, force=1) open_order.SaleOrder_applySaleTradeCondition(batch_mode=1, force=1)
...@@ -127,6 +151,8 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -127,6 +151,8 @@ if instance_tree.getCausalityState() == 'diverged':
inherited_trade_condition = open_sale_order.getSpecialiseValue() inherited_trade_condition = open_sale_order.getSpecialiseValue()
if specialise is None: if specialise is None:
# XXX Comment on instance tree that no open can be created
# XXX ensure no open order has been created
assert inherited_trade_condition is not None assert inherited_trade_condition is not None
while inherited_trade_condition is not None: while inherited_trade_condition is not None:
...@@ -152,7 +178,7 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -152,7 +178,7 @@ if instance_tree.getCausalityState() == 'diverged':
str([x.getRelativeUrl() for x in predicate_list]), str([x.getRelativeUrl() for x in predicate_list]),
str([(x.getRelativeUrl(), x.getResource()) for x in log_predicate_list]), str([(x.getRelativeUrl(), x.getResource()) for x in log_predicate_list]),
)) ))
open_order_line.edit( open_order_cell.edit(
price=price price=price
) )
...@@ -166,7 +192,7 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -166,7 +192,7 @@ if instance_tree.getCausalityState() == 'diverged':
open_order = open_order_line.getParentValue() open_order = open_order_line.getParentValue()
assert open_order_line.getResource().startswith('software_product') assert open_order_line.getResource().startswith('software_product')
assert open_order_line.getQuantityUnit() == 'unit/piece' assert open_order_line.getQuantityUnit() == 'time/month', open_order_line.getQuantityUnit()
assert open_order_line.getBaseContribution() == 'base_amount/invoicing/discounted' assert open_order_line.getBaseContribution() == 'base_amount/invoicing/discounted'
assert open_order_line.getBaseContributionList()[1] == 'base_amount/invoicing/taxable' assert open_order_line.getBaseContributionList()[1] == 'base_amount/invoicing/taxable'
assert open_order_line.getUse() == 'trade/sale' assert open_order_line.getUse() == 'trade/sale'
......
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