optimize - no float_compare if mto true
authorjke-openerp <jke@openerp.com>
Mon, 7 Oct 2013 13:48:31 +0000 (15:48 +0200)
committerjke-openerp <jke@openerp.com>
Mon, 7 Oct 2013 13:48:31 +0000 (15:48 +0200)
bzr revid: jke@openerp.com-20131007134831-ne0w1h9xnv4n6pmw

addons/sale_stock/sale_stock.py

index 0230fbf..c08d29a 100644 (file)
@@ -342,16 +342,8 @@ class sale_order_line(osv.osv):
         product_obj = product_obj.browse(cr, uid, product, context=context)
         res['value']['delay'] = (product_obj.sale_delay or 0.0)
         
-        isMto = False
-        for one_route in product_obj.route_ids:
-            if one_route.name == u'MTO':
-                isMto = True
-                break;        
-        
-        print("********** Is MTO ", isMto)
         
         
-
         #check if product is available, and if not: raise an error
         uom2 = False
         if uom:
@@ -365,14 +357,22 @@ class sale_order_line(osv.osv):
         res_packing = self.product_packaging_change(cr, uid, ids, pricelist, product, qty, uom, partner_id, packaging, context=context)
         res['value'].update(res_packing.get('value', {}))
         warning_msgs = res_packing.get('warning') and res_packing['warning']['message'] or ''
-        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 isMto == False:
-          #and (product_obj.procure_method=='make_to_stock'): --> need to find alternative for procure_method
-            warn_msg = _('You plan to sell %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') % \
-                    (qty, uom2 and uom2.name or product_obj.uom_id.name,
-                     max(0,product_obj.virtual_available), product_obj.uom_id.name,
-                     max(0,product_obj.qty_available), product_obj.uom_id.name)
-            warning_msgs += _("Not enough stock ! : ") + warn_msg + "\n\n"
+        
+        isMto = False
+        for one_route in product_obj.route_ids:
+            if one_route.name == u'MTO':
+                isMto = True
+                break;        
+        
+        if isMto == False:    
+            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'): --> need to find alternative for procure_method
+                warn_msg = _('You plan to sell %.2f %s but you only have %.2f %s available !\nThe real stock is %.2f %s. (without reservations)') % \
+                        (qty, uom2 and uom2.name or product_obj.uom_id.name,
+                         max(0,product_obj.virtual_available), product_obj.uom_id.name,
+                         max(0,product_obj.qty_available), product_obj.uom_id.name)
+                warning_msgs += _("Not enough stock ! : ") + warn_msg + "\n\n"
 
         #update of warning messages
         if warning_msgs: