Commit c2f4d12f authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Converge if Open Order Line is invalidated

   If the Destroyed Hosting subscription is only present on Invalidated Open Orders, we just skip and converge the Hosting Subscription.

  This means the user deleted everything he had at once, too fast, before everything get processed.
parent 26e5c5ba
...@@ -137,11 +137,22 @@ for hosting_subscription in portal.portal_catalog( ...@@ -137,11 +137,22 @@ for hosting_subscription in portal.portal_catalog(
hosting_subscription = hosting_subscription.getObject() hosting_subscription = hosting_subscription.getObject()
if hosting_subscription.getCausalityState() == 'diverged': if hosting_subscription.getCausalityState() == 'diverged':
# Simply check that it has never been simulated # Simply check that it has never been simulated
if hosting_subscription.getSlapState() == 'destroy_requested':
# Line should be deleted
open_order_line = portal.portal_catalog.getResultValue(
portal_type='Open Sale Order Line',
default_aggregate_uid=hosting_subscription.getUid())
if open_order_line is not None and open_order_line.getValidationState() == "invalidated":
hosting_subscription.converge(comment="Last open order: %s" % open_order_line.getRelativeUrl())
elif open_order_line is None:
# User has no Open Sale Order (likely), so we add the line to remove later. This allow us to charge
# eventual usage between the runs of the alarm.
add_line_list.append(hosting_subscription)
else:
assert len(portal.portal_catalog( assert len(portal.portal_catalog(
portal_type='Open Sale Order Line', portal_type='Open Sale Order Line',
default_aggregate_uid=hosting_subscription.getUid(), default_aggregate_uid=hosting_subscription.getUid(),
limit=1)) == 0 limit=1)) == 0
# Let's add # Let's add
add_line_list.append(hosting_subscription) add_line_list.append(hosting_subscription)
else: else:
......
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