From fa27d284947451b83f1807d6d6039ec0cea663c5 Mon Sep 17 00:00:00 2001 From: Rifakat Date: Thu, 7 Aug 2014 16:56:27 +0200 Subject: [PATCH] [FIX] stock: inventory lines with no production lot: compare with correct stock level Inventory lines without production lot number should be compared with the stock level of products without a production lot. Otherwise the final result of a validated inventory is wrong as soon as there are lines with and without production lot for the same product. Adds corresponding regression test. Fixes https://bugs.launchpad.net/openobject-addons/+bug/1008099 Manual rebase of #1658, courtesy of Numerigraphe --- addons/stock/product.py | 2 ++ addons/stock/test/opening_stock.yml | 30 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/addons/stock/product.py b/addons/stock/product.py index 5db1e1b3164..3050d2aff28 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -283,6 +283,8 @@ class product_product(osv.osv): if prodlot_id: prodlot_clause = ' and prodlot_id = %s ' where += [prodlot_id] + elif 'prodlot_id' in context and not prodlot_id: + prodlot_clause = ' and prodlot_id is null ' # TODO: perhaps merge in one query. if 'in' in what: diff --git a/addons/stock/test/opening_stock.yml b/addons/stock/test/opening_stock.yml index 9efcfd3af99..5dfb5c4b9fa 100644 --- a/addons/stock/test/opening_stock.yml +++ b/addons/stock/test/opening_stock.yml @@ -37,6 +37,36 @@ !python {model: product.product}: | product = self.browse(cr, uid, ref('product_product_6'), context=context) assert product.qty_available == 10, "Stock is not updated." +- + I update the current stock of the Ice-cream with 10 kgm without Production Lot. +- + !record {model: stock.change.product.qty, id: change_qty_nolot}: + location_id: location_monitor_small + new_quantity: 10 + product_id: product_product_6 +- + !python {model: stock.change.product.qty}: | + self.change_product_qty(cr, uid, [ref('change_qty_nolot')], context=dict(context, active_id=ref('product_product_6'))) +- + I check available stock of Ice-cream after update stock. +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('product_product_6'), context=context) + assert product.qty_available == 20, "Real stock is not updated." +- + I revert 10kgm updated stock again with no production lot in order to level the stock +- + !record {model: stock.change.product.qty, id: change_qty_nolot_1}: + location_id: location_monitor_small + new_quantity: 0 + product_id: product_product_6 +- + !python {model: stock.change.product.qty}: | + self.change_product_qty(cr, uid, [ref('change_qty_nolot_1')], context=dict(context, active_id=ref('product_product_6'))) +- + !python {model: product.product}: | + product = self.browse(cr, uid, ref('product_product_6'), context=context) + assert product.qty_available == 10, "Real stock is not updated." - Stock user can merge inventory, so let's check data with giving the access rights of user. -