Commit 7082d0e5 authored by Sebastien Robin's avatar Sebastien Robin

allow to take into account the quantity of the context in getAggregatedAmountList


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4319 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 04e926e1
...@@ -258,11 +258,15 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -258,11 +258,15 @@ class Transformation(XMLObject, Predicate, Variated):
'getAggregatedAmountList') 'getAggregatedAmountList')
def getAggregatedAmountList(self, context=None, REQUEST=None, def getAggregatedAmountList(self, context=None, REQUEST=None,
ind_phase_id_list=None, ind_phase_id_list=None,
rejected_resource_uid_list=None, **kw): rejected_resource_uid_list=None,
context_quantity=0,**kw):
""" """
getAggregatedAmountList returns a AggregatedAmountList which getAggregatedAmountList returns a AggregatedAmountList which
can be used either to do some calculation (ex. price, BOM) can be used either to do some calculation (ex. price, BOM)
or to display a detailed view of a transformation. or to display a detailed view of a transformation.
context_quantity : if set to one, multiply all quantities
with the quantity of the context
""" """
context = self.asContext(context=context, REQUEST=REQUEST, **kw) context = self.asContext(context=context, REQUEST=REQUEST, **kw)
# First we need to get the list of transformations which this # First we need to get the list of transformations which this
...@@ -293,6 +297,8 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -293,6 +297,8 @@ class Transformation(XMLObject, Predicate, Variated):
# Browse each transformed or assorted resource of the current # Browse each transformed or assorted resource of the current
# transformation # transformation
result.extend(transformation_line.getAggregatedAmountList(context)) result.extend(transformation_line.getAggregatedAmountList(context))
if context_quantity:
result.multiplyQuantity(context=context)
return result return result
# XXX subclassing directly list would be better, # XXX subclassing directly list would be better,
...@@ -325,5 +331,20 @@ class AggregatedAmountList(UserList): ...@@ -325,5 +331,20 @@ class AggregatedAmountList(UserList):
map(lambda x: x.getDuration(), self))) map(lambda x: x.getDuration(), self)))
return result return result
def multiplyQuantity(self,context=None):
"""
Take into account the quantity of the
context. Change the quantity of each element.
"""
quantity = None
if context is not None:
if context.getQuantity() is not None:
quantity = context.getQuantity()
if quantity is not None:
for x in self:
previous_quantity = x.getQuantity()
if previous_quantity is not None:
x.edit(quantity=context.getQuantity()*previous_quantity)
InitializeClass(AggregatedAmountList) InitializeClass(AggregatedAmountList)
allow_class(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