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):
reference = trade_model_line.getReference()
if reference not in reference_list or reference is None:
reference_list.append(reference)
if len(trade_model_line.getBaseContributionList()) == 0:
# when movement will not generate anything which contributes
# it is safe to be last on list
trade_model_line_composed_list.append(trade_model_line)
else:
# parse full list of currently generated trade model lines
# if current line applies to anything, put it after last
# object it applies to
index = 0
insert_index = 0
for old_trade_model_line in trade_model_line_composed_list:
for base_application in trade_model_line \
.getBaseApplicationList():
if base_application in old_trade_model_line \
.getBaseContributionList():
insert_index = index + 1
continue
index += 1
trade_model_line_composed_list.insert(insert_index,
trade_model_line)
return trade_model_line_composed_list
trade_model_line_composed_list.append(trade_model_line)
# build a graph
father_dict = {}
child_dict = {}
root_line = []
for line in trade_model_line_composed_list:
father_dict.setdefault(line, [])
for other_line in trade_model_line_composed_list:
if line == other_line:
continue
child_dict.setdefault(other_line, [])
for base_application in line.getBaseApplicationList():
if base_application in other_line.getBaseContributionList():
father_dict[line].append(other_line)
child_dict[other_line].append(line)
if len(father_dict):
# find roots elements
# XXX maybe this can be done while building the graph
root_line_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,
'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