[Erp5-report] r31201 aurel - /erp5/trunk/products/ERP5/Document/TradeCondition.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Dec 9 17:32:04 CET 2009
Author: aurel
Date: Wed Dec 9 17:32:03 2009
New Revision: 31201
URL: http://svn.erp5.org?rev=31201&view=rev
Log:
build a graph and browse it by predecessors in order to defined order
of contribution/application relation
Modified:
erp5/trunk/products/ERP5/Document/TradeCondition.py
Modified: erp5/trunk/products/ERP5/Document/TradeCondition.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TradeCondition.py?rev=31201&r1=31200&r2=31201&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] Wed Dec 9 17:32:03 2009
@@ -187,28 +187,49 @@
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')
More information about the Erp5-report
mailing list