[FIX] stock: corrected fix of bug 881356
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Wed, 15 Feb 2012 17:12:15 +0000 (18:12 +0100)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Wed, 15 Feb 2012 17:12:15 +0000 (18:12 +0100)
bzr revid: qdp-launchpad@openerp.com-20120215171215-6r0ky0a8o6a6ogm3

addons/sale/sale.py
addons/stock/stock.py

index d82688d..5b9660c 100644 (file)
@@ -1233,7 +1233,7 @@ class sale_order_line(osv.osv):
 
         if not uom2:
             uom2 = product_obj.uom_id
-        compare_qty = float_compare(product_obj.virtual_available * uom2.factor,qty * product_obj.uom_id.factor, precision_rounding=product_obj.uom_id.rounding)
+        compare_qty = float_compare(product_obj.virtual_available * uom2.factor, qty * product_obj.uom_id.factor, precision_rounding=product_obj.uom_id.rounding)
         if (product_obj.type=='product') and int(compare_qty) == -1 \
           and (product_obj.procure_method=='make_to_stock'):
             warn_msg = _('You plan to sell %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') % \
index a65bf45..8826079 100644 (file)
@@ -387,7 +387,7 @@ class stock_location(osv.osv):
         :param lock: if True, the stock.move lines of product with id ``product_id`` in all locations (and children locations) with ``ids`` will
                      be write-locked using postgres's "FOR UPDATE NOWAIT" option until the transaction is committed or rolled back. This is
                      to prevent reserving twice the same products.
-        :param context: optional context dictionary: it a 'uom' key is present it will be used instead of the default product uom to
+        :param context: optional context dictionary: if a 'uom' key is present it will be used instead of the default product uom to
                         compute the ``product_qty`` and in the return value.
         :return: List of tuples in the form (qty, location_id) with the (partial) quantities that can be taken in each location to
                  reach the requested product_qty (``qty`` is expressed in the default uom of the product), of False if enough
@@ -397,6 +397,10 @@ class stock_location(osv.osv):
         amount = 0.0
         if context is None:
             context = {}
+        uom_obj = self.pool.get('product.uom')
+        uom_rounding = self.pool.get('product.product').browse(cr, uid, product_id, context=context).uom_id.rounding
+        if context.get('uom'):
+            uom_rounding = uom_obj.browse(cr, uid, context.get('uom'), context=context).rounding
         for id in self.search(cr, uid, [('location_id', 'child_of', ids)]):
             if lock:
                 try:
@@ -452,7 +456,7 @@ class stock_location(osv.osv):
             total = 0.0
             results2 = 0.0
             for r in results:
-                amount = self.pool.get('product.uom')._compute_qty(cr, uid, r['product_uom'], r['product_qty'], context.get('uom', False))
+                amount = uom_obj._compute_qty(cr, uid, r['product_uom'], r['product_qty'], context.get('uom', False))
                 results2 += amount
                 total += amount
 
@@ -460,8 +464,8 @@ class stock_location(osv.osv):
                 continue
 
             amount = results2
-            compare_qty = float_compare(amount, product_qty, precision_rounding=context.get('rounding'))
-            if compare_qty <> -1:
+            compare_qty = float_compare(amount, 0, precision_rounding=uom_rounding)
+            if compare_qty == 1:
                 if amount > min(total, product_qty):
                     amount = min(product_qty, total)
                 result.append((amount, id))
@@ -2007,7 +2011,7 @@ class stock_move(osv.osv):
                 continue
             if move.state in ('confirmed', 'waiting'):
                 # Important: we must pass lock=True to _product_reserve() to avoid race conditions and double reservations
-                res = self.pool.get('stock.location')._product_reserve(cr, uid, [move.location_id.id], move.product_id.id, move.product_qty, {'uom': move.product_uom.id, 'rounding': move.product_uom.rounding}, lock=True)
+                res = self.pool.get('stock.location')._product_reserve(cr, uid, [move.location_id.id], move.product_id.id, move.product_qty, {'uom': move.product_uom.id}, lock=True)
                 if res:
                     #_product_available_test depends on the next status for correct functioning
                     #the test does not work correctly if the same product occurs multiple times