2013-06-26 08:30:39 +00:00
|
|
|
|
|
|
|
function openerp_picking_widgets(instance){
|
|
|
|
var module = instance.stock;
|
|
|
|
|
|
|
|
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],
|
|
|
|
qty: moveline.product_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-27 15:25:30 +00:00
|
|
|
var current_package_id = instance.session.user_context.current_package_id;
|
|
|
|
return current_package_id ? 'Current Operations for package: ' + current_package_id[1] : 'Current Operations';
|
2013-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
get_rows: function(){
|
2013-06-27 15:25:30 +00:00
|
|
|
var current_package_id = instance.session.user_context.current_package_id;
|
2013-06-27 09:58:27 +00:00
|
|
|
var model = this.getParent();
|
|
|
|
var rows = [];
|
|
|
|
|
|
|
|
_.each( model.operations, function(op){
|
2013-06-27 15:25:30 +00:00
|
|
|
if(current_package_id && op.package_id !== current_package_id){
|
2013-06-27 12:32:02 +00:00
|
|
|
return;
|
|
|
|
}
|
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-06-27 09:58:27 +00:00
|
|
|
qty: op.product_qty,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
var rows = [];
|
|
|
|
_.each( model.packages, function(pack){
|
|
|
|
rows.push({
|
|
|
|
cols:{ pack: pack.name},
|
|
|
|
id: pack.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return rows;
|
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;
|
|
|
|
this.movelines = null;
|
2013-06-27 09:58:27 +00:00
|
|
|
this.operations = null;
|
2013-06-26 14:14:21 +00:00
|
|
|
|
|
|
|
window.pickwidget = this;
|
2013-06-26 13:11:31 +00:00
|
|
|
|
|
|
|
console.log('Action params:', params);
|
2013-06-27 12:32:02 +00:00
|
|
|
console.log('Session:',instance.session);
|
2013-06-26 13:11:31 +00:00
|
|
|
|
2013-06-27 15:25:30 +00:00
|
|
|
this.loaded = this.load();
|
|
|
|
},
|
|
|
|
load: function(picking_id){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if(picking_id){
|
|
|
|
var picking = new instance.web.Model('stock.picking.in').call('read',[[picking_id], []]);
|
|
|
|
}else{
|
|
|
|
var picking = new instance.web.Model('stock.picking.in').query().first();
|
|
|
|
}
|
|
|
|
|
|
|
|
var loaded = picking.then(function(picking){
|
|
|
|
self.picking = picking instanceof Array ? picking[0] : picking;
|
|
|
|
console.log('Picking:',self.picking);
|
|
|
|
|
2013-06-26 14:14:21 +00:00
|
|
|
return new instance.web.Model('stock.move').call('read',[self.picking.move_lines, []]);
|
|
|
|
}).then(function(movelines){
|
|
|
|
self.movelines = movelines;
|
|
|
|
console.log('Move Lines:',movelines);
|
2013-06-27 09:58:27 +00:00
|
|
|
|
|
|
|
return new instance.web.Model('stock.pack.operation').call('read',[self.picking.pack_operation_ids, []]);
|
|
|
|
}).then(function(operations){
|
|
|
|
self.operations = operations;
|
|
|
|
console.log('Operations:',self.operations);
|
2013-06-27 14:00:54 +00:00
|
|
|
|
|
|
|
return new instance.web.Model('stock.quant.package').call('read',[self.picking.package_ids, []]);
|
|
|
|
}).then(function(packages){
|
|
|
|
self.packages = packages;
|
|
|
|
console.log('Packages:', self.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-06-26 08:30:39 +00:00
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
instance.webclient.set_content_full_screen(true);
|
2013-06-27 12:57:08 +00:00
|
|
|
this.connect_barcode_scanner();
|
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-06-26 14:38:15 +00:00
|
|
|
|
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-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(){
|
|
|
|
console.log('Refreshing UI');
|
|
|
|
self.picking_editor.renderElement();
|
|
|
|
self.package_editor.renderElement();
|
|
|
|
self.package_selector.renderElement();
|
|
|
|
});
|
|
|
|
},
|
2013-06-26 14:14:21 +00:00
|
|
|
scan: function(ean){
|
2013-06-27 09:58:27 +00:00
|
|
|
var self = this;
|
2013-06-27 12:57:08 +00:00
|
|
|
console.log('Scan: ',ean);
|
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;
|
|
|
|
console.log('Pack');
|
2013-06-27 15:25:30 +00:00
|
|
|
new instance.web.Model('stock.picking')
|
|
|
|
.call('action_pack',[[self.picking.id]])
|
2013-06-27 14:15:43 +00:00
|
|
|
.then(function(){
|
|
|
|
instance.session.user_context.current_package_id = false;
|
|
|
|
console.log('Context Reset');
|
|
|
|
|
2013-06-27 15:25:30 +00:00
|
|
|
return self.refresh_ui(self.picking.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
done: function(){
|
|
|
|
var self = this;
|
|
|
|
console.log('Done');
|
|
|
|
new instance.web.Model('stock.picking')
|
|
|
|
.call('action_done_from_packing_ui',[[self.picking.id]])
|
|
|
|
.then(function(new_picking_id){
|
|
|
|
console.log('New picking id:',new_picking_id);
|
2013-06-27 14:15:43 +00:00
|
|
|
});
|
|
|
|
},
|
2013-06-27 12:57:08 +00:00
|
|
|
connect_barcode_scanner: function(){
|
|
|
|
var self =this;
|
|
|
|
var code = [];
|
|
|
|
var timestamp = 0;
|
|
|
|
$('body').delegate('','keyup',function(e){
|
|
|
|
if (e.keyCode >= 48 && e.keyCode < 58){
|
|
|
|
if(timestamp + 30 < new Date().getTime()){
|
|
|
|
code = [];
|
|
|
|
}
|
|
|
|
timestamp = new Date().getTime();
|
|
|
|
code.push(e.keyCode - 48);
|
|
|
|
if(code.length === 13){
|
|
|
|
self.scan(code.join(''));
|
|
|
|
code = [];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
code = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
disconnect_barcode_scanner: function(){
|
|
|
|
$('body').undelegate('', 'keyup')
|
|
|
|
},
|
2013-06-26 14:38:15 +00:00
|
|
|
quit: function(){
|
|
|
|
console.log('Quit');
|
2013-06-27 12:57:08 +00:00
|
|
|
disconnect_barcode_scanner();
|
2013-06-26 14:38:15 +00:00
|
|
|
instance.webclient.set_content_full_screen(false);
|
|
|
|
window.location = '/'; // FIXME THIS IS SHIT NIV WILL KILL YOU (BY MULTIPLE FACE-STABBING) IF YOU MERGE THIS IN TRUNK
|
|
|
|
},
|
2013-06-26 08:30:39 +00:00
|
|
|
});
|
|
|
|
}
|