diff --git a/addons/stock/product.py b/addons/stock/product.py index 27b7590cf5d..2a819ea89b2 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -248,6 +248,7 @@ class product_product(osv.osv): date_str = "date<=%s" date_values = [to_date] + prodlot_id = context.get('prodlot_id', False) # TODO: perhaps merge in one query. if date_values: @@ -257,10 +258,11 @@ class product_product(osv.osv): cr.execute( 'select sum(product_qty), product_id, product_uom '\ 'from stock_move '\ - 'where location_id NOT IN %s'\ - 'and location_dest_id IN %s'\ - 'and product_id IN %s'\ - 'and state IN %s' + (date_str and 'and '+date_str+' ' or '') +''\ + 'where location_id NOT IN %s '\ + 'and location_dest_id IN %s '\ + 'and product_id IN %s '\ + '' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\ + 'and state IN %s ' + (date_str and 'and '+date_str+' ' or '') +' '\ 'group by product_id,product_uom',tuple(where)) results = cr.fetchall() if 'out' in what: @@ -268,10 +270,11 @@ class product_product(osv.osv): cr.execute( 'select sum(product_qty), product_id, product_uom '\ 'from stock_move '\ - 'where location_id IN %s'\ + 'where location_id IN %s '\ 'and location_dest_id NOT IN %s '\ - 'and product_id IN %s'\ - 'and state in %s' + (date_str and 'and '+date_str+' ' or '') + ''\ + 'and product_id IN %s '\ + '' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\ + 'and state in %s ' + (date_str and 'and '+date_str+' ' or '') + ' '\ 'group by product_id,product_uom',tuple(where)) results2 = cr.fetchall() uom_obj = self.pool.get('product.uom') diff --git a/addons/stock/stock.py b/addons/stock/stock.py index af1b783709e..aeb82269357 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2556,7 +2556,7 @@ class stock_inventory(osv.osv): move_ids = [] for line in inv.inventory_line_id: pid = line.product_id.id - product_context.update(uom=line.product_uom.id,date=inv.date) + product_context.update(uom=line.product_uom.id, date=inv.date, prodlot_id=line.prod_lot_id.id) amount = location_obj._product_get(cr, uid, line.location_id.id, [pid], product_context)[pid] change = line.product_qty - amount