diff --git a/product/ERP5/Document/Transformation.py b/product/ERP5/Document/Transformation.py index a6ab0775cb974dd04dd4dda6cb94e22f7dfb5aa3..3c17804e436e4cc2cbd151d2b88b67bfa49e1a3f 100644 --- a/product/ERP5/Document/Transformation.py +++ b/product/ERP5/Document/Transformation.py @@ -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 diff --git a/product/ERP5/Document/TransformedResource.py b/product/ERP5/Document/TransformedResource.py index c59731d5ba70cd6ccd472258707802fe6b8dca6f..d5fad98c477898680a80de9d0f6377a640bbaebd 100644 --- a/product/ERP5/Document/TransformedResource.py +++ b/product/ERP5/Document/TransformedResource.py @@ -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 diff --git a/product/ERP5Legacy/Document/TransformationRule.py b/product/ERP5Legacy/Document/TransformationRule.py index e96483611959dfb96ba683ff20d8d849a3981a5f..7960685a1a7c3cc4909647f1c0787681347c0e5b 100644 --- a/product/ERP5Legacy/Document/TransformationRule.py +++ b/product/ERP5Legacy/Document/TransformationRule.py @@ -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": (),