Commit 0c78c084 authored by Fabien Morin's avatar Fabien Morin

- correct bad indentation

- override the getCell method to search cells on inherited models if it's not
  find on the current model


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18590 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 07ac83df
...@@ -37,99 +37,114 @@ from zLOG import LOG, WARNING, DEBUG ...@@ -37,99 +37,114 @@ from zLOG import LOG, WARNING, DEBUG
#XXX WARNING: current API naming may change although model should be stable. #XXX WARNING: current API naming may change although model should be stable.
class PaySheetModel(TradeCondition, XMLMatrix): class PaySheetModel(TradeCondition, XMLMatrix):
""" """
PaySheetModel are used to define calculating rules specific to a PaySheetModel are used to define calculating rules specific to a
date, a convention, a enmployees group... date, a convention, a enmployees group...
This permit to applied a whole of calculating rules on a whole of This permit to applied a whole of calculating rules on a whole of
pay sheets pay sheets
""" """
meta_type = 'ERP5 Pay Sheet Model' meta_type = 'ERP5 Pay Sheet Model'
portal_type = 'Pay Sheet Model' portal_type = 'Pay Sheet Model'
isPredicate = 1 isPredicate = 1
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject , PropertySheet.XMLObject
, PropertySheet.CategoryCore , PropertySheet.CategoryCore
, PropertySheet.DublinCore , PropertySheet.DublinCore
, PropertySheet.Folder , PropertySheet.Folder
, PropertySheet.Comment , PropertySheet.Comment
, PropertySheet.Arrow , PropertySheet.Arrow
, PropertySheet.TradeCondition , PropertySheet.TradeCondition
, PropertySheet.Order , PropertySheet.Order
, PropertySheet.PaySheetModel , PropertySheet.PaySheetModel
, PropertySheet.MappedValue , PropertySheet.MappedValue
, PropertySheet.Amount , PropertySheet.Amount
, PropertySheet.DefaultAnnotationLine , PropertySheet.DefaultAnnotationLine
) )
def getReferenceDict(self, portal_type_list, get_none_reference=0): security.declareProtected( Permissions.View, 'getCell' )
''' def getCell(self, *kw , **kwd):
return all objects reference and id of the model wich portal_type is in the '''
portal_type_list override of the function getCell to ba able to search a cell on the
- parameters : inheritance model
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 LOG('getCell ', 0, kw)
inherite from. cell = XMLMatrix.getCell(self, *kw, **kwd)
'''
reference_dict={} # if cell not found, look on the inherited models
if cell is None and self.getSpecialiseValue() is not None:
object_list = self.contentValues(portal_type=portal_type_list, cell = self.getSpecialiseValue().getCell(*kw, **kwd)
sort_on='id') return cell
for object in object_list:
reference_method = getattr(object, 'getReference', None) def getReferenceDict(self, portal_type_list, get_none_reference=0):
if reference_method is None: '''
LOG('PaySheetModel getReferenceList', 0, '%s have not ' return all objects reference and id of the model wich portal_type is in the
'getReference method' % object.getTitle() or portal_type_list
object.getRelativeUrl()) - parameters :
else: o get_none_reference : permit to get a dict with all references
reference = reference_method() not defined. This is usefull to get all object on the model paysheet
if reference is not None and not get_none_reference: inherite from.
reference_dict[reference]=object.getId() '''
elif reference is None and get_none_reference: reference_dict={}
reference_dict[object.getId()]=object.getId()
object_list = self.contentValues(portal_type=portal_type_list,
return reference_dict sort_on='id')
def getInheritanceModelReferenceDict(self, portal_type_list): for object in object_list:
''' reference_method = getattr(object, 'getReference', None)
return a dict with the model url as key and a list of reference if reference_method is None:
as value. Normaly, a Reference appear only one time in the final output LOG('PaySheetModel getReferenceList', 0, '%s have not '
It's use a Breadth First Search 'getReference method' % object.getTitle() or
''' object.getRelativeUrl())
model = self else:
already_add_models = [model] reference = reference_method()
model_list = [model] if reference is not None and not get_none_reference:
model_reference_dict = {} reference_dict[reference]=object.getId()
reference_list = [] elif reference is None and get_none_reference:
reference_dict[object.getId()]=object.getId()
return reference_dict
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
'''
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 = [] id_list = []
specialise_list = model.getSpecialiseValueList()
while len(model_list) != 0: model_reference_list=model.getReferenceDict(portal_type_list)
model = model_list.pop(0) for reference in model_reference_list.keys():
id_list = [] if reference not in reference_list:
specialise_list = model.getSpecialiseValueList() reference_list.append(reference)
id_list.append(model_reference_list[reference])
model_reference_list=model.getReferenceDict(portal_type_list) if id_list != []:
for reference in model_reference_list.keys(): model_reference_dict[model.getRelativeUrl()]=id_list
if reference not in reference_list:
reference_list.append(reference)
id_list.append(model_reference_list[reference])
if id_list != []: while len(specialise_list) !=0:
model_reference_dict[model.getRelativeUrl()]=id_list child = specialise_list.pop(0)
while len(specialise_list) !=0: # this should avoid circular dependencies
child = specialise_list.pop(0) if child not in already_add_models:
already_add_models.append(child)
model_list.append(child)
# this should avoid circular dependencies return model_reference_dict
if child not in already_add_models:
already_add_models.append(child)
model_list.append(child)
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