Commit 63ae6a2e authored by Fabien Morin's avatar Fabien Morin

- add Version propertysheet

- add security declaration
- change some method names and description
- add methods to be able to handle model version and validity


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26053 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ec00cb92
...@@ -30,6 +30,7 @@ from AccessControl import ClassSecurityInfo ...@@ -30,6 +30,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.CMFCore.utils import getToolByName
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Document.Delivery import Delivery from Products.ERP5.Document.Delivery import Delivery
from zLOG import LOG from zLOG import LOG
...@@ -57,6 +58,7 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -57,6 +58,7 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject , PropertySheet.XMLObject
, PropertySheet.CategoryCore , PropertySheet.CategoryCore
, PropertySheet.Version
, PropertySheet.DublinCore , PropertySheet.DublinCore
, PropertySheet.Folder , PropertySheet.Folder
, PropertySheet.Comment , PropertySheet.Comment
...@@ -69,14 +71,13 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -69,14 +71,13 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
, PropertySheet.DefaultAnnotationLine , PropertySheet.DefaultAnnotationLine
) )
security.declareProtected( Permissions.View, 'getCell' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCell')
def getCell(self, *kw , **kwd): def getCell(self, *kw , **kwd):
''' '''
override of the function getCell to ba able to search a cell on the override of the function getCell to ba able to search a cell on the
inheritance model inheritance model
''' '''
cell = XMLMatrix.getCell(self, *kw, **kwd) cell = XMLMatrix.getCell(self, *kw, **kwd)
# if cell not found, look on the inherited models # if cell not found, look on the inherited models
if cell is None: if cell is None:
for specialised_model in self.getSpecialiseValueList(): for specialised_model in self.getSpecialiseValueList():
...@@ -86,6 +87,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -86,6 +87,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
return cell return cell
security.declareProtected(Permissions.AccessContentsInformation,
'getReferenceDict')
def getReferenceDict(self, portal_type_list, property_list=()): def getReferenceDict(self, portal_type_list, property_list=()):
'''Return all objects reference and id of the model wich portal_type is in '''Return all objects reference and id of the model wich portal_type is in
the portal_type_list. If type does not have a reference, it's ID is used. the portal_type_list. If type does not have a reference, it's ID is used.
...@@ -93,10 +96,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -93,10 +96,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
properties is true will be added. properties is true will be added.
''' '''
reference_dict = {} 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')
for obj in object_list: for obj in object_list:
keep = (len(property_list) == 0) keep = (len(property_list) == 0)
for property_ in property_list: for property_ in property_list:
...@@ -106,28 +107,93 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -106,28 +107,93 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
if keep: if keep:
reference_dict[obj.getProperty('reference', reference_dict[obj.getProperty('reference',
obj.getId())] = obj.getId() obj.getId())] = obj.getId()
return reference_dict return reference_dict
def getInheritanceModelReferenceDict(self, portal_type_list, property_list=()): security.declareProtected(Permissions.AccessContentsInformation,
'getInheritanceModelTreeAsList')
def getInheritanceModelTreeAsList(self):
'''Return a list of models. It uses Breadth First Search.
'''
model = self
already_add_models = [model]
model_list = [model]
final_list = [model]
while len(model_list) != 0:
model = model_list.pop(0)
specialise_list = model.getSpecialiseValueList()
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)
final_list.append(child)
return final_list
security.declareProtected(Permissions.AccessContentsInformation,
'getInheritanceEffectiveModelTreeAsList')
def getInheritanceEffectiveModelTreeAsList(self, paysheet):
'''Return a list of effective models. It uses Breadth First Search.
'''
model = self.getEffectiveModel(paysheet)
already_add_models = [model]
model_list = [model]
final_list = [model]
while len(model_list) != 0:
model = model_list.pop(0)
specialise_list = model.getSpecialiseValueList()
while len(specialise_list) !=0:
child = specialise_list.pop(0)
child = child.getEffectiveModel(paysheet)
# this should avoid circular dependencies
if child not in already_add_models:
already_add_models.append(child)
model_list.append(child)
final_list.append(child)
return final_list
security.declareProtected(Permissions.AccessContentsInformation,
'getInheritanceEffectiveModelReferenceDict')
def getInheritanceEffectiveModelReferenceDict(self, paysheet,
portal_type_list, property_list=()):
'''Returns a dict with the model url as key and a list of reference as '''Returns 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. value. Normaly, a Reference appear only one time in the final output.
It uses Breadth First Search. It uses Breadth First Search.
If property_list is not empty, documents for which all properties in If property_list is not empty, documents for which all properties in
property_list are false will be skipped. property_list are false will be skipped.
''' '''
model = self model_list = self.getInheritanceEffectiveModelTreeAsList(paysheet,
already_add_models = [model] portal_type_list,
model_list = [model] property_list)
model_reference_dict = {}
reference_list = [] reference_list = []
model_reference_dict = {}
for model in model_list:
id_list = [] id_list = []
model_reference_list = model.getReferenceDict(
portal_type_list, property_list=property_list)
for reference in model_reference_list.keys():
if reference not in reference_list:
reference_list.append(reference)
id_list.append(model_reference_list[reference])
if id_list != []:
model_reference_dict[model.getRelativeUrl()]=id_list
return model_reference_dict
while len(model_list) != 0: security.declareProtected(Permissions.AccessContentsInformation,
model = model_list.pop(0) 'getInheritanceModelReferenceDict')
def getInheritanceModelReferenceDict(self, portal_type_list,
property_list=()):
'''Returns 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 uses Breadth First Search.
If property_list is not empty, documents for which all properties in
property_list are false will be skipped.
'''
model_list = self.getInheritanceModelTreeAsList()
reference_list = []
model_reference_dict = {}
for model in model_list:
id_list = [] id_list = []
specialise_list = model.getSpecialiseValueList()
model_reference_list = model.getReferenceDict( model_reference_list = model.getReferenceDict(
portal_type_list, property_list=property_list) portal_type_list, property_list=property_list)
for reference in model_reference_list.keys(): for reference in model_reference_list.keys():
...@@ -138,12 +204,60 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -138,12 +204,60 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
if id_list != []: if id_list != []:
model_reference_dict[model.getRelativeUrl()]=id_list model_reference_dict[model.getRelativeUrl()]=id_list
while len(specialise_list) !=0: return model_reference_dict
child = specialise_list.pop(0)
# this should avoid circular dependencies security.declareProtected(Permissions.AccessContentsInformation,
if child not in already_add_models: 'getEffectiveModel')
already_add_models.append(child) def getEffectiveModel(self, context):
model_list.append(child) '''
return the more appropriate model using effective_date, expiration_date
and version number
'''
reference = self.getReference()
if not reference:
return self
return model_reference_dict effective_model_list = []
start_date = context.getStartDate()
stop_date = context.getStopDate()
model_object_list = [result.getObject() for result in \
self.portal_catalog(portal_type='Pay Sheet Model',
reference=reference,)]
#sort_on=(('version','descending'),))]
# XXX currently, version is not catalogued, so sort using python
def sortByVersion(a, b):
return cmp(b.getVersion(), a.getVersion())
model_object_list.sort(sortByVersion)
for current_model in model_object_list:
# if there is a model with exact dates, return it
if start_date == current_model.getEffectiveDate() and \
stop_date == current_model.getExpirationDate():
effective_model_list.append(current_model)
if len(effective_model_list):
return effective_model_list[0]
# else, if there is model wich has effective period containing
# the start_date and the stop date of the paysheet, return it
for current_model in model_object_list:
if start_date >= current_model.getEffectiveDate() and \
stop_date <= current_model.getExpirationDate():
effective_model_list.append(current_model)
if len(effective_model_list):
return effective_model_list[0]
# if no effective model are found (ex. because dates are None), return self
return self
security.declareProtected(Permissions.AccessContentsInformation,
'getModelIneritanceEffectiveProperty')
def getModelIneritanceEffectiveProperty(self, paysheet, property_name):
"""Get a property from an effective model
"""
v = self.getProperty(property_name)
if v:
return v
model_list = self.getInheritanceEffectiveModelTreeAsList(paysheet)
for specialised_model in model_list:
v = specialised_model.getProperty(property_name)
if v:
return v
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