From c4a30b0601b35d0e0b6c6953fb56feef99efe120 Mon Sep 17 00:00:00 2001
From: Guillaume Michon <guillaume@nexedi.com>
Date: Mon, 12 Dec 2005 13:00:12 +0000
Subject: [PATCH] Bug fix : use quantity of each item instead of number of
 items when calculating inventory

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4607 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/InventoryCell.py |  7 ++-----
 product/ERP5/Document/InventoryLine.py | 12 ++++--------
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/product/ERP5/Document/InventoryCell.py b/product/ERP5/Document/InventoryCell.py
index 2d0b9cb37e..19160a59d1 100755
--- a/product/ERP5/Document/InventoryCell.py
+++ b/product/ERP5/Document/InventoryCell.py
@@ -71,11 +71,8 @@ class InventoryCell(DeliveryCell):
       DeliveryCell._edit(self, REQUEST=REQUEST, force_update = force_update, **kw)
       # Calculate inventory
       item_list = self.getAggregateValueList()
-      if len(item_list) > 0:
-        inventory = 0
-        for item in item_list:
-          if item.getQuantity() not in (None, ''):
-            inventory += item.getQuantity()
+      inventory = len(item_list)
+      if inventory != 0:
         self.setInventory(inventory)
       
 
diff --git a/product/ERP5/Document/InventoryLine.py b/product/ERP5/Document/InventoryLine.py
index 61223b8204..f0f2972a0a 100755
--- a/product/ERP5/Document/InventoryLine.py
+++ b/product/ERP5/Document/InventoryLine.py
@@ -71,13 +71,11 @@ class InventoryLine(DeliveryLine):
       DeliveryLine._edit(self, REQUEST=REQUEST, force_update = force_update, **kw)
       # Calculate inventory
       item_list = self.getAggregateValueList()
-      if len(item_list) > 0:
-        inventory = 0
-        for item in item_list:
-          if item.getQuantity() not in (None, ''):
-            inventory += item.getQuantity()
+      if item_list is not None:
+        inventory = len(item_list)
+      if inventory != 0:
         self.setInventory(inventory)
-      
+
 
     security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory')
     def getTotalInventory(self):
@@ -128,9 +126,7 @@ class InventoryLine(DeliveryLine):
           inventory = self.getInventory()
           if current_inventory in (None, ''):
             current_inventory = 0.0
-          LOG('return 1', 0, '%s - %s' % (repr(self.getInventory()), repr(current_inventory)))
           return self.getInventory() - current_inventory
-        LOG('return 2', 0, repr(self.getInventory()))
         return self.getInventory()
       else:
         return None
-- 
2.30.9