From f201eada944ade0e4111cdb8d8135984c75ebadf Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Tue, 26 Oct 2010 11:49:17 +0000
Subject: [PATCH] Fix
 TestTransformation.test_01_getAggregatedAmountListWithVariatedProperty

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39526 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/MappedValue.py         |  4 ++++
 product/ERP5/Document/TransformedResource.py | 13 ++++++++++++-
 product/ERP5/tests/testTransformation.py     |  7 ++++++-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Document/MappedValue.py b/product/ERP5/Document/MappedValue.py
index 52b9b71993..b37c21a624 100644
--- a/product/ERP5/Document/MappedValue.py
+++ b/product/ERP5/Document/MappedValue.py
@@ -39,6 +39,10 @@ _MARKER = []
 class MappedValue(Predicate):
   """
     A MappedValue allows to associate a value to a predicate
+
+  XXX Why do we redefine xxxProperty methods ?
+      When a property is defined by a property sheet with a specific storage_id,
+      they break accessors of this property when a value is mapped to it.
   """
   meta_type = 'ERP5 Mapped Value'
   portal_type = 'Mapped Value'
diff --git a/product/ERP5/Document/TransformedResource.py b/product/ERP5/Document/TransformedResource.py
index c302d49c8c..26faa77224 100644
--- a/product/ERP5/Document/TransformedResource.py
+++ b/product/ERP5/Document/TransformedResource.py
@@ -63,7 +63,18 @@ class TransformedResource(AmountGeneratorLine):
     # Provide default mapped value properties and categories if
     # not defined
     def getMappedValuePropertyList(self):
-      return self._baseGetMappedValuePropertyList() or ('quantity',)
+      result = self._baseGetMappedValuePropertyList()
+      if not result:
+        result = ['quantity']
+        # Take into account variation_property_list for each variation
+        # for which hasProperty is true...
+        # FIXME: Why the resource and not the model line itself ? Or both ??
+        resource = self.getDefaultResourceValue()
+        if resource is not None:
+          # XXX Using getattr directly is a hack. See MappedValue.__doc__
+          result.extend(key for key in resource.getVariationPropertyList()
+                            if getattr(self, key, self) is not self)
+      return result
 
     def getMappedValueBaseCategoryList(self):
       result = self._baseGetMappedValueBaseCategoryList()
diff --git a/product/ERP5/tests/testTransformation.py b/product/ERP5/tests/testTransformation.py
index fa1b6ad317..0acfbe9512 100644
--- a/product/ERP5/tests/testTransformation.py
+++ b/product/ERP5/tests/testTransformation.py
@@ -134,8 +134,13 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion):
     """
     # Only for testing purpose, use a property sheet that has nothing to
     # do with component. It would have been possible to create a new
-    # property sheet for this test
+    # property sheet for this test.
+    # When one do that, the property sheet should be added to many other types
+    # like movements, order lines and so on.
+    self._addPropertySheet('Amount', 'Bug')
     self._addPropertySheet(self.transformed_resource_portal_type, 'Bug')
+    # XXX 'tested' works here because 'storage_id' does not differ
+    #     (see also MappedValue.__doc__)
     variation_property_list = ['tested']
 
     transformation = self.createTransformation()
-- 
2.30.9