diff --git a/addons/stock/static/src/js/widgets.js b/addons/stock/static/src/js/widgets.js index 2046b0f104e..6008fc6723d 100644 --- a/addons/stock/static/src/js/widgets.js +++ b/addons/stock/static/src/js/widgets.js @@ -174,12 +174,12 @@ function openerp_picking_widgets(instance){ this.$('.js_plus').click(function(){ var id = $(this).data('product-id'); var op_id = $(this).parents("[data-id]:first").data('id'); - self.getParent().scan_product_id(id,true,op_id); + self.getParent().scan_product_id(id,1,op_id); }); this.$('.js_minus').click(function(){ var id = $(this).data('product-id'); var op_id = $(this).parents("[data-id]:first").data('id'); - self.getParent().scan_product_id(id,false,op_id); + self.getParent().scan_product_id(id,-1,op_id); }); this.$('.js_unfold').click(function(){ var op_id = $(this).parent().data('id'); @@ -859,7 +859,7 @@ function openerp_picking_widgets(instance){ } }); }, - scan_product_id: function(product_id,increment,op_id){ //performs the same operation as a scan, but with product id instead + scan_product_id: function(product_id,increment,op_id){ //performs the same operation as a scan, but with product id instead, increment is the value to increment (-1 or 1) var self = this; return new instance.web.Model('stock.picking') .call('process_product_id_from_ui', [self.picking.id, product_id, op_id, increment]) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index ce54bb1821c..56ebcb4153d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1443,7 +1443,7 @@ class stock_picking(osv.osv): stock_operation_obj.write(cr, uid, pack_operation_ids, {'result_package_id': package_id}, context=context) return True - def process_product_id_from_ui(self, cr, uid, picking_id, product_id, op_id, increment=True, context=None): + def process_product_id_from_ui(self, cr, uid, picking_id, product_id, op_id, increment=1, context=None): return self.pool.get('stock.pack.operation')._search_and_increment(cr, uid, picking_id, [('product_id', '=', product_id),('id', '=', op_id)], increment=increment, context=context) def process_barcode_from_ui(self, cr, uid, picking_id, barcode_str, visible_op_ids, context=None): @@ -1457,7 +1457,7 @@ class stock_picking(osv.osv): #check if the barcode is a weighted barcode or simply a product if parsed_result['type'] in ['weight', 'product', 'package']: - weight=-1 + weight=1 if parsed_result['type'] == 'weight': domain = ['|', ('barcode', '=', parsed_result['base_code']), ('default_code', '=', parsed_result['base_code'])] weight=parsed_result['value'] @@ -1474,7 +1474,7 @@ class stock_picking(osv.osv): matching_product_ids = obj.search(cr, uid, domain, context=context) if matching_product_ids: - op_id = stock_operation_obj._search_and_increment(cr, uid, picking_id, [(id_in_operation, '=', matching_product_ids[0])], filter_visible=True, visible_op_ids=visible_op_ids, weight=weight, increment=True, context=context) + op_id = stock_operation_obj._search_and_increment(cr, uid, picking_id, [(id_in_operation, '=', matching_product_ids[0])], filter_visible=True, visible_op_ids=visible_op_ids, increment=weight, context=context) answer['operation_id'] = op_id return answer @@ -1484,7 +1484,7 @@ class stock_picking(osv.osv): matching_lot_ids = lot_obj.search(cr, uid, [('name', '=', parsed_result['code'])], context=context) if matching_lot_ids: lot = lot_obj.browse(cr, uid, matching_lot_ids[0], context=context) - op_id = stock_operation_obj._search_and_increment(cr, uid, picking_id, [('product_id', '=', lot.product_id.id), ('lot_id', '=', lot.id)], filter_visible=True, visible_op_ids=visible_op_ids, increment=True, context=context) + op_id = stock_operation_obj._search_and_increment(cr, uid, picking_id, [('product_id', '=', lot.product_id.id), ('lot_id', '=', lot.id)], filter_visible=True, visible_op_ids=visible_op_ids, increment=1, context=context) answer['operation_id'] = op_id return answer @@ -3944,12 +3944,11 @@ class stock_pack_operation(osv.osv): new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, val, context=context) self.write(cr, uid, id, {'lot_id': new_lot_id}, context=context) - def _search_and_increment(self, cr, uid, picking_id, domain, filter_visible=False, visible_op_ids=False, weight=-1, increment=True, context=None): - '''Search for an operation with given 'domain' in a picking, if it exists increment the qty (+weight if weight != -1, +1 otherwise) otherwise create it + def _search_and_increment(self, cr, uid, picking_id, domain, filter_visible=False, visible_op_ids=False, increment=1, context=None): + '''Search for an operation with given 'domain' in a picking, if it exists increment the qty by the value of increment otherwise create it :param domain: list of tuple directly reusable as a domain context can receive a key 'current_package_id' with the package to consider for this operation - weight is used for weighted products for which quantity != 1 (not per unit but e.g. per kg). Weight == -1 when buttons - or + are pressed. returns True ''' if context is None: @@ -3969,21 +3968,15 @@ class stock_pack_operation(osv.osv): operation_id = todo_operation_ids[0] op_obj = self.browse(cr, uid, operation_id, context=context) qty = op_obj.qty_done - if increment: - if weight == -1: # increment by 1 - if qty < op_obj.product_qty: - qty = min(qty+1, op_obj.product_qty); - else: - qty += 1 - else: # Weigth scanned - qty += weight; - else: + if increment > 0: + qty += increment + elif increment < 0: if qty == 0 and op_obj.product_qty == 0: #we have a line with 0 qty set, so delete it self.unlink(cr, uid, [operation_id], context=context) return False else: - qty = max(0, qty-1) #if qty >= 1 else 0 + qty = max(0, qty-1) self.write(cr, uid, [operation_id], {'qty_done': qty}, context=context) else: #no existing operation found for the given domain and picking => create a new one @@ -3994,7 +3987,7 @@ class stock_pack_operation(osv.osv): 'product_qty': 0, 'location_id': picking.location_id.id, 'location_dest_id': picking.location_dest_id.id, - 'qty_done': weight if weight != -1 else 1, + 'qty_done': increment, } for key in domain: var_name, dummy, value = key