Commit acb2f6ea authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: do not create Hosting Subscript before the price is found

parent d0a4c42e
......@@ -29,12 +29,17 @@ def newOpenOrder(start_date, service,
cell_portal_type = 'Sale Order Cell'
base_id = 'movement'
module = portal.sale_order_module
aggregate_value_list = []
else:
order_portal_type = 'Open Sale Order'
line_portal_type = 'Open Sale Order Line'
cell_portal_type = 'Open Sale Order Cell'
base_id = 'path'
module = portal.open_sale_order_module
aggregate_value_list = [
hosting_subscription,
instance_tree
]
open_sale_order = module.newContent(
portal_type=order_portal_type,
......@@ -92,15 +97,13 @@ def newOpenOrder(start_date, service,
temp_object=temp_order,
*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
],
aggregate_value_list=aggregate_value_list,
activate_kw=activate_kw
)
......@@ -159,14 +162,6 @@ if instance_tree.getCausalityState() == 'diverged':
# Let's create the open order
if is_open_order_creation_needed:
hosting_subscription = portal.hosting_subscription_module.newContent(
portal_type="Hosting Subscription",
title=instance_tree.getTitle(),
ledger_value=portal.portal_categories.ledger.automated,
)
hosting_subscription.validate()
start_date = hosting_subscription.HostingSubscription_calculateSubscriptionStartDate()
# Search for matching resource
service, software_release, software_type = instance_tree.InstanceTree_getSoftwareProduct()
if (service is None) or (service.getUse() != 'trade/sale'):
......@@ -178,10 +173,10 @@ if instance_tree.getCausalityState() == 'diverged':
# Sale Supply price do not match Open Order
# Create a temp Sale Order to calculate the real price
sale_order, order_line, order_cell = newOpenOrder(
start_date, service,
_, _, order_cell = newOpenOrder(
DateTime(), service,
software_release, software_type,
hosting_subscription, instance_tree,
None, instance_tree,
activate_kw,
temp_order=True
)
......@@ -189,6 +184,15 @@ if instance_tree.getCausalityState() == 'diverged':
# No price found, do not create anything for now
storeWorkflowComment(instance_tree, "No price found")
return
hosting_subscription = portal.hosting_subscription_module.newContent(
portal_type="Hosting Subscription",
title=instance_tree.getTitle(),
ledger_value=portal.portal_categories.ledger.automated,
)
hosting_subscription.validate()
start_date = hosting_subscription.HostingSubscription_calculateSubscriptionStartDate()
open_sale_order, open_order_line, open_order_cell = newOpenOrder(
start_date, service,
software_release, software_type,
......
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