From d89aaddde7db84773a865eafb2d18980d4d237cb Mon Sep 17 00:00:00 2001 From: Fabien Morin <fabien@nexedi.com> Date: Thu, 13 Dec 2007 20:41:29 +0000 Subject: [PATCH] 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 --- product/ERP5/Document/PaySheetModel.py | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/product/ERP5/Document/PaySheetModel.py b/product/ERP5/Document/PaySheetModel.py index 0028bb4497..152c712f98 100644 --- a/product/ERP5/Document/PaySheetModel.py +++ b/product/ERP5/Document/PaySheetModel.py @@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5.Document.TradeCondition import TradeCondition from Products.ERP5Type.XMLMatrix import XMLMatrix +from zLOG import LOG, WARNING, DEBUG class PaySheetModel(TradeCondition, XMLMatrix): @@ -65,3 +66,59 @@ class PaySheetModel(TradeCondition, XMLMatrix): , 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 + -- 2.30.9