Commit 15f86a04 authored by Romain Courteaud's avatar Romain Courteaud

erp5_open_trade: do not reexpand simulation if there is no simulation movement to create

expand always reindex the full simulation tree, even if there is nothing to do.
This is cpu costly.
parent f06b7534
Pipeline #32998 passed with stage
in 0 seconds
......@@ -3,6 +3,8 @@ if context.checkConsistency():
return
subscription_item_set = set()
now = DateTime().earliestTime()
portal = context.getPortalObject()
for open_order_line in context.objectValues():
for ob in [open_order_line] + open_order_line.getCellValueList():
......@@ -10,4 +12,17 @@ for open_order_line in context.objectValues():
if getattr(item.aq_explicit, 'updateSimulation', None) is not None and \
item not in subscription_item_set:
subscription_item_set.add(item)
stop_date = item.getNextPeriodicalDate(now)
# Do not expand subscription item if there is
# no new simulation movement to create
# (expand always reindex the full simulation tree,
# which can be cpu costly when we have many hosting subscription)
simulation_movement_list = portal.portal_simulation.getMovementHistoryList(
portal_type='Simulation Movement',
aggregate__uid=item.getUid(),
from_date=stop_date,
at_date=stop_date,
only_accountable=False,
)
if len(simulation_movement_list) == 0:
item.updateSimulation(expand_root=1)
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