Commit 5ffaca0d authored by Jérome Perrin's avatar Jérome Perrin

getInheritedObjectValueList: allow to pass a list of properties to check on

objects. If none of those properties are set, we ignore the subobject.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21432 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 76a7c7fa
......@@ -86,25 +86,35 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
return cell
def getReferenceDict(self, portal_type_list):
def getReferenceDict(self, portal_type_list, property_list=()):
'''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.
If property_list is provided, only objects for which at least one of
properties is true will be added.
'''
reference_dict={}
reference_dict = {}
object_list = self.contentValues(portal_type=portal_type_list,
sort_on='id')
for obj in object_list:
reference_dict[obj.getProperty('reference', obj.getId())] = obj.getId()
keep = (len(property_list) == 0)
for property_ in property_list:
if obj.hasProperty(property_):
keep = 1
break
if keep:
reference_dict[obj.getProperty('reference',
obj.getId())] = obj.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
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 = self
already_add_models = [model]
......@@ -118,7 +128,8 @@ class PaySheetModel(TradeCondition, XMLMatrix, Delivery):
id_list = []
specialise_list = model.getSpecialiseValueList()
model_reference_list=model.getReferenceDict(portal_type_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)
......
......@@ -324,6 +324,7 @@ class PaySheetTransaction(Invoice):
return cmp(a.getIntIndex(), b.getIntIndex())
# XXX should this be recursive ? then should membership be strict
base_amount_list = paysheet.portal_categories['base_amount'].contentValues()
base_amount_list.sort(sortByIntIndex)
......@@ -507,13 +508,16 @@ class PaySheetTransaction(Invoice):
return pay_sheet_line_list
def getInheritedObjectValueList(self, portal_type_list):
def getInheritedObjectValueList(self, portal_type_list, property_list=()):
'''Return a list of all subobjects of the herited model (incuding the
dependencies)
dependencies).
If property_list is provided, only subobjects with at least one of those
properties is defined will be taken into account
'''
model = self.getSpecialiseValue()
model_reference_dict = model.getInheritanceModelReferenceDict(
portal_type_list=portal_type_list)
portal_type_list=portal_type_list,
property_list=property_list)
sub_object_list = []
traverse = self.getPortalObject().unrestrictedTraverse
......
......@@ -1437,6 +1437,48 @@ class TestPayroll(TestPayrollMixin):
self.assertEquals(2, len(paysheet.contentValues()))
def test_apply_model_empty_line(self):
# apply a model with some empty lines
eur = self.portal.currency_module.EUR
employee = self.portal.person_module.newContent(
portal_type='Person',
title='Employee')
employer = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Employer')
model = self.portal.paysheet_model_module.newContent(
portal_type='Pay Sheet Model',
source_section_value=employee,
destination_section_value=employer,
price_currency_value=eur,
payment_condition_payment_date=DateTime(2008, 1, 1),
work_time_annotation_line_quantity=10)
employee_model = self.portal.paysheet_model_module.newContent(
portal_type='Pay Sheet Model',
specialise_value=model,
work_time_annotation_line_quantity=20)
employee_model.setWorkTimeAnnotationLineQuantity(None)
paysheet = self.portal.accounting_module.newContent(
portal_type='Pay Sheet Transaction',
specialise_value=employee_model)
paysheet.PaySheetTransaction_applyModel()
self.assertEquals(employee, paysheet.getSourceSectionValue())
self.assertEquals(employer, paysheet.getDestinationSectionValue())
self.assertEquals(eur, paysheet.getResourceValue())
self.assertEquals(eur, paysheet.getPriceCurrencyValue())
self.assertEquals(DateTime(2008, 1, 1),
paysheet.getPaymentConditionPaymentDate())
# WorkTimeAnnotationLine is not taken on employee_model, because the line
# is "empty", it is taken on model.
self.assertEquals(10, paysheet.getWorkTimeAnnotationLineQuantity())
# applying twice does not copy subdocument twice
self.assertEquals(2, len(paysheet.contentValues()))
paysheet.PaySheetTransaction_applyModel()
self.assertEquals(2, len(paysheet.contentValues()))
import unittest
def test_suite():
suite = unittest.TestSuite()
......
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