Commit 74838d44 authored by Nicolas Dumazet's avatar Nicolas Dumazet

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.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33830 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 092c7e0b
......@@ -241,14 +241,11 @@ class Transformation(XMLObject, Predicate, Variated):
# 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 @@ class Transformation(XMLObject, Predicate, Variated):
# 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
else:
result.extend(line_result)
if context_quantity:
result.multiplyQuantity(context=context)
return result
......@@ -264,6 +264,25 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
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
variation_category_list = None
......
......@@ -248,7 +248,7 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule):
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": (),
......
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