[Erp5-report] r33830 nicolas.dumazet - in /erp5/trunk/products: ERP5/Document/ ERP5Legacy/D...

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Mar 18 04:15:53 CET 2010


Author: nicolas.dumazet
Date: Thu Mar 18 04:15:52 2010
New Revision: 33830

URL: http://svn.erp5.org?rev=33830&view=rev
Log:
Fix durably getAggregatedAmount issues:
* both Transformation and TransformedResource should support a context
  passing a multiple quantity. The proper way to do so is to deleguate
  quantity computation to Transformation Lines, and then to pull the result
  up to aggregate it in Transformations.
* Fix a quirk in TransformationRule that was induced by the wrong
  behaviour of TransformedResource.getAggregatedAmountList: noone should
  need to multiply the amounts returned by getAggregatedAmountList, as
  the method should already include the computed quantities.

Modified:
    erp5/trunk/products/ERP5/Document/Transformation.py
    erp5/trunk/products/ERP5/Document/TransformedResource.py
    erp5/trunk/products/ERP5Legacy/Document/TransformationRule.py

Modified: erp5/trunk/products/ERP5/Document/Transformation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Transformation.py?rev=33830&r1=33829&r2=33830&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Transformation.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Transformation.py [utf8] Thu Mar 18 04:15:52 2010
@@ -241,14 +241,11 @@
                                 # obsolete, use trade_phase_list instead
                                 ind_phase_url_list=None,
                                 rejected_resource_uid_list=None,
-                                context_quantity=0,**kw):
+                                **kw):
       """
         getAggregatedAmountList returns an AggregatedAmountList which
         can be used either to do some calculation (ex. price, BOM)
         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)
 
@@ -304,13 +301,13 @@
           # transformation
           if line_is_included(transformation_line):
             try:
-              result.extend(transformation_line.getAggregatedAmountList(context))
+              line_result = transformation_line.getAggregatedAmountList(context)
             except KeyError:
               # KeyError is raised by TransformedResource.getAggregatedAmountList
               # in case of misconfiguration of a Cell.
               # Just ignore the line
               pass
-
-      if context_quantity:
-        result.multiplyQuantity(context=context)
+            else:
+              result.extend(line_result)
+
       return result

Modified: erp5/trunk/products/ERP5/Document/TransformedResource.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TransformedResource.py?rev=33830&r1=33829&r2=33830&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TransformedResource.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/TransformedResource.py [utf8] Thu Mar 18 04:15:52 2010
@@ -263,6 +263,25 @@
           quantity = float(quantity)
         except ValueError:
           error_string += 'Quantity is not a float.'
+
+        # If IAmount specifies that 4 resources are needed, all quantities
+        # need to be multiplicated by 4...
+        context_quantity = None
+        quantity_getter = getattr(context, "getQuantity", None)
+        if quantity_getter is not None:
+          _marker = object()
+          context_quantity = quantity_getter(_marker)
+          if context_quantity is _marker:
+            # XXX Backwards compatibility:
+            # previously, quantity property of the Amount was completely
+            # ignored, and was assumed to be 1.0 . Re-enact this old
+            # behavior (quantity default value is 0.0) to avoid breakages
+            warn("No quantity was defined on the Amount passed to " \
+                 "getAggregatedAmountList, 1.0 was assumed", DeprecationWarning)
+            context_quantity = 1.0
+        else:
+          raise KeyError("No quantity defined on context")
+        quantity *= float(context_quantity)
 
         # Get the variation category list
         variation_category_list_defined_by = None

Modified: erp5/trunk/products/ERP5Legacy/Document/TransformationRule.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Legacy/Document/TransformationRule.py?rev=33830&r1=33829&r2=33830&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Legacy/Document/TransformationRule.py [utf8] (original)
+++ erp5/trunk/products/ERP5Legacy/Document/TransformationRule.py [utf8] Thu Mar 18 04:15:52 2010
@@ -248,7 +248,7 @@
                         amount.getVariationCategoryList(),
           "variation_property_dict": \
                         amount.getVariationPropertyDict(),
-          "quantity": amount.getNetQuantity() * parent_movement.getQuantity(), # getNetQuantity to support efficency from transformation
+          "quantity": amount.getNetQuantity(), # getNetQuantity to support efficency from transformation
           "price": price,
           "quantity_unit": amount.getQuantityUnit(),
           "destination_list": (),




More information about the Erp5-report mailing list