Commit e16d63be authored by Fabien Morin's avatar Fabien Morin

- change some methods names

- reuse more code from TradeCondition
- add getAggregatedAmountList method


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27415 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 680d5e47
############################################################################## ##############################################################################
# #
# Copyright (c) 2007, Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2007-2009, Nexedi SA and Contributors. All Rights Reserved.
# Fabien Morin <fabien@nexedi.com> # Fabien Morin <fabien@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
...@@ -48,6 +48,7 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -48,6 +48,7 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
meta_type = 'ERP5 Pay Sheet Model' meta_type = 'ERP5 Pay Sheet Model'
portal_type = 'Pay Sheet Model' portal_type = 'Pay Sheet Model'
model_line_portal_type_list = 'Pay Sheet Model Line'
isPredicate = 1 isPredicate = 1
# Declarative security # Declarative security
...@@ -74,16 +75,18 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -74,16 +75,18 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
security.declareProtected( Permissions.AccessContentsInformation, '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 Overload the function getCell to be able to search a cell on the
inheritance model inheritance model tree
''' '''
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:
if kwd.has_key('paysheet'): if kwd.has_key('paysheet'):
model_list = self.getInheritanceEffectiveModelTreeAsList(kwd['paysheet']) model_list = self.findEffectiveSpecialiseValueList(\
start_date=kwd['paysheet'].getStartDate(),
stop_date=kwd['paysheet'].getStopDate())
else: else:
model_list = self.getInheritanceModelTreeAsList() model_list = self.findSpecialiseValueList(context=self)
if self in model_list: if self in model_list:
model_list.remove(self) model_list.remove(self)
for specialised_model in model_list: for specialised_model in model_list:
...@@ -110,83 +113,25 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -110,83 +113,25 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
keep = 1 keep = 1
break break
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
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getInheritanceModelTreeAsList') 'findEffectiveSpecialiseValueList')
def getInheritanceModelTreeAsList(self): def findEffectiveSpecialiseValueList(self, start_date=None, stop_date=None):
'''Return a list of models. It uses Breadth First Search. '''Return a list of effective models
''' '''
model = self model_list = self.findSpecialiseValueList(self)
already_add_models = [model] if start_date is None and stop_date is None:
model_list = [model] return model_list
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, new_list = [model.getEffectiveModel(start_date, stop_date) for model in\
'getInheritanceEffectiveModelTreeAsList') model_list]
def getInheritanceEffectiveModelTreeAsList(self, paysheet): return new_list
'''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
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.getInheritanceEffectiveModelTreeAsList(paysheet,
portal_type_list,
property_list)
reference_list = []
model_reference_dict = {}
for model in model_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
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getInheritanceModelReferenceDict') 'getInheritanceReferenceDict')
def getInheritanceModelReferenceDict(self, portal_type_list, def getInheritanceReferenceDict(self, portal_type_list,
property_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.
...@@ -194,7 +139,7 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -194,7 +139,7 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
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_list = self.getInheritanceModelTreeAsList() model_list = self.findSpecialiseValueList(context=self)
reference_list = [] reference_list = []
model_reference_dict = {} model_reference_dict = {}
for model in model_list: for model in model_list:
...@@ -213,9 +158,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -213,9 +158,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getEffectiveModel') 'getEffectiveModel')
def getEffectiveModel(self, context): def getEffectiveModel(self, start_date=None, stop_date=None):
''' '''return the more appropriate model using effective_date, expiration_date
return the more appropriate model using effective_date, expiration_date
and version number and version number
''' '''
reference = self.getReference() reference = self.getReference()
...@@ -223,8 +167,6 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -223,8 +167,6 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
return self return self
effective_model_list = [] effective_model_list = []
start_date = context.getStartDate()
stop_date = context.getStopDate()
model_object_list = [result.getObject() for result in \ model_object_list = [result.getObject() for result in \
self.portal_catalog(portal_type='Pay Sheet Model', self.portal_catalog(portal_type='Pay Sheet Model',
reference=reference,)] reference=reference,)]
...@@ -261,8 +203,39 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery): ...@@ -261,8 +203,39 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
v = self.getProperty(property_name) v = self.getProperty(property_name)
if v: if v:
return v return v
model_list = self.getInheritanceEffectiveModelTreeAsList(paysheet) model_list = self.findEffectiveSpecialiseValueList(\
start_date=paysheet.getStartDate(), stop_date=paysheet.getStopDate())
for specialised_model in model_list: for specialised_model in model_list:
v = specialised_model.getProperty(property_name) v = specialised_model.getProperty(property_name)
if v: if v:
return v return v
def getAggregatedAmountList(self, context, **kw):
from Products.ERP5Type.Document import newTempSimulationMovement
movement_list = []
cell_list = context.getMovementList()
for cell in cell_list:
self_id = 'transaction_cell' + cell.getParentValue().getId() + '_' \
+ cell.getId()
tmp_movement = newTempSimulationMovement(self.getPortalObject(), self_id )
tmp_movement.edit(
title=cell.getTitle(),
int_index=cell.getIntIndex(),
causality=cell.getRelativeUrl(),
resource=cell.getResource(),
description=cell.getDescription(),
base_application_list=cell.getBaseApplicationList(),
base_contribution_list=cell.getBaseContributionList(),
variation_category_list=cell.getVariationCategoryList(),
price = cell.getPrice(),
quantity = cell.getQuantity(0.0),)
movement_list.append(tmp_movement)
movement_list = TradeCondition.getAggregatedAmountList(self, context,
movement_list, **kw)
# remove movement that should not be created
final_list = []
for movement in movement_list:
if getattr(movement, 'create_line', True):
final_list.append(movement)
return final_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