From b8779f0c536560ba8362f83ab5ce6d6817fcf750 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 7 May 2015 16:54:18 +0200 Subject: [PATCH] [FIX] stock: keep inventory options consistent Make sure that appropriate fields are emptied when switching to in between inventory filters. This prevents incoherent results due to hidden fields which were filled in a previous selection. opw-634388 Fixes #6512 --- addons/stock/stock.py | 24 ++++++++++++++++--- .../stock/wizard/stock_change_product_qty.py | 7 ++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 76e87a72763..a4c7324dafd 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2746,15 +2746,33 @@ class stock_inventory(osv.osv): def _check_filter_product(self, cr, uid, ids, context=None): for inventory in self.browse(cr, uid, ids, context=context): + if inventory.filter == 'none' and inventory.product_id and inventory.location_id and inventory.lot_id: + return True if inventory.filter not in ('product', 'product_owner') and inventory.product_id: return False + if inventory.filter != 'lot' and inventory.lot_id: + return False + if inventory.filter not in ('owner', 'product_owner') and inventory.partner_id: + return False + if inventory.filter != 'pack' and inventory.package_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 {}} + def onchange_filter(self, cr, uid, ids, filter, context=None): + to_clean = { 'value': {} } + if filter not in ('product', 'product_owner'): + to_clean['value']['product_id'] = False + if filter != 'lot': + to_clean['value']['lot_id'] = False + if filter not in ('owner', 'product_owner'): + to_clean['value']['partner_id'] = False + if filter != 'pack': + to_clean['value']['package_id'] = False + return to_clean _constraints = [ - (_check_filter_product, 'A specific product is chosen while the filter "One product only" is not selected', ['product_id', 'filter']), + (_check_filter_product, 'The selected inventory options are not coherent.', + ['filter', 'product_id', 'lot_id', 'partner_id', 'package_id']), ] class stock_inventory_line(osv.osv): diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py index 8843581d70a..9c495106a2f 100644 --- a/addons/stock/wizard/stock_change_product_qty.py +++ b/addons/stock/wizard/stock_change_product_qty.py @@ -93,8 +93,15 @@ class stock_change_product_qty(osv.osv_memory): ctx = context.copy() ctx['location'] = data.location_id.id ctx['lot_id'] = data.lot_id.id + if data.product_id.id and data.lot_id.id: + filter = 'none' + elif data.product_id.id: + filter = 'product' + else: + filter = 'none' inventory_id = inventory_obj.create(cr, uid, { 'name': _('INV: %s') % tools.ustr(data.product_id.name), + 'filter': filter, 'product_id': data.product_id.id, 'location_id': data.location_id.id, 'lot_id': data.lot_id.id}, context=context)