[MERGE] lot assignation in the barcode scanner UI

bzr revid: qdp-launchpad@openerp.com-20140505141921-vovtqufg0f6rzktt
This commit is contained in:
Quentin (OpenERP) 2014-05-05 16:19:21 +02:00
commit 46268f9597
3 changed files with 58 additions and 5 deletions

View File

@ -193,7 +193,38 @@ function openerp_picking_widgets(instance){
});
this.$('.js_create_lot').click(function(){
var op_id = $(this).parents("[data-id]:first").data('id');
self.getParent().create_lot(op_id);
var lot_name = false;
self.$('.js_lot_scan').val('');
var $lot_modal = self.$el.siblings('#js_LotChooseModal');
//disconnect scanner to prevent scanning a product in the back while dialog is open
self.getParent().barcode_scanner.disconnect();
$lot_modal.modal()
//focus input
$lot_modal.on('shown.bs.modal', function(){
self.$('.js_lot_scan').focus();
})
//reactivate scanner when dialog close
$lot_modal.on('hidden.bs.modal', function(){
self.getParent().barcode_scanner.connect(function(ean){
self.getParent().scan(ean);
});
})
self.$('.js_lot_scan').focus();
//button action
self.$('.js_validate_lot').click(function(){
//get content of input
var name = self.$('.js_lot_scan').val();
if (name.length !== 0){
lot_name = name;
}
$lot_modal.modal('hide');
//we need this here since it is not sure the hide event
//will be catch because we refresh the view after the create_lot call
self.getParent().barcode_scanner.connect(function(ean){
self.getParent().scan(ean);
});
self.getParent().create_lot(op_id, lot_name);
});
});
this.$('.js_delete_pack').click(function(){
var pack_id = $(this).parents("[data-id]:first").data('id');
@ -846,10 +877,10 @@ function openerp_picking_widgets(instance){
}
});
},
create_lot: function(op_id){
create_lot: function(op_id, lot_name){
var self = this;
new instance.web.Model('stock.pack.operation')
.call('create_and_assign_lot',[parseInt(op_id)])
.call('create_and_assign_lot',[parseInt(op_id), lot_name])
.then(function(){
return self.refresh_ui(self.picking.id);
});

View File

@ -27,6 +27,25 @@
</div>
</div>
<div class="modal fade" id="js_LotChooseModal" tabindex="-1" role="dialog" aria-labelledby="LotChooseModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title" id="myModalLabel">Create Lot</h4>
</div>
<div class="modal-body">
<p>Scan a lot or type it below (leave empty to generate one automatically)</p>
<input class='col-xs-6 js_lot_scan' type='text'/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary js_validate_lot">Create Lot</button>
</div>
</div>
</div>
</div>
<div class="row">
<div>
<div class="col-sm-4 col-xs-6">

View File

@ -3807,13 +3807,16 @@ class stock_pack_operation(osv.osv):
processed_ids.append(op)
self.write(cr, uid, processed_ids, {'processed': 'true'}, context=context)
def create_and_assign_lot(self, cr, uid, id, context=None):
def create_and_assign_lot(self, cr, uid, id, name, context=None):
''' Used by barcode interface to create a new lot and assign it to the operation
'''
obj = self.browse(cr,uid,id,context)
product_id = obj.product_id.id
val = {'product_id': product_id}
if name:
val.update({'name': name})
if not obj.lot_id:
new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, {'product_id': product_id}, context=context)
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, increment=True, context=None):