Commit c8acd609 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: do not crash if open order line is not linked to an instance

parent c7922f3a
...@@ -58,31 +58,33 @@ if open_sale_order.getValidationState() == 'validated': ...@@ -58,31 +58,33 @@ if open_sale_order.getValidationState() == 'validated':
hosting_subscription = open_order_line.getAggregateValue(portal_type='Hosting Subscription') hosting_subscription = open_order_line.getAggregateValue(portal_type='Hosting Subscription')
instance_tree = open_order_line.getAggregateValue(portal_type='Instance Tree') instance_tree = open_order_line.getAggregateValue(portal_type='Instance Tree')
assert current_start_date == hosting_subscription.HostingSubscription_calculateSubscriptionStartDate() assert current_start_date == hosting_subscription.HostingSubscription_calculateSubscriptionStartDate()
subscription_request = instance_tree.getAggregateRelatedValue(portal_type="Subscription Request") if instance_tree is not None:
# Define the start date of the period, this can variates with the time. subscription_request = instance_tree.getAggregateRelatedValue(portal_type="Subscription Request")
next_stop_date_delta = 0 # Define the start date of the period, this can variates with the time.
if subscription_request is not None: next_stop_date_delta = 0
next_stop_date_delta = 46 if subscription_request is not None:
next_stop_date_delta = 46
# First check if the instance tree has been correctly simulated (this script may run only once per year...)
stop_date = calculateOpenOrderLineStopDate(open_order_line, hosting_subscription, instance_tree, # First check if the instance tree has been correctly simulated (this script may run only once per year...)
start_date_delta=0, next_stop_date_delta=next_stop_date_delta) stop_date = calculateOpenOrderLineStopDate(open_order_line, hosting_subscription, instance_tree,
if current_stop_date < stop_date: start_date_delta=0, next_stop_date_delta=next_stop_date_delta)
# Bingo, new subscription to generate if current_stop_date < stop_date:
open_order_line.edit( # Bingo, new subscription to generate
stop_date=stop_date, open_order_line.edit(
activate_kw=activate_kw) stop_date=stop_date,
storeWorkflowComment(open_order_line, activate_kw=activate_kw)
'Stop date updated to %s' % stop_date) storeWorkflowComment(open_order_line,
'Stop date updated to %s' % stop_date)
if instance_tree.getSlapState() == 'destroy_requested':
# Line should be deleted if instance_tree.getSlapState() == 'destroy_requested':
assert instance_tree.getCausalityState() == 'diverged' # Line should be deleted
instance_tree.converge(comment="Last open order: %s" % open_order_line.getRelativeUrl()) assert instance_tree.getCausalityState() == 'diverged'
instance_tree.converge(comment="Last open order: %s" % open_order_line.getRelativeUrl())
open_sale_order.archive()
storeWorkflowComment(open_sale_order, "Instance Tree destroyed: %s" % instance_tree.getRelativeUrl()) open_sale_order.archive()
elif (instance_tree.getCausalityState() == 'diverged'): storeWorkflowComment(open_sale_order, "Instance Tree destroyed: %s" % instance_tree.getRelativeUrl())
instance_tree.converge(comment="Nothing to do on open order.") elif (instance_tree.getCausalityState() == 'diverged'):
instance_tree.converge(comment="Nothing to do on open 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