[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
This commit is contained in:
parent
61a5bbfb21
commit
b8779f0c53
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue