Commit b30098ba authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: speed up the first invoice creation

It should reduce number of open order expand calls.
parent bcdbf6a1
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<key> <string>categories</string> </key> <key> <string>categories</string> </key>
<value> <value>
<tuple> <tuple>
<string>after_script/portal_workflow/slapos_simulation_interaction_workflow/script_Base_triggerUpdateOpenOrderSimulation</string> <string>after_script/portal_workflow/slapos_simulation_interaction_workflow/script_OpenSaleOrder_triggerUpdateOpenOrderSimulation</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
from DateTime import DateTime
open_sale_order = state_change['object']
tag = 'script_Base_triggerCreateHostingSubscriptionSimulation'
current_date = DateTime()
# Prevent creating empty applied rule if not simulation movement
# will be created
# Sadly, this is probably nearly for tests which freeze date
start_date = open_sale_order.getStartDate()
if (start_date is not None) and (start_date < current_date):
for open_order_line in open_sale_order.objectValues():
for ob in [open_order_line] + open_order_line.getCellValueList():
for item in ob.getAggregateValueList(portal_type='Hosting Subscription'):
ob.reindexObject(activate_kw={'tag': tag})
item.activate(after_tag=tag, activity='SQLQueue').Base_reindexAndSenseAlarm(['slapos_accounting_create_hosting_subscription_simulation'])
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>script_Base_triggerUpdateOpenOrderSimulation</string> </value> <value> <string>script_OpenSaleOrder_triggerUpdateOpenOrderSimulation</string> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
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