From a32d6425d83aaf1507fc951727bcdfd69a6bc3ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 1 Feb 2013 15:17:28 +0100
Subject: [PATCH] Test & fix behaviour with movements with NULL price & 0
 quantity

---
 .../erp5_core/Resource_zGetInventoryList.xml  |  4 ++--
 product/ERP5/bootstrap/erp5_core/bt/revision  |  2 +-
 product/ERP5/tests/testInventoryAPI.py        | 21 ++++++++++++++++++-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml
index 1c385e5dda..d51348167d 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml
@@ -97,7 +97,7 @@ SELECT\n
       <dtml-if transformed_uid> * transformation.quantity</dtml-if>, <dtml-var precision>))\n
     AS converted_quantity,\n
   </dtml-if>\n
-  SUM(ROUND(<dtml-var stock_table_id>.total_price, <dtml-var precision>)) AS total_price\n
+  IFNULL(SUM(ROUND(<dtml-var stock_table_id>.total_price, <dtml-var precision>)), 0) AS total_price\n
 <dtml-else>\n
   SUM(<dtml-var stock_table_id>.quantity <dtml-if transformed_uid> * transformation.quantity</dtml-if>) AS inventory,\n
   SUM(<dtml-var stock_table_id>.quantity <dtml-if transformed_uid> * transformation.quantity</dtml-if>) AS total_quantity,\n
@@ -107,7 +107,7 @@ SELECT\n
       <dtml-if transformed_uid> * transformation.quantity</dtml-if>), 12)\n
     AS converted_quantity,\n
   </dtml-if>\n
-  SUM(<dtml-var stock_table_id>.total_price) AS total_price\n
+  IFNULL(SUM(<dtml-var stock_table_id>.total_price), 0) AS total_price\n
 </dtml-if>\n
 <dtml-if inventory_list>\n
   ,node.title AS node_title,\n
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index 1bc6f423c2..00888d0ae6 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-41068
\ No newline at end of file
+41069
\ No newline at end of file
diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py
index 806ed1434f..85a6cca19d 100644
--- a/product/ERP5/tests/testInventoryAPI.py
+++ b/product/ERP5/tests/testInventoryAPI.py
@@ -819,6 +819,15 @@ class TestInventoryList(InventoryAPITestCase):
     # default is an empty list
     self.assertEquals(0, len(inventory_list))
 
+  def testDefault0(self):
+    getInventoryList = self.getSimulationTool().getInventoryList
+    self._makeMovement()
+    inventory_list = getInventoryList(section_uid=self.section.getUid(),)
+    self.assertEquals(1, len(inventory_list))
+    self.assertEquals(0, inventory_list[0].total_quantity)
+    # The total price of grouped movements without price is 0
+    self.assertEquals(0, inventory_list[0].total_price)
+
   def test_GroupByNode(self):
     getInventoryList = self.getSimulationTool().getInventoryList
     self._makeMovement(quantity=100)
@@ -1394,7 +1403,17 @@ class TestMovementHistoryList(InventoryAPITestCase):
                     'Shared.DC.ZRDB.Results.Results')
     # default is an empty list
     self.assertEquals(0, len(mvt_history_list))
-  
+
+  def testDefault0(self):
+    self._makeMovement()
+    getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
+    mvt_history_list = getMovementHistoryList(
+      section_uid=self.section.getUid(),)
+    self.assertEquals(1, len(mvt_history_list))
+    self.assertEquals(0, mvt_history_list[0].total_quantity)
+    # If a movement have no price, None is returned
+    self.assertEquals(None, mvt_history_list[0].total_price)
+
   def testMovementBothSides(self):
     """Movement History List returns movement from both sides""" 
     getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
-- 
2.30.9