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');
}
});
},
- 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])
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):
#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']
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
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
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:
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
'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