Commit 497b1797 authored by Fabien Morin's avatar Fabien Morin

move out findSpecialiseValueList method to have it on the class (she is...

move out findSpecialiseValueList method to have it on the class (she is usefull for class wich inherite of TradeCondition).
Change a bit it to accept portal_type_list parameter to be able to have inheritance tree of another portal_type thant caller (ie. 'Business Process' in 'Pay Sheet Model')
Change also getTradeModelLineComposedList to accept portal_type_list parameter for the same reasons


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27314 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9ee4c15a
...@@ -114,25 +114,37 @@ class TradeCondition(Path, Transformation): ...@@ -114,25 +114,37 @@ class TradeCondition(Path, Transformation):
return {'movement_to_delete_list' : movement_to_delete_list, return {'movement_to_delete_list' : movement_to_delete_list,
'movement_to_add_list': movement_to_add_list} 'movement_to_add_list': movement_to_add_list}
def getTradeModelLineComposedList(self, context=None): security.declareProtected(Permissions.AccessContentsInformation,
""" 'findSpecialiseValueList')
Returns list of Trade Model Lines using composition def findSpecialiseValueList(self, context, portal_type_list=None):
Reference of Trade Model Line is used to hide other Trade Model Line '''Return a list of object. The list will represent the inheritance tree.
In chain first found Trade Model Line has precedence It uses Breadth First Search.
Context's, if not None, Trade Model Lines have precedence '''
"""
visited_trade_condition_list = [] visited_trade_condition_list = []
def findSpecialiseValueList(context):
specialise_value_list = [] specialise_value_list = []
if context.getPortalType() in self.getPortalType(): if portal_type_list is None:
portal_type_list = [self.getPortalType()]
if context.getPortalType() in portal_type_list:
specialise_value_list.append(context) specialise_value_list.append(context)
for specialise in context.getSpecialiseValueList(): for specialise in context.getSpecialiseValueList(portal_type=\
portal_type_list):
if specialise in visited_trade_condition_list: if specialise in visited_trade_condition_list:
raise CircularException raise CircularException
visited_trade_condition_list.append(specialise) visited_trade_condition_list.append(specialise)
specialise_value_list.extend(findSpecialiseValueList(specialise)) specialise_value_list.extend(self.findSpecialiseValueList(context=specialise,
portal_type_list=portal_type_list))
return specialise_value_list return specialise_value_list
def getTradeModelLineComposedList(self, context=None, portal_type_list=None):
"""
Returns list of Trade Model Lines using composition
Reference of Trade Model Line is used to hide other Trade Model Line
In chain first found Trade Model Line has precedence
Context's, if not None, Trade Model Lines have precedence
"""
if portal_type_list is None:
portal_type_list = self.model_line_portal_type_list
def sortByIntIndex(a, b): def sortByIntIndex(a, b):
return cmp(a.getIntIndex(), b.getIntIndex()) return cmp(a.getIntIndex(), b.getIntIndex())
...@@ -146,11 +158,11 @@ class TradeCondition(Path, Transformation): ...@@ -146,11 +158,11 @@ class TradeCondition(Path, Transformation):
# for contained Trade Model Lines # for contained Trade Model Lines
document = context.getExplanationValue() document = context.getExplanationValue()
containting_object_list.append(document) containting_object_list.append(document)
containting_object_list.extend(findSpecialiseValueList(self)) containting_object_list.extend(self.findSpecialiseValueList(self))
for specialise in containting_object_list: for specialise in containting_object_list:
for trade_model_line in specialise.contentValues( for trade_model_line in specialise.contentValues(
portal_type=self.model_line_portal_type_list): portal_type=portal_type_list):
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:
trade_model_line_composed_list.append(trade_model_line) trade_model_line_composed_list.append(trade_model_line)
......
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