Commit d89aaddd authored by Fabien Morin's avatar Fabien Morin

add two method that permit to know all references depending on the model inheritance


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18318 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eecbfc40
...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.TradeCondition import TradeCondition from Products.ERP5.Document.TradeCondition import TradeCondition
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from zLOG import LOG, WARNING, DEBUG
class PaySheetModel(TradeCondition, XMLMatrix): class PaySheetModel(TradeCondition, XMLMatrix):
...@@ -65,3 +66,59 @@ class PaySheetModel(TradeCondition, XMLMatrix): ...@@ -65,3 +66,59 @@ class PaySheetModel(TradeCondition, XMLMatrix):
, PropertySheet.DefaultAnnotationLine , PropertySheet.DefaultAnnotationLine
) )
def getReferenceList(self, portal_type_list):
'''
return all objects reference of the model wich portal_type is in the
portal_type_list
'''
reference_list = []
object_list = self.contentValues(portal_type=portal_type_list,
sort_on='id')
for object in object_list:
reference_method = getattr(object, 'getReference', None)
if reference_method is None:
LOG('PaySheetModel getReferenceList', 0, '%s have not '
'getReference method' % object.getTitle() or
object.getRelativeUrl())
else:
reference = reference_method()
if reference is not None:
reference_list.append(reference)
else:
LOG('PaySheetModel getReferenceList', 0, '%s reference '
'property is empty' % object.getTitle() or
object.getRelativeUrl())
return reference_list
def getInheritanceModelReferenceDict(self, model_reference_dict,
model_list, portal_type_list, reference_list):
'''
return a dict with the model url as key and a list of reference
as value. Normaly, a Reference appear only one time in the final output
'''
# handle the case where just one model is given
if type(model_list) != type([]):
model_list = [model_list,]
for model in model_list:
model_reference_list=model.getReferenceList(portal_type_list)
unique_list = []
for reference in model_reference_list:
if reference not in reference_list:
reference_list.append(reference)
unique_list.append(reference)
model_reference_dict[model.getRelativeUrl()]=unique_list
new_model_list = model.getSpecialiseValueList()
model_reference_dict = self.getInheritanceModelReferenceDict(\
model_reference_dict=model_reference_dict,
model_list=new_model_list,
portal_type_list=portal_type_list,
reference_list=reference_list,)
return model_reference_dict
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