From 5a3a589af80387c4a3c0d512c7ee08b81757f6ca Mon Sep 17 00:00:00 2001
From: Nicolas Dumazet <nicolas.dumazet@nexedi.com>
Date: Thu, 18 Mar 2010 03:38:02 +0000
Subject: [PATCH] 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
---
 product/ERP5/Document/Transformation.py      | 12 +++++++++++-
 product/ERP5/Document/TransformedResource.py |  3 +--
 product/ERP5/tests/testTransformation.py     |  4 +++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/product/ERP5/Document/Transformation.py b/product/ERP5/Document/Transformation.py
index 3c17804e43..bfb6c3c817 100644
--- a/product/ERP5/Document/Transformation.py
+++ b/product/ERP5/Document/Transformation.py
@@ -31,6 +31,8 @@
 ##############################################################################
 
 import zope.interface
+
+from warnings import warn
 from AccessControl import ClassSecurityInfo
 
 from Products.ERP5Type import Permissions, PropertySheet, interfaces
@@ -247,7 +249,15 @@ class Transformation(XMLObject, Predicate, Variated):
         can be used either to do some calculation (ex. price, BOM)
         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
       # and returning True iif the line should be kept in the result
diff --git a/product/ERP5/Document/TransformedResource.py b/product/ERP5/Document/TransformedResource.py
index d5fad98c47..53a25cd1d4 100644
--- a/product/ERP5/Document/TransformedResource.py
+++ b/product/ERP5/Document/TransformedResource.py
@@ -133,13 +133,12 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
 
     security.declareProtected(Permissions.AccessContentsInformation, 
                               'getAggregatedAmountList')
-    def getAggregatedAmountList(self, context=None, REQUEST=None, **kw):
+    def getAggregatedAmountList(self, context, REQUEST=None, **kw):
       """
         Get all interesting amount value and return AggregatedAmountList
       """
       from Products.ERP5Type.Document import newTempAmount
 
-      context = self.asContext(context=context, REQUEST=REQUEST, **kw)
       # Create the result object
       aggregated_amount_list = AggregatedAmountList()
       test_result = self.test(context)
diff --git a/product/ERP5/tests/testTransformation.py b/product/ERP5/tests/testTransformation.py
index 796f01707f..2ed4b5f402 100644
--- a/product/ERP5/tests/testTransformation.py
+++ b/product/ERP5/tests/testTransformation.py
@@ -108,9 +108,11 @@ class TestTransformation(TestTransformationMixin, ERP5TypeTestCase):
     component = self.createComponent()
     transformed_resource.edit(
         resource_value=component,
-        quantity=1)
+        quantity=2)
     aggregated_amount_list = transformation.getAggregatedAmountList()
     self.assertEquals(len(aggregated_amount_list), 1)
+    aggregated_amount = aggregated_amount_list[0]
+    self.assertEquals(aggregated_amount.quantity, 2)
 
   def test_01_getAggregatedAmountListWithVariatedProperty(self):
     """
-- 
2.30.9