Commit 38913b13 authored by Romain Courteaud's avatar Romain Courteaud

Add methods getTotalBasePrice, getTotalDuration on AggregatedAmountList class.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2645 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fd8688f6
...@@ -39,6 +39,9 @@ from Products.ERP5.Variated import Variated ...@@ -39,6 +39,9 @@ from Products.ERP5.Variated import Variated
from Products.ERP5.Document.Domain import Domain from Products.ERP5.Document.Domain import Domain
from Globals import InitializeClass
from Products.PythonScripts.Utility import allow_class
import string import string
from zLOG import LOG from zLOG import LOG
...@@ -96,17 +99,13 @@ class Transformation(XMLObject, Domain, Variated): ...@@ -96,17 +99,13 @@ class Transformation(XMLObject, Domain, Variated):
default resource which can be used a variation axis default resource which can be used a variation axis
in the transformation. in the transformation.
""" """
#resource = self.getDefaultResourceValue()
resource = self.getResourceValue() resource = self.getResourceValue()
if resource is not None: if resource is not None:
#result = [''] + resource.getVariationBaseCategoryList()
result = resource.getVariationBaseCategoryList() result = resource.getVariationBaseCategoryList()
else: else:
# XXX result = self.getBaseCategoryIds() # XXX result = self.getBaseCategoryIds()
# Why calling this method ? # Why calling this method ?
# Get a global variable which define a list of variation base category # Get a global variable which define a list of variation base category
# XXX I don' t like this approch, maybe can we define this variable
# on Transformation property sheet ? (Romain)
result = self.getPortalVariationBaseCategoryList() result = self.getPortalVariationBaseCategoryList()
return result return result
...@@ -219,7 +218,7 @@ class Transformation(XMLObject, Domain, Variated): ...@@ -219,7 +218,7 @@ class Transformation(XMLObject, Domain, Variated):
resource = self.portal_categories.resolveCategory(variation_category) resource = self.portal_categories.resolveCategory(variation_category)
if resource.getPortalType() == 'Category': if resource.getPortalType() == 'Category':
# Category is unusable if only Title is displayed... # XXX Category is unusable if only Title is displayed...
value = getattr(resource, 'getLogicalPath')() value = getattr(resource, 'getLogicalPath')()
else: else:
# And displaying LogicalPath for variation is unusable for user... # And displaying LogicalPath for variation is unusable for user...
...@@ -263,67 +262,32 @@ class Transformation(XMLObject, Domain, Variated): ...@@ -263,67 +262,32 @@ class Transformation(XMLObject, Domain, Variated):
return result return result
# XXX subclassing directly list would be better, but does not work yet (error with class and security)
# # UPDATED BY JPS from UserList import UserList
# class AggregatedAmountList(UserList):
# # XXX This should not be there, but in Document/TransformedResource.py or something like
# # this, but actually this does not work, we should find why.
# security.declareProtected(Permissions.ModifyPortalContent, '_setVariationBaseCategoryList')
# def _setVariationBaseCategoryList(self, new_base_category_list):
# """
# We override the default behaviour generated by Utils.py in order
# to update all TransformedResource contained in this transformation
# """
# # Get the list of previous base_category that have been removed or kept
# removed_base_category = []
# kept_base_category = []
# for cat in self.getVariationBaseCategoryList():
# if cat in new_base_category_list:
# kept_base_category += [cat]
# else:
# removed_base_category += [cat]
#
# # Update variation_base_category_list
# self.variation_base_category_list = new_base_category_list
#
# # Make sure there is no reference to categories
# # of removed_base_category
# # in categories
# if len(removed_base_category) > 0:
# self._setCategoryMembership(removed_base_category, [], base=1)
#
# # Filter all fields which are based on base_category
# if self.getVariationBaseCategoryLine() not in new_base_category_list:
# self._setVariationBaseCategoryLine(None)
# if self.getVariationBaseCategoryColumn() not in new_base_category_list:
# self._setVariationBaseCategoryColumn(None)
# self._setVariationBaseCategoryTabList(keepIn(self.getVariationBaseCategoryTabList(),
# new_base_category_list))
#
# # Make sure that all sub-objects use a valid range
# # We simply call range functions on each object to force
# # range update in XMLMatrix
# for o in self.objectValues():
# if hasattr(o,'v_variation_base_category_list'):
# o.setVVariationBaseCategoryList(keepIn(o.getVVariationBaseCategoryList(),
# new_base_category_list))
# if hasattr(o,'q_variation_base_category_list'):
# o.setQVariationBaseCategoryList(keepIn(o.getQVariationBaseCategoryList(),
# new_base_category_list))
class AggregatedAmountList(list):
""" """
Temporary object needed to aggregate Amount value Temporary object needed to aggregate Amount value
And to calculate some report or total value And to calculate some report or total value
""" """
meta_type = "AggregatedAmountList" meta_type = "AggregatedAmountList"
security = ClassSecurityInfo() security = ClassSecurityInfo()
# security.declareObjectPublic()
# def append(self, element): security.declarePublic('getTotalBasePrice')
# return list.append(self, element) def getTotalBasePrice(self):
# """
# def extend(self, list): Return total bas price of the transformation
# return list.extend(self, list) """
result = sum( filter(lambda y: y is not None ,map( lambda x: x.getTotalBasePrice(), self)) )
return result
security.declarePublic('getTotalDuration')
def getTotalDuration(self):
"""
Return total duration of the transformation
"""
result = sum( filter(lambda y: y is not None ,map( lambda x: x.getDuration(), self) ))
return result
InitializeClass(AggregatedAmountList)
allow_class(AggregatedAmountList)
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