From 561346db9ed820f09540382b012baa583f2df951 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 5 May 2015 14:26:17 +0200 Subject: [PATCH] [FIX] stock: forbids possibility to make inventory of all products when a given product is chosen opw-634388 Fixes #6512 --- addons/stock/stock.py | 12 ++++++++++++ addons/stock/stock_view.xml | 2 +- addons/stock/test/inventory.yml | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index fc1e636d435..76e87a72763 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2744,6 +2744,18 @@ class stock_inventory(osv.osv): vals.append(product_line) return vals + def _check_filter_product(self, cr, uid, ids, context=None): + for inventory in self.browse(cr, uid, ids, context=context): + if inventory.filter not in ('product', 'product_owner') and inventory.product_id: + return False + return True + + def onchange_filter(self, cr, uid, ids, filter): + return {'value': {'product_id': False} if filter not in ('product', 'product_owner') else {}} + + _constraints = [ + (_check_filter_product, 'A specific product is chosen while the filter "One product only" is not selected', ['product_id', 'filter']), + ] class stock_inventory_line(osv.osv): _name = "stock.inventory.line" diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 44352125727..828a63c53f8 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -102,7 +102,7 @@ - + diff --git a/addons/stock/test/inventory.yml b/addons/stock/test/inventory.yml index a0b0f58512b..4bfc70d3dd1 100644 --- a/addons/stock/test/inventory.yml +++ b/addons/stock/test/inventory.yml @@ -9,6 +9,7 @@ - !record {model: stock.inventory, id: inventory_test0}: name: Test + filter: product product_id: inventory_product - I confirm the inventory and check that my inventory has no line, as the product is a new one. @@ -60,6 +61,7 @@ - !record {model: stock.inventory, id: inventory_test1}: name: second test inventory + filter: product product_id: inventory_product - I confirm the inventory and check that my inventory has one line, with a quantity of 10.