Commit 5a3a589a authored by Nicolas Dumazet's avatar Nicolas Dumazet

Fix wrong behaviour of Transformation.getAggregatedAmountList:

an Amount context should _always_ be passed to this method.

this fixes TestTransformation.test_01_getAggregatedAmountListSimple


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33831 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 74838d44
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
############################################################################## ##############################################################################
import zope.interface import zope.interface
from warnings import warn
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
...@@ -247,7 +249,15 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -247,7 +249,15 @@ class Transformation(XMLObject, Predicate, Variated):
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 = self.asContext(context=context, REQUEST=REQUEST, **kw) if context is None:
warn("Calling Transformation.getAggregatedAmountList without context " \
"is wrong. Context should be an Amount defining the resource to " \
"produce", DeprecationWarning)
from Products.ERP5Type.Document import newTempAmount
context = newTempAmount(self, "deprecated_usage")
context.setResourceValue(self.getResourceValue())
context.setQuantity(1.0)
# A list of functions taking a transformation_line as sole argument # A list of functions taking a transformation_line as sole argument
# and returning True iif the line should be kept in the result # and returning True iif the line should be kept in the result
......
...@@ -133,13 +133,12 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount): ...@@ -133,13 +133,12 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList') 'getAggregatedAmountList')
def getAggregatedAmountList(self, context=None, REQUEST=None, **kw): def getAggregatedAmountList(self, context, REQUEST=None, **kw):
""" """
Get all interesting amount value and return AggregatedAmountList Get all interesting amount value and return AggregatedAmountList
""" """
from Products.ERP5Type.Document import newTempAmount from Products.ERP5Type.Document import newTempAmount
context = self.asContext(context=context, REQUEST=REQUEST, **kw)
# Create the result object # Create the result object
aggregated_amount_list = AggregatedAmountList() aggregated_amount_list = AggregatedAmountList()
test_result = self.test(context) test_result = self.test(context)
......
...@@ -108,9 +108,11 @@ class TestTransformation(TestTransformationMixin, ERP5TypeTestCase): ...@@ -108,9 +108,11 @@ class TestTransformation(TestTransformationMixin, ERP5TypeTestCase):
component = self.createComponent() component = self.createComponent()
transformed_resource.edit( transformed_resource.edit(
resource_value=component, resource_value=component,
quantity=1) quantity=2)
aggregated_amount_list = transformation.getAggregatedAmountList() aggregated_amount_list = transformation.getAggregatedAmountList()
self.assertEquals(len(aggregated_amount_list), 1) self.assertEquals(len(aggregated_amount_list), 1)
aggregated_amount = aggregated_amount_list[0]
self.assertEquals(aggregated_amount.quantity, 2)
def test_01_getAggregatedAmountListWithVariatedProperty(self): def test_01_getAggregatedAmountListWithVariatedProperty(self):
""" """
......
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