From 3a9e6828f1fc2bc8a26c59abd41dd467867505aa Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Fri, 12 Jun 2015 11:21:43 +0200 Subject: [PATCH] [FIX] stock: Unit of Measure When the uom(Unit) set by default is not in the same category than the uom category of the product, the uom of the product is set. When the uom is changed, the theoretical quantity and the real quantity are recomputed. opw:641027 --- addons/stock/stock.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index d16fc082b24..4248141a083 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2883,11 +2883,13 @@ class stock_inventory_line(osv.osv): uom_obj = self.pool["product.uom"] res = {'value': {}} # If no UoM already put the default UoM of the product - if product_id and not uom_id: + if product_id: product = self.pool.get('product.product').browse(cr, uid, product_id, context=context) - res['value']['product_uom_id'] = product.uom_id.id - res['domain'] = {'product_uom_id': [('category_id','=',product.uom_id.category_id.id)]} - uom_id = product.uom_id.id + uom = self.pool['product.uom'].browse(cr, uid, uom_id, context=context) + if product.uom_id.category_id.id != uom.category_id.id: + res['value']['product_uom_id'] = product.uom_id.id + res['domain'] = {'product_uom_id': [('category_id','=',product.uom_id.category_id.id)]} + uom_id = product.uom_id.id # Calculate theoretical quantity by searching the quants as in quants_get if product_id and location_id: product = self.pool.get('product.product').browse(cr, uid, product_id, context=context) @@ -2897,9 +2899,12 @@ class stock_inventory_line(osv.osv): ('product_id','=', product_id), ('owner_id', '=', partner_id), ('package_id', '=', package_id)] quants = quant_obj.search(cr, uid, dom, context=context) th_qty = sum([x.qty for x in quant_obj.browse(cr, uid, quants, context=context)]) + qty = product.qty_available if product_id and uom_id and product.uom_id.id != uom_id: th_qty = uom_obj._compute_qty(cr, uid, product.uom_id.id, th_qty, uom_id) + qty = uom_obj._compute_qty(cr, uid, product.uom_id.id, qty, uom_id) res['value']['theoretical_qty'] = th_qty + res['value']['product_qty'] = qty return res def _resolve_inventory_line(self, cr, uid, inventory_line, context=None):