Commit d62dacd7 authored by Julien Muchembled's avatar Julien Muchembled

_migrateSimulationTree: automatically delete orphan Simulation Movements

parent 33f1ef9c
...@@ -322,6 +322,7 @@ class AppliedRule(XMLObject, ExplainableMixin): ...@@ -322,6 +322,7 @@ class AppliedRule(XMLObject, ExplainableMixin):
if history_item['simulation_state'] in draft_state_list: if history_item['simulation_state'] in draft_state_list:
continue continue
# Delivery is/was not is draft state # Delivery is/was not is draft state
resolveCategory = portal.portal_categories.resolveCategory
order_dict = {} order_dict = {}
old_dict = {} old_dict = {}
# Caller may want to drop duplicate SM, like a unbuilt SM if there's # Caller may want to drop duplicate SM, like a unbuilt SM if there's
...@@ -330,7 +331,10 @@ class AppliedRule(XMLObject, ExplainableMixin): ...@@ -330,7 +331,10 @@ class AppliedRule(XMLObject, ExplainableMixin):
# remember them and returns None for duplicates. # remember them and returns None for duplicates.
sort_sm = lambda x: (not x.getDelivery(), not x.getQuantity(), x.getId()) sort_sm = lambda x: (not x.getDelivery(), not x.getQuantity(), x.getId())
for sm in sorted(self.objectValues(), key=sort_sm): for sm in sorted(self.objectValues(), key=sort_sm):
sm_dict = old_dict.setdefault(sm.getOrder() or sm.getDelivery(), {}) line = sm.getOrder() or sm.getDelivery()
# Check SM is not orphan, which happened with old buggy trees.
if resolveCategory(line) is not None:
sm_dict = old_dict.setdefault(line, {})
recurse_list = deque(({get_matching_key(sm): (sm,)},)) recurse_list = deque(({get_matching_key(sm): (sm,)},))
while recurse_list: while recurse_list:
for k, x in recurse_list.popleft().iteritems(): for k, x in recurse_list.popleft().iteritems():
...@@ -349,7 +353,8 @@ class AppliedRule(XMLObject, ExplainableMixin): ...@@ -349,7 +353,8 @@ class AppliedRule(XMLObject, ExplainableMixin):
r.setdefault(x.getSpecialise(), []).append(sm_list) r.setdefault(x.getSpecialise(), []).append(sm_list)
for x in r.values(): for x in r.values():
if len(x) > 1: if len(x) > 1:
x = [y for y in x if any(z.getDelivery() for z in y)] or x[:1] x = [y for y in x if any(z.getDelivery()
for z in y)] or x[:1]
x, = x x, = x
r = {} r = {}
for x in x: for x in x:
......
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