[Erp5-report] r32167 nicolas.dumazet - in /erp5/trunk/products/ERP5: Document/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 2 11:18:37 CET 2010


Author: nicolas.dumazet
Date: Tue Feb  2 11:18:37 2010
New Revision: 32167

URL: http://svn.erp5.org?rev=32167&view=rev
Log:
Quantity Unit Definitions: Performance & backward-compatibility (2/2)

* Add a (failing) test where the old system is used for quantities
* Use a cached Python Script to keep the universal quantity definitions:
  * erp5_content_long
  * delete the cache when a global quantity definition is changed via an
    interaction workflow on Definitions
  * Use the catalog to retrieve the global definitions
  * If no Quantity Definitions are defined _at all_, then it falls
    back and uses the properties on categories


Modified:
    erp5/trunk/products/ERP5/Document/Resource.py
    erp5/trunk/products/ERP5/tests/testInventoryAPI.py

Modified: erp5/trunk/products/ERP5/Document/Resource.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Resource.py?rev=32167&r1=32166&r2=32167&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Resource.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Resource.py [utf8] Tue Feb  2 11:18:37 2010
@@ -852,29 +852,6 @@
         if len(result) == 1:
           return result[0]
 
-    def _getGlobalQuantityUnitDefinitionDict(self):
-      # XXX this info could be cached, as it is the same for all Resources
-      result = {}
-      module = self.getPortalObject().quantity_unit_conversion_module
-      for definition_list in module.objectValues(portal_type= \
-          'Quantity Unit Conversion Group'):
-        standard_quantity_unit_uid = definition_list.getQuantityUnitUid()
-        if standard_quantity_unit_uid is None:
-          continue
-
-        result[standard_quantity_unit_uid] = (None, 1.0)
-        for definition in definition_list.objectValues(portal_type= \
-            'Quantity Unit Conversion Definition'):
-          unit_uid = definition.getQuantityUnitUid()
-          if unit_uid is None:
-            continue
-          quantity = definition.getQuantity()
-          if not quantity:
-            continue
-          result[unit_uid] = (definition.getUid(), quantity)
-
-      return result
-
     def _getQuantityUnitDefinitionDict(self):
       """
       Returns a dictionary representing the Unit Definitions that hold
@@ -889,7 +866,8 @@
             For example, if mass/g is the global standard quantity_unit, all
             definitions for mass/* will be expressed in grams.
       """
-      global_definition_dict = self._getGlobalQuantityUnitDefinitionDict()
+      global_definition_dict = self.\
+          QuantityUnitConversionModule_getUniversalDefinitionDict()
 
       result = global_definition_dict.copy()
       for definition_list in self.objectValues(portal_type= \

Modified: erp5/trunk/products/ERP5/tests/testInventoryAPI.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInventoryAPI.py?rev=32167&r1=32166&r2=32167&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInventoryAPI.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testInventoryAPI.py [utf8] Tue Feb  2 11:18:37 2010
@@ -2409,6 +2409,7 @@
     InventoryAPITestCase.afterSetUp(self)
 
     self.setUpUnitDefinition()
+    self._safeTic()
 
   def makeMovement(self, quantity, resource, *variation, **kw):
     m = self._makeMovement(quantity=quantity, resource_value=resource,
@@ -2671,6 +2672,65 @@
                       self.resource_bylot_overriding\
                           .convertQuantity(1, "unit/lot", "unit/unit"))
 
+class TestUnitConversionBackwardCompatibility(BaseTestUnitConversion):
+  QUANTITY_UNIT_DICT = {
+    # base: (reference, dict_of_others)
+    'mass':   ('kilogram', dict(gram=0.001)),
+  }
+  METRIC_TYPE_CATEGORY_LIST = (
+    'mass/net',
+  )
+  def setUpUnitDefinition(self):
+    # bypass Unit Definition setup
+    mass_category = self.portal.portal_categories.quantity_unit.mass
+    mass_category.gram.setProperty('quantity', 0.001)
+    mass_category.kilogram.setProperty('quantity', 1)
+
+    pass
+
+  def testBackwardCompatibility(self):
+    delivery_rule = self.getRuleTool().default_delivery_rule
+    delivery_rule.validate()
+
+    resource = self.portal.product_module.newContent(
+                      portal_type='Product',
+                      quantity_unit_list=('mass/gram',
+                                          'mass/kilogram'),)
+    node = self.portal.organisation_module.newContent(
+                      portal_type='Organisation')
+    delivery = self.portal.purchase_packing_list_module.newContent(
+                      portal_type='Purchase Packing List',
+                      start_date='2010-01-26',
+                      price_currency='currency_module/EUR',
+                      destination_value=node,
+                      destination_section_value=node)
+    delivery.newContent(portal_type='Purchase Packing List Line',
+                        resource_value=resource,
+                        quantity=10,
+                        quantity_unit='mass/gram')
+    delivery.newContent(portal_type='Purchase Packing List Line',
+                        resource_value=resource,
+                        quantity=3,
+                        quantity_unit='mass/kilogram')
+    delivery.confirm()
+    delivery.start()
+    delivery.stop()
+    transaction.commit()
+    self.tic()
+
+    # inventories of that resource are indexed in grams
+    self.assertEquals(3010,
+        self.portal.portal_simulation.getCurrentInventory(
+          resource_uid=resource.getUid(),
+          node_uid=node.getUid()))
+
+    # converted inventory also works
+    self.assertEquals(3.01,
+        self.portal.portal_simulation.getCurrentInventory(
+          quantity_unit='mass/kilogram',
+          resource_uid=resource.getUid(),
+          node_uid=node.getUid()))
+
 def test_suite():
   suite = unittest.TestSuite()
   suite.addTest(unittest.makeSuite(TestInventory))
@@ -2682,6 +2742,7 @@
   suite.addTest(unittest.makeSuite(TestInventoryDocument))
   suite.addTest(unittest.makeSuite(TestUnitConversion))
   suite.addTest(unittest.makeSuite(TestUnitConversionDefinition))
+  suite.addTest(unittest.makeSuite(TestUnitConversionBackwardCompatibility))
   return suite
 
 # vim: foldmethod=marker




More information about the Erp5-report mailing list