2013-06-26 08:30:39 +00:00
|
|
|
|
|
|
|
function openerp_picking_widgets(instance){
|
2013-11-13 17:24:48 +00:00
|
|
|
|
2013-06-26 08:30:39 +00:00
|
|
|
var module = instance.stock;
|
2013-11-13 17:24:48 +00:00
|
|
|
var _t = instance.web._t;
|
|
|
|
var QWeb = instance.web.qweb;
|
2013-06-26 08:30:39 +00:00
|
|
|
|
|
|
|
module.PickingEditorWidget = instance.web.Widget.extend({
|
|
|
|
template: 'PickingEditorWidget',
|
2013-06-26 13:11:31 +00:00
|
|
|
init: function(parent,options){
|
|
|
|
this._super(parent,options);
|
|
|
|
},
|
2013-06-26 08:30:39 +00:00
|
|
|
get_header: function(){
|
2013-06-27 09:58:27 +00:00
|
|
|
var model = this.getParent();
|
|
|
|
return 'Picking: '+model.picking.name;
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
get_rows: function(){
|
2013-06-26 14:14:21 +00:00
|
|
|
var model = this.getParent();
|
|
|
|
var rows = [];
|
2013-06-27 14:00:54 +00:00
|
|
|
|
2013-06-26 14:14:21 +00:00
|
|
|
_.each( model.movelines, function(moveline){
|
|
|
|
rows.push({
|
|
|
|
cols: { product: moveline.product_id[1],
|
2013-06-30 14:10:14 +00:00
|
|
|
qty: moveline.product_uom_qty,
|
2013-06-27 09:58:27 +00:00
|
|
|
rem: moveline.remaining_qty,
|
2013-06-26 14:14:21 +00:00
|
|
|
uom: moveline.product_uom[1],
|
|
|
|
loc: moveline.location_id[1],
|
|
|
|
stat: moveline.state
|
|
|
|
},
|
|
|
|
classes: (moveline.qty_remaining < 0 ? 'oe_invalid' : '')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return rows;
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.PackageEditorWidget = instance.web.Widget.extend({
|
|
|
|
template: 'PackageEditorWidget',
|
|
|
|
get_header: function(){
|
2013-06-27 12:32:02 +00:00
|
|
|
var model = this.getParent();
|
2013-06-28 09:55:47 +00:00
|
|
|
var current_package = model.get_selected_package();
|
|
|
|
return current_package ? 'Operations for Package: ' + current_package.name : 'Current Operations';
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
get_rows: function(){
|
2013-06-27 09:58:27 +00:00
|
|
|
var model = this.getParent();
|
|
|
|
var rows = [];
|
2013-06-28 15:15:03 +00:00
|
|
|
var ops = model.get_current_operations();
|
|
|
|
|
|
|
|
_.each( ops, function(op){
|
2013-06-27 09:58:27 +00:00
|
|
|
rows.push({
|
|
|
|
cols: {
|
|
|
|
product: op.product_id[1],
|
2013-06-27 12:32:02 +00:00
|
|
|
uom: op.product_uom ? product_uom[1] : '',
|
2013-07-23 15:34:24 +00:00
|
|
|
qty: op.product_qty,
|
2013-06-27 09:58:27 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return rows;
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.PackageSelectorWidget = instance.web.Widget.extend({
|
|
|
|
template: 'PackageSelectorWidget',
|
|
|
|
get_header: function(){
|
2013-06-27 14:00:54 +00:00
|
|
|
return this._header || 'Packages:';
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
get_rows: function(){
|
2013-06-27 14:00:54 +00:00
|
|
|
var model = this.getParent();
|
2013-06-28 09:55:47 +00:00
|
|
|
var current_package = model.get_selected_package();
|
2013-06-27 14:00:54 +00:00
|
|
|
var rows = [];
|
|
|
|
_.each( model.packages, function(pack){
|
|
|
|
rows.push({
|
|
|
|
cols:{ pack: pack.name},
|
2013-06-28 09:55:47 +00:00
|
|
|
id: pack.id,
|
2013-06-28 11:39:49 +00:00
|
|
|
classes: pack === current_package ? ' oe_selected' : '' ,
|
2013-06-27 14:00:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return rows;
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
2013-06-28 09:55:47 +00:00
|
|
|
renderElement: function(){
|
|
|
|
this._super();
|
|
|
|
var model = this.getParent();
|
2013-06-28 11:39:49 +00:00
|
|
|
this.$('.js_pack_row').each(function(){
|
|
|
|
var pack_id = parseInt($(this).attr('pack-id'));
|
|
|
|
|
2013-07-08 10:34:00 +00:00
|
|
|
$('.js_pack_print', this).click(function(){ model.print_package(pack_id); });
|
2013-06-28 11:39:49 +00:00
|
|
|
$('.js_pack_plus', this).click(function(){ model.copy_package(pack_id); });
|
|
|
|
$('.js_pack_minus', this).click(function(){ model.delete_package(pack_id); });
|
2013-06-28 12:46:49 +00:00
|
|
|
$('.js_pack_select', this).click(function(){
|
|
|
|
if(model.get_selected_package() && model.get_selected_package().id === pack_id){
|
|
|
|
model.deselect_package();
|
|
|
|
}else{
|
|
|
|
model.select_package(pack_id);
|
|
|
|
}
|
|
|
|
});
|
2013-06-28 09:55:47 +00:00
|
|
|
});
|
|
|
|
},
|
2013-06-26 08:30:39 +00:00
|
|
|
});
|
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
module.PickingMenuWidget = instance.web.Widget.extend({
|
|
|
|
template: 'PickingMenuWidget',
|
|
|
|
init: function(parent, params){
|
|
|
|
this._super(parent,params);
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.picking_types = [];
|
|
|
|
this.loaded = this.load();
|
|
|
|
this.scanning_type = 0;
|
|
|
|
this.barcode_scanner = new module.BarcodeScanner();
|
|
|
|
this.pickings_by_type = {};
|
2013-11-13 17:24:48 +00:00
|
|
|
this.pickings_by_id = {};
|
|
|
|
this.picking_search_string = "";
|
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
},
|
|
|
|
load: function(){
|
|
|
|
var self = this;
|
|
|
|
return new instance.web.Model('stock.picking.type').get_func('search_read')([],[])
|
|
|
|
.then(function(types){
|
|
|
|
self.picking_types = types;
|
|
|
|
|
|
|
|
for(var i = 0; i < types.length; i++){
|
|
|
|
self.pickings_by_type[types[i].id] = [];
|
|
|
|
}
|
|
|
|
self.pickings_by_type[0] = [];
|
|
|
|
|
|
|
|
return new instance.web.Model('stock.picking').call('search_read',[ [['state','in',['confirmed','assigned']]], [] ], {context: new instance.web.CompoundContext()});
|
|
|
|
|
|
|
|
}).then(function(pickings){
|
|
|
|
self.pickings = pickings;
|
|
|
|
|
|
|
|
for(var i = 0; i < pickings.length; i++){
|
|
|
|
var picking = pickings[i];
|
|
|
|
self.pickings_by_type[picking.picking_type_id[0]].push(picking);
|
2013-11-13 17:24:48 +00:00
|
|
|
self.pickings_by_id[picking.id] = picking;
|
|
|
|
self.picking_search_string += '' + picking.id + ':' + picking.name.toUpperCase() + '\n'
|
2013-10-03 09:49:04 +00:00
|
|
|
}
|
2013-11-13 17:24:48 +00:00
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
renderElement: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
|
|
|
this.$('.js_pick_quit').click(function(){ self.quit(); });
|
|
|
|
this.$('.js_pick_scan').click(function(){ self.scan_picking($(this).data('id')); });
|
2013-11-13 17:24:48 +00:00
|
|
|
this.$('.js_pick_last').click(function(){ self.goto_last_picking_of_type($(this).data('id')); });
|
|
|
|
this.$('.oe_searchbox input').keyup(function(event){
|
|
|
|
self.on_searchbox($(this).val());
|
|
|
|
});
|
2013-10-03 09:49:04 +00:00
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
this.barcode_scanner.connect(function(barcode){
|
|
|
|
self.on_scan(barcode);
|
|
|
|
});
|
|
|
|
this.loaded.then(function(){
|
|
|
|
self.renderElement();
|
|
|
|
});
|
|
|
|
},
|
2013-11-13 17:24:48 +00:00
|
|
|
goto_picking: function(picking_id){
|
|
|
|
this.do_action({
|
|
|
|
type: 'ir.actions.client',
|
|
|
|
tag: 'stock.ui',
|
|
|
|
target: 'current',
|
|
|
|
context: { picking_id: picking_id },
|
|
|
|
},{
|
|
|
|
clear_breadcrumbs: true,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
goto_last_picking_of_type: function(type_id){
|
2013-10-03 09:49:04 +00:00
|
|
|
this.do_action({
|
|
|
|
type: 'ir.actions.client',
|
|
|
|
tag: 'stock.ui',
|
|
|
|
target: 'current',
|
|
|
|
context: { active_id: type_id },
|
|
|
|
},{
|
|
|
|
clear_breadcrumbs: true,
|
|
|
|
});
|
|
|
|
},
|
2013-11-13 17:24:48 +00:00
|
|
|
search_picking: function(barcode){
|
|
|
|
var re = RegExp("([0-9]+):.*?"+barcode.toUpperCase(),"gi");
|
|
|
|
var results = [];
|
|
|
|
for(var i = 0; i < 100; i++){
|
|
|
|
r = re.exec(this.picking_search_string);
|
|
|
|
if(r){
|
|
|
|
var picking = this.pickings_by_id[Number(r[1])];
|
|
|
|
if(picking){
|
|
|
|
results.push(picking);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
}
|
2013-10-03 09:49:04 +00:00
|
|
|
}
|
2013-11-13 17:24:48 +00:00
|
|
|
return results;
|
2013-10-03 09:49:04 +00:00
|
|
|
},
|
|
|
|
on_scan: function(barcode){
|
2013-11-13 17:24:48 +00:00
|
|
|
var self = this;
|
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
for(var i = 0, len = this.pickings.length; i < len; i++){
|
|
|
|
var picking = this.pickings[i];
|
2013-11-13 17:24:48 +00:00
|
|
|
if(picking.name.toUpperCase() === barcode.toUpperCase()){
|
|
|
|
this.goto_picking(picking.id);
|
|
|
|
break;
|
2013-10-03 09:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-13 17:24:48 +00:00
|
|
|
this.$('.oe_picking_not_found').removeClass('oe_hidden');
|
|
|
|
|
|
|
|
clearTimeout(this.picking_not_found_timeout);
|
|
|
|
this.picking_not_found_timeout = setTimeout(function(){
|
|
|
|
self.$('.oe_picking_not_found').addClass('oe_hidden');
|
|
|
|
},2000);
|
|
|
|
|
|
|
|
},
|
|
|
|
on_searchbox: function(query){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
clearTimeout(this.searchbox_timeout);
|
|
|
|
this.searchbox_timout = setTimeout(function(){
|
|
|
|
if(query){
|
|
|
|
self.$('.oe_picking_not_found').addClass('oe_hidden');
|
|
|
|
self.$('.oe_picking_categories').addClass('oe_hidden');
|
|
|
|
self.$('.oe_picking_search_results').html(
|
|
|
|
QWeb.render('PickingSearchResults',{results:self.search_picking(query)})
|
|
|
|
);
|
|
|
|
self.$('.oe_picking_search_results .oe_picking').click(function(){
|
|
|
|
self.goto_picking($(this).data('id'));
|
|
|
|
});
|
|
|
|
self.$('.oe_picking_search_results').removeClass('oe_hidden');
|
|
|
|
}else{
|
|
|
|
self.$('.oe_picking_categories').removeClass('oe_hidden');
|
|
|
|
self.$('.oe_picking_search_results').addClass('oe_hidden');
|
|
|
|
}
|
|
|
|
},100);
|
2013-10-03 09:49:04 +00:00
|
|
|
},
|
|
|
|
quit: function(){
|
|
|
|
instance.webclient.set_content_full_screen(false);
|
|
|
|
window.location = '/'; // FIXME Ask niv how to do it correctly
|
|
|
|
},
|
|
|
|
destroy: function(){
|
|
|
|
this._super();
|
|
|
|
this.barcode_scanner.disconnect();
|
|
|
|
instance.webclient.set_content_full_screen(false);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
openerp.web.client_actions.add('stock.menu', 'instance.stock.PickingMenuWidget');
|
|
|
|
|
2013-06-26 08:30:39 +00:00
|
|
|
module.PickingMainWidget = instance.web.Widget.extend({
|
|
|
|
template: 'PickingMainWidget',
|
2013-06-26 09:20:29 +00:00
|
|
|
init: function(parent,params){
|
|
|
|
this._super(parent,params);
|
2013-06-26 14:14:21 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.picking = null;
|
2013-10-01 09:21:22 +00:00
|
|
|
this.pickings = [];
|
2013-06-26 14:14:21 +00:00
|
|
|
this.movelines = null;
|
2013-06-27 09:58:27 +00:00
|
|
|
this.operations = null;
|
2013-06-27 15:39:01 +00:00
|
|
|
this.packages = null;
|
2013-10-03 09:49:04 +00:00
|
|
|
this.barcode_scanner = new module.BarcodeScanner();
|
|
|
|
this.picking_type_id = params.context.active_id || 0;
|
2013-06-26 14:14:21 +00:00
|
|
|
|
2013-06-26 13:11:31 +00:00
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
if(params.context.picking_id){
|
|
|
|
this.loaded = this.load(params.context.picking_id);
|
|
|
|
}else{
|
|
|
|
this.loaded = this.load();
|
|
|
|
}
|
2013-06-27 15:25:30 +00:00
|
|
|
},
|
2013-10-03 09:49:04 +00:00
|
|
|
|
|
|
|
// load the picking data from the server. If picking_id is undefined, it will take the first picking
|
|
|
|
// belonging to the category
|
2013-06-27 15:25:30 +00:00
|
|
|
load: function(picking_id){
|
|
|
|
var self = this;
|
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
|
|
|
|
function load_picking_list(type_id){
|
|
|
|
var pickings = new $.Deferred();
|
2013-06-28 15:15:03 +00:00
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
new instance.web.Model('stock.picking')
|
|
|
|
.call('get_picking_for_packing_ui',[{'default_picking_type_id':type_id}])
|
2013-10-01 09:21:22 +00:00
|
|
|
.then(function(picking_ids){
|
|
|
|
if(!picking_ids || picking_ids.length === 0){
|
2013-09-25 13:09:58 +00:00
|
|
|
(new instance.web.Dialog(self,{
|
|
|
|
title: _t('No Picking Available'),
|
|
|
|
buttons: [{
|
|
|
|
text:_t('Ok'),
|
|
|
|
click: function(){
|
|
|
|
self.quit();
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}, _t('<p>We could not find a picking to display.</p>'))).open();
|
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
pickings.reject();
|
2013-09-25 13:09:58 +00:00
|
|
|
}else{
|
2013-10-01 09:21:22 +00:00
|
|
|
self.pickings = picking_ids;
|
2013-10-03 09:49:04 +00:00
|
|
|
pickings.resolve(picking_ids);
|
2013-09-25 13:09:58 +00:00
|
|
|
}
|
2013-06-28 16:20:26 +00:00
|
|
|
});
|
2013-10-03 09:49:04 +00:00
|
|
|
|
|
|
|
return pickings;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we have a specified picking id, we load that one, and we load the picking of the same type as the active list
|
|
|
|
if( picking_id ){
|
|
|
|
var loaded_picking = new instance.web.Model('stock.picking')
|
|
|
|
.call('read',[[picking_id], [], new instance.web.CompoundContext()])
|
|
|
|
.then(function(picking){
|
|
|
|
self.picking = picking[0];
|
|
|
|
|
|
|
|
return load_picking_list(self.picking.picking_type_id[0]);
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
// if we don't have a specified picking id, we load the pickings belong to the specified type, and then we take
|
|
|
|
// the first one of that list as the active picking
|
|
|
|
var loaded_picking = new $.Deferred();
|
|
|
|
load_picking_list(self.picking_type_id)
|
|
|
|
.then(function(){
|
|
|
|
return new instance.web.Model('stock.picking').call('read',[self.pickings[0],[], new instance.web.CompoundContext()]);
|
|
|
|
})
|
|
|
|
.then(function(picking){
|
|
|
|
self.picking = picking;
|
|
|
|
loaded_picking.resolve();
|
|
|
|
});
|
2013-06-27 15:25:30 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 09:49:04 +00:00
|
|
|
var loaded = loaded_picking.then(function(){
|
2013-06-27 15:25:30 +00:00
|
|
|
|
2013-06-27 16:47:54 +00:00
|
|
|
return new instance.web.Model('stock.move').call('read',[self.picking.move_lines, [], new instance.web.CompoundContext()]);
|
2013-06-26 14:14:21 +00:00
|
|
|
}).then(function(movelines){
|
|
|
|
self.movelines = movelines;
|
2013-06-27 09:58:27 +00:00
|
|
|
|
2013-06-27 16:47:54 +00:00
|
|
|
return new instance.web.Model('stock.pack.operation').call('read',[self.picking.pack_operation_ids, [], new instance.web.CompoundContext()]);
|
2013-06-27 09:58:27 +00:00
|
|
|
}).then(function(operations){
|
|
|
|
self.operations = operations;
|
2013-06-27 16:26:27 +00:00
|
|
|
|
|
|
|
var package_ids = [];
|
2013-06-27 14:00:54 +00:00
|
|
|
|
2013-06-27 16:26:27 +00:00
|
|
|
for(var i = 0; i < operations.length; i++){
|
|
|
|
if(!_.contains(package_ids,operations[i].result_package_id[0])){
|
|
|
|
package_ids.push(operations[i].result_package_id[0]);
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 16:47:54 +00:00
|
|
|
|
2013-06-27 16:26:27 +00:00
|
|
|
|
2013-06-27 16:47:54 +00:00
|
|
|
return new instance.web.Model('stock.quant.package').call('read',[package_ids, [], new instance.web.CompoundContext()]);
|
2013-06-27 14:00:54 +00:00
|
|
|
}).then(function(packages){
|
|
|
|
self.packages = packages;
|
2013-06-26 13:11:31 +00:00
|
|
|
});
|
2013-06-26 08:30:39 +00:00
|
|
|
|
2013-06-27 15:25:30 +00:00
|
|
|
return loaded;
|
2013-10-03 09:49:04 +00:00
|
|
|
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
instance.webclient.set_content_full_screen(true);
|
2013-10-03 09:49:04 +00:00
|
|
|
this.connect_numpad();
|
|
|
|
this.barcode_scanner.connect(function(ean){
|
|
|
|
self.scan(ean);
|
|
|
|
});
|
2013-06-26 08:30:39 +00:00
|
|
|
|
2013-06-26 14:38:15 +00:00
|
|
|
this.$('.js_pick_quit').click(function(){ self.quit(); });
|
2013-06-27 14:15:43 +00:00
|
|
|
this.$('.js_pick_pack').click(function(){ self.pack(); });
|
2013-06-27 15:25:30 +00:00
|
|
|
this.$('.js_pick_done').click(function(){ self.done(); });
|
2013-10-01 09:21:22 +00:00
|
|
|
this.$('.js_pick_prev').click(function(){ self.picking_prev(); });
|
|
|
|
this.$('.js_pick_next').click(function(){ self.picking_next(); });
|
2013-10-03 09:49:04 +00:00
|
|
|
this.$('.js_pick_menu').click(function(){ self.menu(); });
|
2013-06-26 14:38:15 +00:00
|
|
|
|
2013-11-13 17:24:48 +00:00
|
|
|
this.hotkey_handler = function(event){
|
|
|
|
if(event.keyCode === 37 ){ // Left Arrow
|
|
|
|
self.picking_prev();
|
|
|
|
}else if(event.keyCode === 39){ // Right Arrow
|
|
|
|
self.picking_next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$('body').on('keyup',this.hotkey_handler);
|
|
|
|
|
2013-06-26 14:14:21 +00:00
|
|
|
$.when(this.loaded).done(function(){
|
2013-06-27 09:58:27 +00:00
|
|
|
self.picking_editor = new module.PickingEditorWidget(self);
|
|
|
|
self.picking_editor.replace(self.$('.oe_placeholder_picking_editor'));
|
2013-06-26 14:14:21 +00:00
|
|
|
|
2013-06-27 09:58:27 +00:00
|
|
|
self.package_editor = new module.PackageEditorWidget(self);
|
|
|
|
self.package_editor.replace(self.$('.oe_placeholder_package_editor'));
|
2013-06-26 08:30:39 +00:00
|
|
|
|
2013-06-27 09:58:27 +00:00
|
|
|
self.package_selector = new module.PackageSelectorWidget(self);
|
|
|
|
self.package_selector.replace(self.$('.oe_placeholder_package_selector'));
|
2013-10-01 09:21:22 +00:00
|
|
|
|
|
|
|
if( self.picking.id === self.pickings[0]){
|
|
|
|
self.$('.js_pick_prev').addClass('oe_disabled');
|
|
|
|
}else{
|
|
|
|
self.$('.js_pick_prev').removeClass('oe_disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
if( self.picking.id === self.pickings[self.pickings.length-1] ){
|
|
|
|
self.$('.js_pick_next').addClass('oe_disabled');
|
|
|
|
}else{
|
|
|
|
self.$('.js_pick_next').removeClass('oe_disabled');
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:14:21 +00:00
|
|
|
});
|
2013-06-26 08:30:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
return this._super();
|
|
|
|
},
|
2013-06-27 15:25:30 +00:00
|
|
|
// reloads the data from the provided picking and refresh the ui.
|
|
|
|
// (if no picking_id is provided, gets the first picking in the db)
|
|
|
|
refresh_ui: function(picking_id){
|
|
|
|
var self = this;
|
|
|
|
return this.load(picking_id)
|
|
|
|
.then(function(){
|
|
|
|
self.picking_editor.renderElement();
|
|
|
|
self.package_editor.renderElement();
|
|
|
|
self.package_selector.renderElement();
|
2013-10-01 09:21:22 +00:00
|
|
|
if( self.picking.id === self.pickings[0]){
|
|
|
|
self.$('.js_pick_prev').addClass('oe_disabled');
|
|
|
|
}else{
|
|
|
|
self.$('.js_pick_prev').removeClass('oe_disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
if( self.picking.id === self.pickings[self.pickings.length-1] ){
|
|
|
|
self.$('.js_pick_next').addClass('oe_disabled');
|
|
|
|
}else{
|
|
|
|
self.$('.js_pick_next').removeClass('oe_disabled');
|
|
|
|
}
|
2013-06-27 15:25:30 +00:00
|
|
|
});
|
|
|
|
},
|
2013-10-03 09:49:04 +00:00
|
|
|
menu: function(){
|
|
|
|
this.do_action({
|
|
|
|
type: 'ir.actions.client',
|
|
|
|
tag: 'stock.menu',
|
|
|
|
target: 'current',
|
|
|
|
},{
|
|
|
|
clear_breadcrumbs: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
2013-06-26 14:14:21 +00:00
|
|
|
scan: function(ean){
|
2013-06-27 09:58:27 +00:00
|
|
|
var self = this;
|
2013-06-26 14:14:21 +00:00
|
|
|
new instance.web.Model('stock.picking')
|
2013-06-27 14:00:54 +00:00
|
|
|
.call('get_barcode_and_return_todo_stuff', [self.picking.id, ean])
|
2013-06-27 15:25:30 +00:00
|
|
|
.then(function(){
|
|
|
|
return self.refresh_ui(self.picking.id);
|
2013-06-26 14:14:21 +00:00
|
|
|
});
|
|
|
|
},
|
2013-06-27 14:15:43 +00:00
|
|
|
pack: function(){
|
|
|
|
var self = this;
|
2013-06-27 15:25:30 +00:00
|
|
|
new instance.web.Model('stock.picking')
|
2013-07-24 17:30:39 +00:00
|
|
|
.call('action_pack',[[[self.picking.id]]])
|
2013-06-27 14:15:43 +00:00
|
|
|
.then(function(){
|
|
|
|
instance.session.user_context.current_package_id = false;
|
|
|
|
|
2013-06-27 15:25:30 +00:00
|
|
|
return self.refresh_ui(self.picking.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
done: function(){
|
|
|
|
var self = this;
|
|
|
|
new instance.web.Model('stock.picking')
|
2013-06-28 15:57:32 +00:00
|
|
|
.call('action_done_from_packing_ui',[self.picking.id])
|
2013-06-27 15:25:30 +00:00
|
|
|
.then(function(new_picking_id){
|
2013-07-08 10:34:00 +00:00
|
|
|
return self.refresh_ui(new_picking_id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
print_package: function(package_id){
|
|
|
|
var self = this;
|
|
|
|
new instance.web.Model('stock.quant.package')
|
|
|
|
.call('action_print',[[package_id]])
|
|
|
|
.then(function(action){
|
|
|
|
return self.do_action(action);
|
2013-06-28 11:39:49 +00:00
|
|
|
});
|
|
|
|
},
|
2013-10-01 09:21:22 +00:00
|
|
|
picking_next: function(){
|
|
|
|
for(var i = 0; i < this.pickings.length; i++){
|
|
|
|
if(this.pickings[i] === this.picking.id){
|
|
|
|
if(i < this.pickings.length -1){
|
|
|
|
this.refresh_ui(this.pickings[i+1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
picking_prev: function(){
|
|
|
|
for(var i = 0; i < this.pickings.length; i++){
|
|
|
|
if(this.pickings[i] === this.picking.id){
|
|
|
|
if(i > 0){
|
|
|
|
this.refresh_ui(this.pickings[i-1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-06-28 11:39:49 +00:00
|
|
|
copy_package: function(package_id){
|
2013-06-28 13:19:58 +00:00
|
|
|
var self = this;
|
2013-06-28 11:39:49 +00:00
|
|
|
new instance.web.Model('stock.quant.package')
|
2013-07-23 15:34:24 +00:00
|
|
|
.call('copy',[[package_id]])
|
2013-06-28 11:39:49 +00:00
|
|
|
.then(function(){
|
|
|
|
return self.refresh_ui(self.picking.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
delete_package: function(package_id){
|
2013-06-28 13:19:58 +00:00
|
|
|
var self = this;
|
2013-06-28 11:39:49 +00:00
|
|
|
new instance.web.Model('stock.quant.package')
|
2013-06-28 12:46:49 +00:00
|
|
|
.call('unlink',[[package_id]])
|
2013-06-28 11:39:49 +00:00
|
|
|
.then(function(){
|
|
|
|
return self.refresh_ui(self.picking.id);
|
2013-06-27 14:15:43 +00:00
|
|
|
});
|
|
|
|
},
|
2013-06-28 12:46:49 +00:00
|
|
|
deselect_package: function(){
|
|
|
|
instance.session.user_context.current_package_id = false;
|
|
|
|
this.package_editor.renderElement();
|
|
|
|
this.package_selector.renderElement();
|
|
|
|
},
|
2013-06-28 09:55:47 +00:00
|
|
|
select_package: function(package_id){
|
|
|
|
instance.session.user_context.current_package_id = package_id;
|
|
|
|
this.package_editor.renderElement();
|
|
|
|
this.package_selector.renderElement();
|
|
|
|
},
|
|
|
|
get_selected_package: function(){
|
|
|
|
var current_package;
|
|
|
|
|
|
|
|
_.each( this.packages, function(pack){
|
|
|
|
if(pack.id === instance.session.user_context.current_package_id){
|
|
|
|
current_package = pack;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return current_package;
|
|
|
|
},
|
2013-06-28 15:15:03 +00:00
|
|
|
get_current_operations: function(){
|
|
|
|
var current_package_id = instance.session.user_context.current_package_id;
|
|
|
|
var ops = [];
|
|
|
|
_.each( this.operations, function(op){
|
|
|
|
if(!current_package_id){
|
|
|
|
if(op.result_package_id !== false){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}else if(op.result_package_id[0] !== current_package_id){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ops.push(op);
|
|
|
|
});
|
|
|
|
return ops;
|
|
|
|
},
|
2013-06-28 14:40:19 +00:00
|
|
|
set_operation_quantity: function(quantity){
|
2013-06-28 15:15:03 +00:00
|
|
|
var self = this;
|
|
|
|
var ops = this.get_current_operations();
|
|
|
|
if( !ops || ops.length === 0){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var op = ops[ops.length-1];
|
|
|
|
|
2013-06-28 14:40:19 +00:00
|
|
|
if(quantity === '++'){
|
2013-06-28 15:15:03 +00:00
|
|
|
quantity = op.product_qty + 1;
|
2013-06-28 14:40:19 +00:00
|
|
|
}else if(quantity === '--'){
|
2013-06-28 15:15:03 +00:00
|
|
|
quantity = op.product_qty - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(typeof quantity === 'number' && quantity >= 0){
|
|
|
|
new instance.web.Model('stock.pack.operation')
|
|
|
|
.call('write',[[op.id],{'product_qty': quantity }])
|
|
|
|
.then(function(){
|
|
|
|
self.refresh_ui(self.picking.id);
|
|
|
|
});
|
2013-06-28 14:40:19 +00:00
|
|
|
}
|
2013-06-28 15:15:03 +00:00
|
|
|
|
2013-06-28 14:40:19 +00:00
|
|
|
},
|
2013-10-03 09:49:04 +00:00
|
|
|
connect_numpad: function(){
|
2013-06-28 15:15:03 +00:00
|
|
|
var self = this;
|
2013-06-28 14:40:19 +00:00
|
|
|
var numpad = [];
|
|
|
|
var numpad_timestamp;
|
2013-10-03 09:49:04 +00:00
|
|
|
|
|
|
|
this.numpad_handler = function(e){
|
|
|
|
// upper row numbers are reserved for the barcode scanner
|
|
|
|
if( e.keyCode < 48 && e.keyCode >= 58){
|
2013-06-28 14:40:19 +00:00
|
|
|
if(numpad_timestamp + 1500 < new Date().getTime()){
|
|
|
|
numpad = [];
|
|
|
|
}
|
|
|
|
if(e.keyCode === 27 || e.keyCode === 8){ // ESC or BACKSPACE
|
|
|
|
numpad = [];
|
|
|
|
}else if(e.keyCode >= 96 && e.keyCode <= 105){ // NUMPAD NUMBERS
|
|
|
|
numpad.push(e.keyCode - 96);
|
|
|
|
}else if(e.keyCode === 13){ // ENTER
|
|
|
|
if(numpad.length > 0){
|
|
|
|
self.set_operation_quantity(parseInt(numpad.join('')));
|
|
|
|
}
|
|
|
|
numpad = [];
|
|
|
|
}else if(e.keyCode === 107){ // NUMPAD +
|
|
|
|
self.set_operation_quantity('++');
|
|
|
|
numpad = [];
|
|
|
|
}else if(e.keyCode === 109){ // NUMPAD -
|
|
|
|
self.set_operation_quantity('--');
|
|
|
|
numpad = [];
|
|
|
|
}else{
|
|
|
|
numpad = [];
|
|
|
|
}
|
|
|
|
numpad_timestamp = new Date().getTime();
|
2013-06-27 12:57:08 +00:00
|
|
|
}
|
2013-10-03 09:49:04 +00:00
|
|
|
};
|
|
|
|
$('body').on('keypress', this.numpad_handler);
|
2013-06-27 12:57:08 +00:00
|
|
|
},
|
2013-10-03 09:49:04 +00:00
|
|
|
disconnect_numpad: function(){
|
|
|
|
$('body').off('keypress', this.numpad_handler);
|
2013-06-27 12:57:08 +00:00
|
|
|
},
|
2013-06-26 14:38:15 +00:00
|
|
|
quit: function(){
|
2013-10-03 09:49:04 +00:00
|
|
|
this.destroy();
|
2013-09-25 13:09:58 +00:00
|
|
|
window.location = '/'; // FIXME Ask niv how to do it correctly
|
2013-06-26 14:38:15 +00:00
|
|
|
},
|
2013-10-03 09:49:04 +00:00
|
|
|
destroy: function(){
|
|
|
|
this._super();
|
|
|
|
this.disconnect_numpad();
|
|
|
|
this.barcode_scanner.disconnect();
|
2013-11-13 17:24:48 +00:00
|
|
|
$('body').off('keyup',this.hotkey_handler);
|
2013-10-03 09:49:04 +00:00
|
|
|
instance.webclient.set_content_full_screen(false);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
openerp.web.client_actions.add('stock.ui', 'instance.stock.PickingMainWidget');
|
|
|
|
|
|
|
|
module.BarcodeScanner = instance.web.Class.extend({
|
|
|
|
connect: function(callback){
|
|
|
|
var code = "";
|
|
|
|
var timeStamp = 0;
|
|
|
|
var timeout = null;
|
|
|
|
|
|
|
|
this.handler = function(e){
|
|
|
|
if(e.which === 13){ //ignore returns
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(timeStamp + 50 < new Date().getTime()){
|
|
|
|
code = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
timeStamp = new Date().getTime();
|
|
|
|
clearTimeout(timeout);
|
|
|
|
|
|
|
|
code += String.fromCharCode(e.which);
|
|
|
|
|
|
|
|
timeout = setTimeout(function(){
|
|
|
|
if(code.length >= 3){
|
|
|
|
callback(code);
|
|
|
|
}
|
|
|
|
code = "";
|
|
|
|
},100);
|
|
|
|
};
|
|
|
|
|
|
|
|
$('body').on('keypress', this.handler);
|
|
|
|
|
|
|
|
},
|
|
|
|
disconnect: function(){
|
|
|
|
$('body').off('keypress', this.handler);
|
|
|
|
},
|
2013-06-26 08:30:39 +00:00
|
|
|
});
|
2013-10-03 09:49:04 +00:00
|
|
|
|
2013-06-26 08:30:39 +00:00
|
|
|
}
|