Commit d1b02093 authored by Aurel's avatar Aurel

build a graph and browse it by predecessors in order to defined order

of contribution/application relation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31201 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cb295e0e
...@@ -187,28 +187,49 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -187,28 +187,49 @@ class TradeCondition(Path, Transformation, XMLMatrix):
reference = trade_model_line.getReference() reference = trade_model_line.getReference()
if reference not in reference_list or reference is None: if reference not in reference_list or reference is None:
reference_list.append(reference) reference_list.append(reference)
if len(trade_model_line.getBaseContributionList()) == 0: trade_model_line_composed_list.append(trade_model_line)
# when movement will not generate anything which contributes
# it is safe to be last on list # build a graph
trade_model_line_composed_list.append(trade_model_line) father_dict = {}
else: child_dict = {}
# parse full list of currently generated trade model lines root_line = []
# if current line applies to anything, put it after last for line in trade_model_line_composed_list:
# object it applies to father_dict.setdefault(line, [])
index = 0 for other_line in trade_model_line_composed_list:
insert_index = 0 if line == other_line:
for old_trade_model_line in trade_model_line_composed_list: continue
for base_application in trade_model_line \ child_dict.setdefault(other_line, [])
.getBaseApplicationList(): for base_application in line.getBaseApplicationList():
if base_application in old_trade_model_line \ if base_application in other_line.getBaseContributionList():
.getBaseContributionList(): father_dict[line].append(other_line)
insert_index = index + 1 child_dict[other_line].append(line)
continue
index += 1 if len(father_dict):
trade_model_line_composed_list.insert(insert_index, # find roots elements
trade_model_line) # XXX maybe this can be done while building the graph
root_line_list = []
return trade_model_line_composed_list for k, v in child_dict.iteritems():
if len(v) == 0:
root_line_list.append(k)
# sort graph according to predecessors
f = root_line_list[:]
tmp = None
cpt = 0
final_list = root_line_list[:]
while len(f):
tmp = f.pop(0)
for predecessors in father_dict[tmp]:
f.append(predecessors)
if predecessors in final_list:
final_list.remove(predecessors)
final_list.append(predecessors)
final_list.reverse()
if len(final_list) == 0:
# at least return original lines retrieved
final_list = trade_model_line_composed_list
return final_list
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList') 'getAggregatedAmountList')
......
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