From 76e8d6061d09ade6d43e1414c54831654d8e9591 Mon Sep 17 00:00:00 2001 From: Fabien Morin <fabien@nexedi.com> Date: Sat, 15 Dec 2007 19:08:36 +0000 Subject: [PATCH] - typo - remove commented code - modify getInheritanceModelReferenceDict method to use a Breadth First Search instead of Depth First Search witch is very more appropiate in this case. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18344 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/PaySheetModel.py | 37 ++++++++++++-------- product/ERP5/Document/PaySheetTransaction.py | 31 +++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/product/ERP5/Document/PaySheetModel.py b/product/ERP5/Document/PaySheetModel.py index 279ac04a87..294ddea655 100644 --- a/product/ERP5/Document/PaySheetModel.py +++ b/product/ERP5/Document/PaySheetModel.py @@ -33,6 +33,8 @@ from Products.ERP5.Document.TradeCondition import TradeCondition from Products.ERP5Type.XMLMatrix import XMLMatrix from zLOG import LOG, WARNING, DEBUG +#XXX TODO: review naming of new methods +#XXX WARNING: current API naming may change although model should be stable. class PaySheetModel(TradeCondition, XMLMatrix): """ @@ -95,20 +97,25 @@ class PaySheetModel(TradeCondition, XMLMatrix): return reference_dict - def getInheritanceModelReferenceDict(self, model_reference_dict, - model_list, portal_type_list, reference_list): + def getInheritanceModelReferenceDict(self, portal_type_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 + It's use a Breadth First Search ''' - # 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.getReferenceDict(portal_type_list) + model = self + already_add_models = [model] + model_list = [model] + model_reference_dict = {} + reference_list = [] + id_list = [] + + while len(model_list) != 0: + model = model_list.pop(0) id_list = [] + specialise_list = model.getSpecialiseValueList() + model_reference_list=model.getReferenceDict(portal_type_list) for reference in model_reference_list.keys(): if reference not in reference_list: reference_list.append(reference) @@ -117,10 +124,12 @@ class PaySheetModel(TradeCondition, XMLMatrix): if id_list != []: model_reference_dict[model.getRelativeUrl()]=id_list - new_model_list = model.getSpecialiseValueList() - self.getInheritanceModelReferenceDict(\ - model_reference_dict=model_reference_dict, - model_list=new_model_list, - portal_type_list=portal_type_list, - reference_list=reference_list,) + while len(specialise_list) !=0: + child = specialise_list.pop(0) + + # this should avoid circular dependencies + if child not in already_add_models: + already_add_models.append(child) + model_list.append(child) + return model_reference_dict diff --git a/product/ERP5/Document/PaySheetTransaction.py b/product/ERP5/Document/PaySheetTransaction.py index 1e22fea94a..e7d1b19341 100644 --- a/product/ERP5/Document/PaySheetTransaction.py +++ b/product/ERP5/Document/PaySheetTransaction.py @@ -399,13 +399,15 @@ class PaySheetTransaction(Invoice): 0, tuple) continue - if len(cell.getVariationCategoryList(base_category_list='tax_category')): - share = \ - cell.getVariationCategoryList(base_category_list='tax_category')[0] - - if len(cell.getVariationCategoryList(base_category_list='salary_range')): - slice = \ - cell.getVariationCategoryList(base_category_list='salary_range')[0] + if len(cell.getVariationCategoryList(\ + base_category_list='tax_category')): + share = cell.getVariationCategoryList(\ + base_category_list='tax_category')[0] + + if len(cell.getVariationCategoryList(\ + base_category_list='salary_range')): + slice = cell.getVariationCategoryList(\ + base_category_list='salary_range')[0] # get the edited values if this model_line is editable # and replace the original cell values by this ones @@ -485,12 +487,6 @@ class PaySheetTransaction(Invoice): quantity = cell_dict['quantity'] price = cell_dict['price'] -# # Define an empty new cell -# new_cell = { 'axe_list' : tuple, # share, slice -# 'quantity' : quantity, -# 'price' : price, -# #'categories' : causality/machin_module/annotation_line, -# } cell_list.append(cell_dict) # update the base_participation @@ -539,12 +535,9 @@ class PaySheetTransaction(Invoice): ''' model = self.getSpecialiseValue() - model_reference_dict={} - model.getInheritanceModelReferenceDict(\ - model_reference_dict=model_reference_dict, - model_list=model, - portal_type_list=portal_type_list, - reference_list=[]) + model_reference_dict = \ + model.getInheritanceModelReferenceDict(\ + portal_type_list=portal_type_list) # add line of base model without reference model_dict = model.getReferenceDict(\ -- 2.30.9