Commit ff479218 authored by Fabien Morin's avatar Fabien Morin

- add getSubObjectValueList method on the PaySheetTransaction Class. It return

  a list of all subobjects from the herited model
- rename getReferenceList in getReferenceDict, and now, this method return
  reference and id (dict)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18328 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3d091380
...@@ -66,12 +66,17 @@ class PaySheetModel(TradeCondition, XMLMatrix): ...@@ -66,12 +66,17 @@ class PaySheetModel(TradeCondition, XMLMatrix):
, PropertySheet.DefaultAnnotationLine , PropertySheet.DefaultAnnotationLine
) )
def getReferenceList(self, portal_type_list): def getReferenceDict(self, portal_type_list, get_none_reference=0):
''' '''
return all objects reference of the model wich portal_type is in the return all objects reference and id of the model wich portal_type is in the
portal_type_list portal_type_list
- parameters :
o get_none_reference : permit to get a dict with all references
not defined. This is usefull to get all object on the model paysheet
inherite from.
''' '''
reference_list = [] reference_dict={}
object_list = self.contentValues(portal_type=portal_type_list, object_list = self.contentValues(portal_type=portal_type_list,
sort_on='id') sort_on='id')
...@@ -83,14 +88,17 @@ class PaySheetModel(TradeCondition, XMLMatrix): ...@@ -83,14 +88,17 @@ class PaySheetModel(TradeCondition, XMLMatrix):
object.getRelativeUrl()) object.getRelativeUrl())
else: else:
reference = reference_method() reference = reference_method()
if reference is not None: if reference is not None and not get_none_reference:
reference_list.append(reference) reference_dict[reference]=object.getId()
elif reference is None and get_none_reference:
reference_dict[reference]=object.getId()
else: else:
LOG('PaySheetModel getReferenceList', 0, '%s reference ' LOG('PaySheetModel getReferenceList', 0, '%s reference '
'property is empty' % object.getTitle() or 'property is empty' % object.getTitle() or
object.getRelativeUrl()) object.getRelativeUrl())
return reference_list return reference_dict
def getInheritanceModelReferenceDict(self, model_reference_dict, def getInheritanceModelReferenceDict(self, model_reference_dict,
model_list, portal_type_list, reference_list): model_list, portal_type_list, reference_list):
...@@ -103,19 +111,19 @@ class PaySheetModel(TradeCondition, XMLMatrix): ...@@ -103,19 +111,19 @@ class PaySheetModel(TradeCondition, XMLMatrix):
model_list = [model_list,] model_list = [model_list,]
for model in model_list: for model in model_list:
model_reference_list=model.getReferenceList(portal_type_list) model_reference_list=model.getReferenceDict(portal_type_list)
unique_list = [] id_list = []
for reference in model_reference_list: for reference in model_reference_list.keys():
if reference not in reference_list: if reference not in reference_list:
reference_list.append(reference) reference_list.append(reference)
unique_list.append(reference) id_list.append(model_reference_list[reference])
if unique_list != []: if id_list != []:
model_reference_dict[model.getRelativeUrl()]=unique_list model_reference_dict[model.getRelativeUrl()]=id_list
new_model_list = model.getSpecialiseValueList() new_model_list = model.getSpecialiseValueList()
model_reference_dict = self.getInheritanceModelReferenceDict(\ self.getInheritanceModelReferenceDict(\
model_reference_dict=model_reference_dict, model_reference_dict=model_reference_dict,
model_list=new_model_list, model_list=new_model_list,
portal_type_list=portal_type_list, portal_type_list=portal_type_list,
......
...@@ -492,16 +492,44 @@ class PaySheetTransaction(Invoice): ...@@ -492,16 +492,44 @@ class PaySheetTransaction(Invoice):
return pay_sheet_line_list return pay_sheet_line_list
def copyInheritanceSubObjects(self, model_reference_dict): def getSubObjectValueList(self, portal_type_list):
''' '''
copy all sub objects containing in the dict into the current paysheet return a list of all subobject of the herited model (incuding the
dependencies)
''' '''
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=[])
pprint.pformat(model_reference_dict))
# add line of base model without reference
model_dict = model.getReferenceDict(\
portal_type_list=portal_type_list,
get_none_reference=1)
id_list = model_dict.values()
model_reference_dict[model.getRelativeUrl()].extend(id_list)
pprint.pformat(model_reference_dict))
# get sub objects
key_list = model_reference_dict.keys() key_list = model_reference_dict.keys()
sub_object_list = []
for key in key_list: for key in key_list:
id_list = model_reference_dict[key] id_list = model_reference_dict[key]
model = self.getPortalObject().restrictedTraverse(key) model = self.getPortalObject().restrictedTraverse(key)
if model is None: if model is None:
LOG("copyInheritanceSubObjects,", 0, "can't find model %s" % key) LOG("copyInheritanceSubObjects,", 0, "can't find model %s" % key)
copied_data = model.manage_copyObjects(ids=id_list)
self.manage_pasteObjects(copied_data) for id in id_list:
object = model._getOb(id)
sub_object_list.append(object)
return sub_object_list
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