2012-05-14 14:03:40 +00:00
|
|
|
function openerp_pos_widgets(instance, module){ //module is instance.point_of_sale
|
2014-01-10 17:17:46 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
var _t = instance.web._t;
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2014-01-06 17:15:32 +00:00
|
|
|
module.DomCache = instance.web.Class.extend({
|
2012-08-16 15:02:13 +00:00
|
|
|
init: function(options){
|
|
|
|
options = options || {};
|
2014-01-06 17:15:32 +00:00
|
|
|
this.max_size = options.max_size || 2000;
|
2012-08-16 15:02:13 +00:00
|
|
|
|
|
|
|
this.cache = {};
|
|
|
|
this.access_time = {};
|
|
|
|
this.size = 0;
|
|
|
|
},
|
2014-01-06 17:15:32 +00:00
|
|
|
cache_node: function(key,node){
|
|
|
|
var cached = this.cache[key];
|
|
|
|
this.cache[key] = node;
|
|
|
|
this.access_time[key] = new Date().getTime();
|
|
|
|
if(!cached){
|
|
|
|
this.size++;
|
2012-08-16 15:02:13 +00:00
|
|
|
while(this.size >= this.max_size){
|
2014-01-06 17:15:32 +00:00
|
|
|
var oldest_key = null;
|
|
|
|
var oldest_time = new Date().getTime();
|
|
|
|
for(var key in this.cache){
|
|
|
|
var time = this.access_time[key];
|
|
|
|
if(time <= oldest_time){
|
|
|
|
oldest_time = time;
|
|
|
|
oldest_key = key;
|
2012-08-16 15:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-06 17:15:32 +00:00
|
|
|
if(oldestKey){
|
|
|
|
delete this.cache[oldest_key];
|
|
|
|
delete this.access_time[oldest_key];
|
2012-08-16 15:02:13 +00:00
|
|
|
}
|
|
|
|
this.size--;
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 17:15:32 +00:00
|
|
|
return node;
|
|
|
|
},
|
|
|
|
get_node: function(key){
|
|
|
|
var cached = this.cache[key];
|
|
|
|
if(cached){
|
|
|
|
this.access_time[key] = new Date().getTime();
|
|
|
|
}
|
|
|
|
return cached;
|
2012-08-16 15:02:13 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-07-03 11:47:41 +00:00
|
|
|
module.NumpadWidget = module.PosBaseWidget.extend({
|
2012-05-11 16:02:23 +00:00
|
|
|
template:'NumpadWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.state = new module.NumpadState();
|
2013-12-02 16:21:44 +00:00
|
|
|
window.numpadstate = this.state;
|
|
|
|
var self = this;
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.state.bind('change:mode', this.changedMode, this);
|
|
|
|
this.changedMode();
|
2013-09-05 13:31:59 +00:00
|
|
|
this.$el.find('.numpad-backspace').click(_.bind(this.clickDeleteLastChar, this));
|
|
|
|
this.$el.find('.numpad-minus').click(_.bind(this.clickSwitchSign, this));
|
|
|
|
this.$el.find('.number-char').click(_.bind(this.clickAppendNewChar, this));
|
|
|
|
this.$el.find('.mode-button').click(_.bind(this.clickChangeMode, this));
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
clickDeleteLastChar: function() {
|
|
|
|
return this.state.deleteLastChar();
|
|
|
|
},
|
|
|
|
clickSwitchSign: function() {
|
|
|
|
return this.state.switchSign();
|
|
|
|
},
|
|
|
|
clickAppendNewChar: function(event) {
|
|
|
|
var newChar;
|
|
|
|
newChar = event.currentTarget.innerText || event.currentTarget.textContent;
|
|
|
|
return this.state.appendNewChar(newChar);
|
|
|
|
},
|
|
|
|
clickChangeMode: function(event) {
|
|
|
|
var newMode = event.currentTarget.attributes['data-mode'].nodeValue;
|
|
|
|
return this.state.changeMode(newMode);
|
|
|
|
},
|
|
|
|
changedMode: function() {
|
|
|
|
var mode = this.state.get('mode');
|
|
|
|
$('.selected-mode').removeClass('selected-mode');
|
2012-08-24 18:27:43 +00:00
|
|
|
$(_.str.sprintf('.mode-button[data-mode="%s"]', mode), this.$el).addClass('selected-mode');
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
});
|
2012-05-21 16:57:21 +00:00
|
|
|
|
2013-12-16 14:35:59 +00:00
|
|
|
// The paypad allows to select the payment method (cashregisters)
|
2012-05-21 16:57:21 +00:00
|
|
|
// used to pay the order.
|
|
|
|
module.PaypadWidget = module.PosBaseWidget.extend({
|
2012-05-11 16:02:23 +00:00
|
|
|
template: 'PaypadWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-21 16:57:21 +00:00
|
|
|
var self = this;
|
2012-05-16 13:01:42 +00:00
|
|
|
this._super();
|
2012-05-21 16:57:21 +00:00
|
|
|
|
2013-12-16 14:35:59 +00:00
|
|
|
_.each(this.pos.cashregisters,function(cashregister) {
|
2012-05-21 16:57:21 +00:00
|
|
|
var button = new module.PaypadButtonWidget(self,{
|
|
|
|
pos: self.pos,
|
|
|
|
pos_widget : self.pos_widget,
|
2013-12-16 14:35:59 +00:00
|
|
|
cashregister: cashregister,
|
2012-05-11 16:02:23 +00:00
|
|
|
});
|
2012-08-24 18:27:43 +00:00
|
|
|
button.appendTo(self.$el);
|
2012-05-21 16:57:21 +00:00
|
|
|
});
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
module.PaypadButtonWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'PaypadButtonWidget',
|
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent, options);
|
2013-12-16 14:35:59 +00:00
|
|
|
this.cashregister = options.cashregister;
|
2012-05-21 16:57:21 +00:00
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-21 16:57:21 +00:00
|
|
|
var self = this;
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super();
|
2012-05-21 16:57:21 +00:00
|
|
|
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.click(function(){
|
2012-05-21 16:57:21 +00:00
|
|
|
if (self.pos.get('selectedOrder').get('screen') === 'receipt'){ //TODO Why ?
|
2012-07-10 10:15:15 +00:00
|
|
|
console.warn('TODO should not get there...?');
|
2012-05-21 16:57:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-12-16 14:35:59 +00:00
|
|
|
self.pos.get('selectedOrder').addPaymentline(self.cashregister);
|
2012-05-21 16:57:21 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('payment');
|
|
|
|
});
|
2012-05-11 16:02:23 +00:00
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
2012-04-25 14:55:55 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
module.OrderWidget = module.PosBaseWidget.extend({
|
|
|
|
template:'OrderWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
2013-12-02 16:21:44 +00:00
|
|
|
var self = this;
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super(parent,options);
|
2013-12-02 16:21:44 +00:00
|
|
|
this.editable = false;
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos.bind('change:selectedOrder', this.change_selected_order, this);
|
2013-12-02 16:21:44 +00:00
|
|
|
this.line_click_handler = function(event){
|
|
|
|
if(!self.editable){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.pos.get('selectedOrder').selectLine(this.orderline);
|
|
|
|
self.pos_widget.numpad.state.reset();
|
|
|
|
};
|
2014-06-13 14:19:05 +00:00
|
|
|
this.client_change_handler = function(event){
|
|
|
|
self.update_summary();
|
|
|
|
}
|
|
|
|
this.bind_order_events();
|
2013-12-02 16:21:44 +00:00
|
|
|
},
|
|
|
|
enable_numpad: function(){
|
|
|
|
this.disable_numpad(); //ensure we don't register the callbacks twice
|
|
|
|
this.numpad_state = this.pos_widget.numpad.state;
|
|
|
|
if(this.numpad_state){
|
|
|
|
this.numpad_state.reset();
|
|
|
|
this.numpad_state.bind('set_value', this.set_value, this);
|
|
|
|
}
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2013-12-02 16:21:44 +00:00
|
|
|
disable_numpad: function(){
|
|
|
|
if(this.numpad_state){
|
|
|
|
this.numpad_state.unbind('set_value', this.set_value);
|
|
|
|
this.numpad_state.reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_editable: function(editable){
|
|
|
|
this.editable = editable;
|
|
|
|
if(editable){
|
|
|
|
this.enable_numpad();
|
|
|
|
}else{
|
|
|
|
this.disable_numpad();
|
|
|
|
this.pos.get('selectedOrder').deselectLine();
|
|
|
|
}
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
set_value: function(val) {
|
2013-05-23 07:06:24 +00:00
|
|
|
var order = this.pos.get('selectedOrder');
|
2013-12-02 16:21:44 +00:00
|
|
|
if (this.editable && order.getSelectedLine()) {
|
|
|
|
var mode = this.numpad_state.get('mode');
|
2012-07-03 11:47:41 +00:00
|
|
|
if( mode === 'quantity'){
|
|
|
|
order.getSelectedLine().set_quantity(val);
|
|
|
|
}else if( mode === 'discount'){
|
|
|
|
order.getSelectedLine().set_discount(val);
|
2012-10-15 07:19:01 +00:00
|
|
|
}else if( mode === 'price'){
|
2013-01-22 13:18:01 +00:00
|
|
|
order.getSelectedLine().set_unit_price(val);
|
2012-07-03 11:47:41 +00:00
|
|
|
}
|
2013-05-23 07:06:24 +00:00
|
|
|
}
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
change_selected_order: function() {
|
2014-06-13 14:19:05 +00:00
|
|
|
this.bind_order_events();
|
2012-04-24 16:25:46 +00:00
|
|
|
this.renderElement();
|
|
|
|
},
|
2014-06-13 14:19:05 +00:00
|
|
|
bind_order_events: function() {
|
|
|
|
|
|
|
|
var order = this.pos.get('selectedOrder');
|
|
|
|
order.unbind('change:client', this.client_change_handler);
|
|
|
|
order.bind('change:client', this.client_change_handler);
|
|
|
|
|
|
|
|
var lines = order.get('orderLines');
|
2013-12-02 16:21:44 +00:00
|
|
|
lines.unbind();
|
|
|
|
lines.bind('add', function(){
|
|
|
|
this.numpad_state.reset();
|
|
|
|
this.renderElement(true);
|
|
|
|
},this);
|
|
|
|
lines.bind('remove', function(line){
|
|
|
|
this.remove_orderline(line);
|
|
|
|
this.numpad_state.reset();
|
|
|
|
this.update_summary();
|
|
|
|
},this);
|
|
|
|
lines.bind('change', function(line){
|
|
|
|
this.rerender_orderline(line);
|
|
|
|
this.update_summary();
|
|
|
|
},this);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2013-12-02 16:21:44 +00:00
|
|
|
render_orderline: function(orderline){
|
|
|
|
var el_str = openerp.qweb.render('Orderline',{widget:this, line:orderline});
|
|
|
|
var el_node = document.createElement('div');
|
|
|
|
el_node.innerHTML = _.str.trim(el_str);
|
|
|
|
el_node = el_node.childNodes[0];
|
|
|
|
el_node.orderline = orderline;
|
|
|
|
el_node.addEventListener('click',this.line_click_handler);
|
|
|
|
|
|
|
|
orderline.node = el_node;
|
|
|
|
return el_node;
|
|
|
|
},
|
|
|
|
remove_orderline: function(order_line){
|
|
|
|
if(this.pos.get('selectedOrder').get('orderLines').length === 0){
|
|
|
|
this.renderElement();
|
|
|
|
}else{
|
|
|
|
order_line.node.parentNode.removeChild(order_line.node);
|
2013-11-27 14:44:27 +00:00
|
|
|
}
|
2013-12-02 16:21:44 +00:00
|
|
|
},
|
|
|
|
rerender_orderline: function(order_line){
|
|
|
|
var node = order_line.node;
|
|
|
|
var replacement_line = this.render_orderline(order_line);
|
|
|
|
node.parentNode.replaceChild(replacement_line,node);
|
|
|
|
},
|
2013-12-04 17:21:22 +00:00
|
|
|
// overriding the openerp framework replace method for performance reasons
|
2013-12-02 16:21:44 +00:00
|
|
|
replace: function($target){
|
|
|
|
this.renderElement();
|
|
|
|
var target = $target[0];
|
|
|
|
target.parentNode.replaceChild(this.el,target);
|
|
|
|
},
|
|
|
|
renderElement: function(scrollbottom){
|
|
|
|
this.pos_widget.numpad.state.reset();
|
2012-07-12 17:00:13 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
var order = this.pos.get('selectedOrder');
|
|
|
|
var orderlines = order.get('orderLines').models;
|
|
|
|
|
|
|
|
var el_str = openerp.qweb.render('OrderWidget',{widget:this, order:order, orderlines:orderlines});
|
2014-06-13 14:19:05 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
var el_node = document.createElement('div');
|
|
|
|
el_node.innerHTML = _.str.trim(el_str);
|
|
|
|
el_node = el_node.childNodes[0];
|
|
|
|
|
2014-06-13 14:19:05 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
var list_container = el_node.querySelector('.orderlines');
|
|
|
|
for(var i = 0, len = orderlines.length; i < len; i++){
|
|
|
|
var orderline = this.render_orderline(orderlines[i]);
|
|
|
|
list_container.appendChild(orderline);
|
2013-01-14 15:25:33 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
if(this.el && this.el.parentNode){
|
|
|
|
this.el.parentNode.replaceChild(el_node,this.el);
|
|
|
|
}
|
|
|
|
this.el = el_node;
|
2012-06-28 12:38:25 +00:00
|
|
|
this.update_summary();
|
2013-10-09 12:51:28 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
if(scrollbottom){
|
|
|
|
this.el.querySelector('.order-scroller').scrollTop = 100 * orderlines.length;
|
2013-10-09 12:51:28 +00:00
|
|
|
}
|
2012-06-28 12:38:25 +00:00
|
|
|
},
|
|
|
|
update_summary: function(){
|
|
|
|
var order = this.pos.get('selectedOrder');
|
2013-01-22 13:18:01 +00:00
|
|
|
var total = order ? order.getTotalTaxIncluded() : 0;
|
|
|
|
var taxes = order ? total - order.getTotalTaxExcluded() : 0;
|
2013-12-02 16:21:44 +00:00
|
|
|
|
2014-02-07 16:16:47 +00:00
|
|
|
this.el.querySelector('.summary .total > .value').textContent = this.format_currency(total);
|
|
|
|
this.el.querySelector('.summary .total .subentry .value').textContent = this.format_currency(taxes);
|
2014-06-13 14:19:05 +00:00
|
|
|
|
2012-07-12 17:00:13 +00:00
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
module.OrderButtonWidget = module.PosBaseWidget.extend({
|
|
|
|
template:'OrderButtonWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options) {
|
2012-05-14 14:03:40 +00:00
|
|
|
this._super(parent,options);
|
2012-11-21 11:26:44 +00:00
|
|
|
var self = this;
|
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
this.order = options.order;
|
2013-09-17 10:14:20 +00:00
|
|
|
this.order.bind('destroy',this.destroy, this );
|
|
|
|
this.order.bind('change', this.renderElement, this );
|
|
|
|
this.pos.bind('change:selectedOrder', this.renderElement,this );
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-06-25 10:01:55 +00:00
|
|
|
renderElement:function(){
|
2014-06-13 14:19:05 +00:00
|
|
|
this.selected = ( this.pos.get('selectedOrder') === this.order )
|
2012-06-25 10:01:55 +00:00
|
|
|
this._super();
|
2013-09-17 10:14:20 +00:00
|
|
|
var self = this;
|
|
|
|
this.$el.click(function(){
|
2014-06-13 14:19:05 +00:00
|
|
|
if( self.pos.get('selectedOrder') === self.order ){
|
|
|
|
var ss = self.pos.pos_widget.screen_selector;
|
|
|
|
if(ss.get_current_screen() === 'clientlist'){
|
|
|
|
ss.back();
|
|
|
|
}else{
|
|
|
|
ss.set_current_screen('clientlist');
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
self.selectOrder();
|
|
|
|
}
|
2013-09-17 10:14:20 +00:00
|
|
|
});
|
2014-06-13 14:19:05 +00:00
|
|
|
if( this.selected){
|
2013-12-05 17:53:25 +00:00
|
|
|
this.$el.addClass('selected');
|
2013-09-05 10:43:57 +00:00
|
|
|
}
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
|
|
|
selectOrder: function(event) {
|
|
|
|
this.pos.set({
|
|
|
|
selectedOrder: this.order
|
|
|
|
});
|
|
|
|
},
|
2013-09-17 10:14:20 +00:00
|
|
|
destroy: function(){
|
|
|
|
this.order.unbind('destroy', this.destroy, this);
|
|
|
|
this.order.unbind('change', this.renderElement, this);
|
|
|
|
this.pos.unbind('change:selectedOrder', this.renderElement, this);
|
|
|
|
this._super();
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ActionButtonWidget = instance.web.Widget.extend({
|
2012-05-14 14:03:40 +00:00
|
|
|
template:'ActionButtonWidget',
|
2012-07-19 15:25:19 +00:00
|
|
|
icon_template:'ActionButtonWidgetWithIcon',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent, options);
|
|
|
|
this.label = options.label || 'button';
|
|
|
|
this.rightalign = options.rightalign || false;
|
|
|
|
this.click_action = options.click;
|
2012-08-31 14:31:59 +00:00
|
|
|
this.disabled = options.disabled || false;
|
2012-05-02 15:30:00 +00:00
|
|
|
if(options.icon){
|
|
|
|
this.icon = options.icon;
|
2012-07-19 15:25:19 +00:00
|
|
|
this.template = this.icon_template;
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
2012-08-31 14:31:59 +00:00
|
|
|
set_disabled: function(disabled){
|
|
|
|
if(this.disabled != disabled){
|
|
|
|
this.disabled = !!disabled;
|
|
|
|
this.renderElement();
|
|
|
|
}
|
|
|
|
},
|
2012-06-25 10:01:55 +00:00
|
|
|
renderElement: function(){
|
|
|
|
this._super();
|
2012-08-31 14:31:59 +00:00
|
|
|
if(this.click_action && !this.disabled){
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.click(_.bind(this.click_action, this));
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-04 12:24:48 +00:00
|
|
|
module.ActionBarWidget = instance.web.Widget.extend({
|
|
|
|
template:'ActionBarWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent,options);
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list = [];
|
2012-08-31 14:31:59 +00:00
|
|
|
this.buttons = {};
|
2012-06-11 14:04:41 +00:00
|
|
|
this.visibility = {};
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-06-11 15:29:29 +00:00
|
|
|
set_element_visible: function(element, visible, action){
|
|
|
|
if(visible != this.visibility[element]){
|
2012-08-31 14:31:59 +00:00
|
|
|
this.visibility[element] = !!visible;
|
2012-06-11 14:04:41 +00:00
|
|
|
if(visible){
|
2013-09-17 10:14:20 +00:00
|
|
|
this.$('.'+element).removeClass('oe_hidden');
|
2012-06-11 14:04:41 +00:00
|
|
|
}else{
|
2013-09-17 10:14:20 +00:00
|
|
|
this.$('.'+element).addClass('oe_hidden');
|
2012-06-11 14:04:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(visible && action){
|
2012-08-31 14:31:59 +00:00
|
|
|
this.action[element] = action;
|
2012-06-11 15:29:29 +00:00
|
|
|
this.$('.'+element).off('click').click(action);
|
2012-06-11 14:04:41 +00:00
|
|
|
}
|
|
|
|
},
|
2012-08-31 14:31:59 +00:00
|
|
|
set_button_disabled: function(name, disabled){
|
|
|
|
var b = this.buttons[name];
|
|
|
|
if(b){
|
|
|
|
b.set_disabled(disabled);
|
|
|
|
}
|
|
|
|
},
|
2012-05-03 16:27:46 +00:00
|
|
|
destroy_buttons:function(){
|
|
|
|
for(var i = 0; i < this.button_list.length; i++){
|
|
|
|
this.button_list[i].destroy();
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list = [];
|
2012-08-31 14:31:59 +00:00
|
|
|
this.buttons = {};
|
2012-05-02 15:30:00 +00:00
|
|
|
return this;
|
|
|
|
},
|
2012-07-19 15:25:19 +00:00
|
|
|
get_button_count: function(){
|
|
|
|
return this.button_list.length;
|
|
|
|
},
|
2012-05-03 16:27:46 +00:00
|
|
|
add_new_button: function(button_options){
|
2012-07-19 15:25:19 +00:00
|
|
|
var button = new module.ActionButtonWidget(this,button_options);
|
|
|
|
this.button_list.push(button);
|
2012-08-31 14:31:59 +00:00
|
|
|
if(button_options.name){
|
2012-08-31 14:56:06 +00:00
|
|
|
this.buttons[button_options.name] = button;
|
2012-08-31 14:31:59 +00:00
|
|
|
}
|
2012-07-30 15:41:43 +00:00
|
|
|
button.appendTo(this.$('.pos-actionbar-button-list'));
|
2012-07-19 15:25:19 +00:00
|
|
|
return button;
|
|
|
|
},
|
|
|
|
show:function(){
|
2013-09-17 10:14:20 +00:00
|
|
|
this.$el.removeClass('oe_hidden');
|
2012-07-19 15:25:19 +00:00
|
|
|
},
|
|
|
|
hide:function(){
|
2013-09-17 10:14:20 +00:00
|
|
|
this.$el.addClass('oe_hidden');
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
});
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
module.ProductCategoriesWidget = module.PosBaseWidget.extend({
|
2012-05-29 16:39:44 +00:00
|
|
|
template: 'ProductCategoriesWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
var self = this;
|
2012-05-29 13:31:41 +00:00
|
|
|
this._super(parent,options);
|
2012-06-04 11:52:44 +00:00
|
|
|
this.product_type = options.product_type || 'all'; // 'all' | 'weightable'
|
2012-05-29 16:39:44 +00:00
|
|
|
this.onlyWeightable = options.onlyWeightable || false;
|
2012-05-29 14:00:08 +00:00
|
|
|
this.category = this.pos.root_category;
|
2012-05-29 13:31:41 +00:00
|
|
|
this.breadcrumb = [];
|
2012-05-29 14:00:08 +00:00
|
|
|
this.subcategories = [];
|
2013-12-02 16:21:44 +00:00
|
|
|
this.product_list_widget = options.product_list_widget || null;
|
2014-01-06 17:15:32 +00:00
|
|
|
this.category_cache = new module.DomCache();
|
2012-05-29 14:00:08 +00:00
|
|
|
this.set_category();
|
2013-12-05 17:53:25 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
this.switch_category_handler = function(event){
|
|
|
|
self.set_category(self.pos.db.get_category_by_id(Number(this.dataset['categoryId'])));
|
|
|
|
self.renderElement();
|
|
|
|
};
|
2013-12-05 17:53:25 +00:00
|
|
|
|
|
|
|
this.clear_search_handler = function(event){
|
|
|
|
self.clear_search();
|
|
|
|
};
|
|
|
|
|
|
|
|
var search_timeout = null;
|
|
|
|
this.search_handler = function(event){
|
|
|
|
clearTimeout(search_timeout);
|
|
|
|
|
|
|
|
var query = this.value;
|
|
|
|
|
|
|
|
search_timeout = setTimeout(function(){
|
|
|
|
self.perform_search(self.category, query, event.which === 13);
|
|
|
|
},70);
|
|
|
|
};
|
2012-05-29 13:31:41 +00:00
|
|
|
},
|
2012-05-29 16:39:44 +00:00
|
|
|
|
|
|
|
// changes the category. if undefined, sets to root category
|
2012-05-29 13:31:41 +00:00
|
|
|
set_category : function(category){
|
2012-08-09 17:21:13 +00:00
|
|
|
var db = this.pos.db;
|
2012-05-29 13:31:41 +00:00
|
|
|
if(!category){
|
2012-08-09 17:21:13 +00:00
|
|
|
this.category = db.get_category_by_id(db.root_category_id);
|
2012-05-29 13:31:41 +00:00
|
|
|
}else{
|
2012-05-29 14:00:08 +00:00
|
|
|
this.category = category;
|
|
|
|
}
|
2012-05-29 16:39:44 +00:00
|
|
|
this.breadcrumb = [];
|
2012-08-09 17:21:13 +00:00
|
|
|
var ancestors_ids = db.get_category_ancestors_ids(this.category.id);
|
|
|
|
for(var i = 1; i < ancestors_ids.length; i++){
|
|
|
|
this.breadcrumb.push(db.get_category_by_id(ancestors_ids[i]));
|
2012-05-29 16:39:44 +00:00
|
|
|
}
|
2012-08-09 17:21:13 +00:00
|
|
|
if(this.category.id !== db.root_category_id){
|
2012-05-29 16:39:44 +00:00
|
|
|
this.breadcrumb.push(this.category);
|
|
|
|
}
|
2012-08-09 17:21:13 +00:00
|
|
|
this.subcategories = db.get_category_by_id(db.get_category_childs_ids(this.category.id));
|
2012-05-29 14:00:08 +00:00
|
|
|
},
|
2012-05-29 16:39:44 +00:00
|
|
|
|
2012-08-17 14:24:15 +00:00
|
|
|
get_image_url: function(category){
|
2014-05-27 07:42:52 +00:00
|
|
|
return window.location.origin + '/web/binary/image?model=pos.category&field=image_medium&id='+category.id;
|
2013-12-02 16:21:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render_category: function( category, with_image ){
|
2014-01-06 17:15:32 +00:00
|
|
|
var cached = this.category_cache.get_node(category.id);
|
|
|
|
if(!cached){
|
2013-12-02 16:21:44 +00:00
|
|
|
if(with_image){
|
|
|
|
var image_url = this.get_image_url(category);
|
|
|
|
var category_html = QWeb.render('CategoryButton',{
|
|
|
|
widget: this,
|
|
|
|
category: category,
|
2014-01-06 17:15:32 +00:00
|
|
|
image_url: this.get_image_url(category),
|
2013-12-02 16:21:44 +00:00
|
|
|
});
|
|
|
|
category_html = _.str.trim(category_html);
|
|
|
|
var category_node = document.createElement('div');
|
|
|
|
category_node.innerHTML = category_html;
|
|
|
|
category_node = category_node.childNodes[0];
|
|
|
|
}else{
|
|
|
|
var category_html = QWeb.render('CategorySimpleButton',{
|
|
|
|
widget: this,
|
|
|
|
category: category,
|
|
|
|
});
|
|
|
|
category_html = _.str.trim(category_html);
|
|
|
|
var category_node = document.createElement('div');
|
|
|
|
category_node.innerHTML = category_html;
|
|
|
|
category_node = category_node.childNodes[0];
|
|
|
|
}
|
2014-01-06 17:15:32 +00:00
|
|
|
this.category_cache.cache_node(category.id,category_node);
|
|
|
|
return category_node;
|
2013-12-02 16:21:44 +00:00
|
|
|
}
|
2014-01-06 17:15:32 +00:00
|
|
|
return cached;
|
2013-12-02 16:21:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
replace: function($target){
|
|
|
|
this.renderElement();
|
|
|
|
var target = $target[0];
|
|
|
|
target.parentNode.replaceChild(this.el,target);
|
2012-08-17 14:24:15 +00:00
|
|
|
},
|
|
|
|
|
2012-05-29 13:31:41 +00:00
|
|
|
renderElement: function(){
|
|
|
|
var self = this;
|
2013-12-02 16:21:44 +00:00
|
|
|
|
|
|
|
var el_str = openerp.qweb.render(this.template, {widget: this});
|
|
|
|
var el_node = document.createElement('div');
|
|
|
|
el_node.innerHTML = el_str;
|
|
|
|
el_node = el_node.childNodes[1];
|
|
|
|
|
|
|
|
if(this.el && this.el.parentNode){
|
|
|
|
this.el.parentNode.replaceChild(el_node,this.el);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.el = el_node;
|
2012-07-17 13:20:48 +00:00
|
|
|
|
|
|
|
var hasimages = false; //if none of the subcategories have images, we don't display buttons with icons
|
2013-12-02 16:21:44 +00:00
|
|
|
for(var i = 0; i < this.subcategories.length; i++){
|
|
|
|
if(this.subcategories[i].image){
|
2012-07-17 13:20:48 +00:00
|
|
|
hasimages = true;
|
2013-12-02 16:21:44 +00:00
|
|
|
break;
|
2012-07-17 13:20:48 +00:00
|
|
|
}
|
2013-12-02 16:21:44 +00:00
|
|
|
}
|
2012-07-17 13:20:48 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
var list_container = el_node.querySelector('.category-list');
|
|
|
|
for(var i = 0, len = this.subcategories.length; i < len; i++){
|
|
|
|
list_container.appendChild(this.render_category(this.subcategories[i],hasimages));
|
|
|
|
};
|
|
|
|
|
|
|
|
var buttons = el_node.querySelectorAll('.js-category-switch');
|
|
|
|
for(var i = 0; i < buttons.length; i++){
|
|
|
|
buttons[i].addEventListener('click',this.switch_category_handler);
|
|
|
|
}
|
2012-07-09 15:53:51 +00:00
|
|
|
|
2013-12-05 17:53:25 +00:00
|
|
|
var products = this.pos.db.get_product_by_category(this.category.id);
|
|
|
|
this.product_list_widget.set_product_list(products);
|
2013-09-20 09:47:34 +00:00
|
|
|
|
2013-12-05 17:53:25 +00:00
|
|
|
this.el.querySelector('.searchbox input').addEventListener('keyup',this.search_handler);
|
|
|
|
|
|
|
|
this.el.querySelector('.search-clear').addEventListener('click',this.clear_search_handler);
|
2013-09-20 09:47:34 +00:00
|
|
|
|
2013-12-16 14:35:59 +00:00
|
|
|
if(this.pos.config.iface_vkeyboard && this.pos_widget.onscreen_keyboard){
|
2013-12-16 18:20:59 +00:00
|
|
|
this.pos_widget.onscreen_keyboard.connect($(this.el.querySelector('.searchbox input')));
|
2013-09-12 15:13:34 +00:00
|
|
|
}
|
2012-05-29 13:31:41 +00:00
|
|
|
},
|
2013-05-23 06:02:23 +00:00
|
|
|
|
2012-05-29 16:39:44 +00:00
|
|
|
// resets the current category to the root category
|
2012-05-29 14:00:08 +00:00
|
|
|
reset_category: function(){
|
|
|
|
this.set_category();
|
2012-05-29 16:39:44 +00:00
|
|
|
this.renderElement();
|
2013-09-20 09:47:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// empties the content of the search box
|
|
|
|
clear_search: function(){
|
|
|
|
var products = this.pos.db.get_product_by_category(this.category.id);
|
2013-12-02 16:21:44 +00:00
|
|
|
this.product_list_widget.set_product_list(products);
|
2013-12-05 17:53:25 +00:00
|
|
|
var input = this.el.querySelector('.searchbox input');
|
|
|
|
input.value = '';
|
|
|
|
input.focus();
|
|
|
|
},
|
|
|
|
perform_search: function(category, query, buy_result){
|
|
|
|
if(query){
|
|
|
|
var products = this.pos.db.search_product_in_category(category.id,query)
|
|
|
|
if(buy_result && products.length === 1){
|
|
|
|
this.pos.get('selectedOrder').addProduct(products[0]);
|
|
|
|
this.clear_search();
|
|
|
|
}else{
|
|
|
|
this.product_list_widget.set_product_list(products);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var products = this.pos.db.get_product_by_category(this.category.id);
|
|
|
|
this.product_list_widget.set_product_list(products);
|
|
|
|
}
|
2012-05-29 14:00:08 +00:00
|
|
|
},
|
2012-05-29 16:39:44 +00:00
|
|
|
|
2012-05-29 13:31:41 +00:00
|
|
|
});
|
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
module.ProductListWidget = module.PosBaseWidget.extend({
|
2012-05-02 15:30:00 +00:00
|
|
|
template:'ProductListWidget',
|
|
|
|
init: function(parent, options) {
|
2012-05-29 16:39:44 +00:00
|
|
|
var self = this;
|
2012-05-29 13:31:41 +00:00
|
|
|
this._super(parent,options);
|
2012-05-02 15:30:00 +00:00
|
|
|
this.model = options.model;
|
2013-01-14 15:25:33 +00:00
|
|
|
this.productwidgets = [];
|
2012-05-29 16:39:44 +00:00
|
|
|
this.weight = options.weight || 0;
|
|
|
|
this.show_scale = options.show_scale || false;
|
2012-05-08 12:37:01 +00:00
|
|
|
this.next_screen = options.next_screen || false;
|
2012-05-29 16:39:44 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
this.click_product_handler = function(event){
|
|
|
|
var product = self.pos.db.get_product_by_id(this.dataset['productId']);
|
|
|
|
options.click_product_action(product);
|
|
|
|
};
|
2013-10-09 10:13:25 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
this.product_list = options.product_list || [];
|
2014-01-06 17:15:32 +00:00
|
|
|
this.product_cache = new module.DomCache();
|
2013-12-02 16:21:44 +00:00
|
|
|
},
|
|
|
|
set_product_list: function(product_list){
|
|
|
|
this.product_list = product_list;
|
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
get_product_image_url: function(product){
|
|
|
|
return window.location.origin + '/web/binary/image?model=product.product&field=image_medium&id='+product.id;
|
|
|
|
},
|
|
|
|
replace: function($target){
|
|
|
|
this.renderElement();
|
|
|
|
var target = $target[0];
|
|
|
|
target.parentNode.replaceChild(this.el,target);
|
|
|
|
},
|
2013-10-09 10:13:25 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
render_product: function(product){
|
2014-01-06 17:15:32 +00:00
|
|
|
var cached = this.product_cache.get_node(product.id);
|
|
|
|
if(!cached){
|
2013-12-02 16:21:44 +00:00
|
|
|
var image_url = this.get_product_image_url(product);
|
|
|
|
var product_html = QWeb.render('Product',{
|
|
|
|
widget: this,
|
|
|
|
product: product,
|
2014-01-06 17:15:32 +00:00
|
|
|
image_url: this.get_product_image_url(product),
|
2013-12-02 16:21:44 +00:00
|
|
|
});
|
|
|
|
var product_node = document.createElement('div');
|
|
|
|
product_node.innerHTML = product_html;
|
|
|
|
product_node = product_node.childNodes[1];
|
2014-01-06 17:15:32 +00:00
|
|
|
this.product_cache.cache_node(product.id,product_node);
|
|
|
|
return product_node;
|
2013-12-02 16:21:44 +00:00
|
|
|
}
|
2014-01-06 17:15:32 +00:00
|
|
|
return cached;
|
2013-12-02 16:21:44 +00:00
|
|
|
},
|
2013-11-27 19:17:50 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
renderElement: function() {
|
|
|
|
var self = this;
|
2013-11-27 19:17:50 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
// this._super()
|
|
|
|
var el_str = openerp.qweb.render(this.template, {widget: this});
|
|
|
|
var el_node = document.createElement('div');
|
|
|
|
el_node.innerHTML = el_str;
|
|
|
|
el_node = el_node.childNodes[1];
|
2013-11-27 19:17:50 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
if(this.el && this.el.parentNode){
|
|
|
|
this.el.parentNode.replaceChild(el_node,this.el);
|
|
|
|
}
|
|
|
|
this.el = el_node;
|
2013-09-17 12:29:29 +00:00
|
|
|
|
2013-12-02 16:21:44 +00:00
|
|
|
var list_container = el_node.querySelector('.product-list');
|
|
|
|
for(var i = 0, len = this.product_list.length; i < len; i++){
|
|
|
|
var product_node = this.render_product(this.product_list[i]);
|
|
|
|
product_node.addEventListener('click',this.click_product_handler);
|
|
|
|
list_container.appendChild(product_node);
|
|
|
|
};
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-07-03 11:47:41 +00:00
|
|
|
module.UsernameWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'UsernameWidget',
|
|
|
|
init: function(parent, options){
|
|
|
|
var options = options || {};
|
|
|
|
this._super(parent,options);
|
|
|
|
this.mode = options.mode || 'cashier';
|
|
|
|
},
|
|
|
|
set_user_mode: function(mode){
|
|
|
|
this.mode = mode;
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
refresh: function(){
|
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
get_name: function(){
|
|
|
|
var user;
|
|
|
|
if(this.mode === 'cashier'){
|
2013-12-16 14:35:59 +00:00
|
|
|
user = this.pos.cashier || this.pos.user;
|
2012-07-03 11:47:41 +00:00
|
|
|
}else{
|
2013-12-16 14:35:59 +00:00
|
|
|
user = this.pos.get('selectedOrder').get_client() || this.pos.user;
|
2012-07-03 11:47:41 +00:00
|
|
|
}
|
|
|
|
if(user){
|
|
|
|
return user.name;
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-07-19 15:25:19 +00:00
|
|
|
module.HeaderButtonWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'HeaderButtonWidget',
|
|
|
|
init: function(parent, options){
|
|
|
|
options = options || {};
|
|
|
|
this._super(parent, options);
|
|
|
|
this.action = options.action;
|
|
|
|
this.label = options.label;
|
|
|
|
},
|
|
|
|
renderElement: function(){
|
|
|
|
var self = this;
|
|
|
|
this._super();
|
|
|
|
if(this.action){
|
2013-09-19 13:12:28 +00:00
|
|
|
this.$el.click(function(){
|
2013-09-23 15:04:31 +00:00
|
|
|
self.action();
|
2013-09-19 13:12:28 +00:00
|
|
|
});
|
2012-07-19 15:25:19 +00:00
|
|
|
}
|
|
|
|
},
|
2013-09-17 10:14:20 +00:00
|
|
|
show: function(){ this.$el.removeClass('oe_hidden'); },
|
|
|
|
hide: function(){ this.$el.addClass('oe_hidden'); },
|
2012-07-19 15:25:19 +00:00
|
|
|
});
|
|
|
|
|
2012-09-12 16:26:53 +00:00
|
|
|
// The debug widget lets the user control and monitor the hardware and software status
|
|
|
|
// without the use of the proxy
|
2012-09-12 16:12:29 +00:00
|
|
|
module.DebugWidget = module.PosBaseWidget.extend({
|
|
|
|
template: "DebugWidget",
|
|
|
|
eans:{
|
2012-09-13 15:09:13 +00:00
|
|
|
admin_badge: '0410100000006',
|
2012-11-21 11:26:44 +00:00
|
|
|
client_badge: '0420200000004',
|
2012-09-12 16:12:29 +00:00
|
|
|
invalid_ean: '1232456',
|
|
|
|
soda_33cl: '5449000000996',
|
|
|
|
oranges_kg: '2100002031410',
|
|
|
|
lemon_price: '2301000001560',
|
|
|
|
unknown_product: '9900000000004',
|
|
|
|
},
|
|
|
|
events:[
|
|
|
|
'open_cashbox',
|
|
|
|
'print_receipt',
|
2014-04-25 12:22:20 +00:00
|
|
|
'scale_read',
|
2012-09-12 16:12:29 +00:00
|
|
|
],
|
|
|
|
minimized: false,
|
2013-12-16 15:57:23 +00:00
|
|
|
init: function(parent,options){
|
|
|
|
this._super(parent,options);
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.minimized = false;
|
|
|
|
|
|
|
|
// for dragging the debug widget around
|
|
|
|
this.dragging = false;
|
2013-12-17 17:22:58 +00:00
|
|
|
this.dragpos = {x:0, y:0};
|
2013-12-16 15:57:23 +00:00
|
|
|
|
2013-12-17 17:22:58 +00:00
|
|
|
function eventpos(event){
|
|
|
|
if(event.touches && event.touches[0]){
|
|
|
|
return {x: event.touches[0].screenX, y: event.touches[0].screenY};
|
|
|
|
}else{
|
|
|
|
return {x: event.screenX, y: event.screenY};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dragend_handler = function(event){
|
2013-12-16 15:57:23 +00:00
|
|
|
self.dragging = false;
|
|
|
|
};
|
2013-12-17 17:22:58 +00:00
|
|
|
this.dragstart_handler = function(event){
|
2013-12-16 15:57:23 +00:00
|
|
|
self.dragging = true;
|
2013-12-17 17:22:58 +00:00
|
|
|
self.dragpos = eventpos(event);
|
2013-12-16 15:57:23 +00:00
|
|
|
};
|
2013-12-17 17:22:58 +00:00
|
|
|
this.dragmove_handler = function(event){
|
2013-12-16 15:57:23 +00:00
|
|
|
if(self.dragging){
|
|
|
|
var top = this.offsetTop;
|
|
|
|
var left = this.offsetLeft;
|
2013-12-17 17:22:58 +00:00
|
|
|
var pos = eventpos(event);
|
|
|
|
var dx = pos.x - self.dragpos.x;
|
|
|
|
var dy = pos.y - self.dragpos.y;
|
2013-12-16 15:57:23 +00:00
|
|
|
|
2013-12-17 17:22:58 +00:00
|
|
|
self.dragpos = pos;
|
2013-12-16 15:57:23 +00:00
|
|
|
|
|
|
|
this.style.right = 'auto';
|
|
|
|
this.style.bottom = 'auto';
|
|
|
|
this.style.left = left + dx + 'px';
|
|
|
|
this.style.top = top + dy + 'px';
|
|
|
|
}
|
2013-12-17 17:22:58 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2013-12-16 15:57:23 +00:00
|
|
|
};
|
|
|
|
},
|
2012-09-12 16:12:29 +00:00
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
|
2013-12-17 17:22:58 +00:00
|
|
|
this.el.addEventListener('mouseleave', this.dragend_handler);
|
|
|
|
this.el.addEventListener('mouseup', this.dragend_handler);
|
|
|
|
this.el.addEventListener('touchend', this.dragend_handler);
|
|
|
|
this.el.addEventListener('touchcancel',this.dragend_handler);
|
|
|
|
this.el.addEventListener('mousedown', this.dragstart_handler);
|
|
|
|
this.el.addEventListener('touchstart', this.dragstart_handler);
|
|
|
|
this.el.addEventListener('mousemove', this.dragmove_handler);
|
|
|
|
this.el.addEventListener('touchmove', this.dragmove_handler);
|
2013-12-16 15:57:23 +00:00
|
|
|
|
2012-09-12 16:12:29 +00:00
|
|
|
this.$('.toggle').click(function(){
|
|
|
|
var content = self.$('.content');
|
|
|
|
var bg = self.$el;
|
|
|
|
if(!self.minimized){
|
|
|
|
content.animate({'height':'0'},200);
|
|
|
|
}else{
|
|
|
|
content.css({'height':'auto'});
|
|
|
|
}
|
|
|
|
self.minimized = !self.minimized;
|
|
|
|
});
|
|
|
|
this.$('.button.set_weight').click(function(){
|
|
|
|
var kg = Number(self.$('input.weight').val());
|
2012-10-02 10:04:20 +00:00
|
|
|
if(!isNaN(kg)){
|
2012-09-12 16:12:29 +00:00
|
|
|
self.pos.proxy.debug_set_weight(kg);
|
|
|
|
}
|
|
|
|
});
|
2012-11-22 13:22:48 +00:00
|
|
|
this.$('.button.reset_weight').click(function(){
|
2013-07-08 14:55:22 +00:00
|
|
|
self.$('input.weight').val('');
|
2012-11-22 13:22:48 +00:00
|
|
|
self.pos.proxy.debug_reset_weight();
|
|
|
|
});
|
2012-09-12 16:12:29 +00:00
|
|
|
this.$('.button.custom_ean').click(function(){
|
|
|
|
var ean = self.pos.barcode_reader.sanitize_ean(self.$('input.ean').val() || '0');
|
|
|
|
self.$('input.ean').val(ean);
|
2014-06-13 14:19:05 +00:00
|
|
|
self.pos.barcode_reader.scan(ean);
|
2013-09-23 14:51:39 +00:00
|
|
|
});
|
|
|
|
this.$('.button.reference').click(function(){
|
2014-06-13 14:19:05 +00:00
|
|
|
self.pos.barcode_reader.scan(self.$('input.ean').val());
|
2012-09-12 16:12:29 +00:00
|
|
|
});
|
|
|
|
_.each(this.eans, function(ean, name){
|
|
|
|
self.$('.button.'+name).click(function(){
|
|
|
|
self.$('input.ean').val(ean);
|
2014-06-13 14:19:05 +00:00
|
|
|
self.pos.barcode_reader.scan(ean);
|
2012-09-12 16:12:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
_.each(this.events, function(name){
|
|
|
|
self.pos.proxy.add_notification(name,function(){
|
2013-05-23 06:02:23 +00:00
|
|
|
self.$('.event.'+name).stop().clearQueue().css({'background-color':'#6CD11D'});
|
2012-09-13 10:46:21 +00:00
|
|
|
self.$('.event.'+name).animate({'background-color':'#1E1E1E'},2000);
|
2012-09-12 16:12:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-09-12 16:26:53 +00:00
|
|
|
// ---------- Main Point of Sale Widget ----------
|
|
|
|
|
2014-01-17 17:58:30 +00:00
|
|
|
module.StatusWidget = module.PosBaseWidget.extend({
|
|
|
|
status: ['connected','connecting','disconnected','warning'],
|
|
|
|
set_status: function(status,msg){
|
2012-09-12 16:26:53 +00:00
|
|
|
var self = this;
|
2014-01-17 17:58:30 +00:00
|
|
|
for(var i = 0; i < this.status.length; i++){
|
|
|
|
this.$('.js_'+this.status[i]).addClass('oe_hidden');
|
|
|
|
}
|
|
|
|
this.$('.js_'+status).removeClass('oe_hidden');
|
2014-01-16 17:28:46 +00:00
|
|
|
|
2014-01-17 17:58:30 +00:00
|
|
|
if(msg){
|
|
|
|
this.$('.js_msg').removeClass('oe_hidden').html(msg);
|
|
|
|
}else{
|
|
|
|
this.$('.js_msg').addClass('oe_hidden').html('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2014-01-16 17:28:46 +00:00
|
|
|
|
2014-01-17 17:58:30 +00:00
|
|
|
// this is used to notify the user that data is being synchronized on the network
|
|
|
|
module.SynchNotificationWidget = module.StatusWidget.extend({
|
|
|
|
template: 'SynchNotificationWidget',
|
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
this.pos.bind('change:synch', function(pos,synch){
|
|
|
|
self.set_status(synch.state, synch.pending);
|
|
|
|
});
|
2013-03-27 10:45:51 +00:00
|
|
|
this.$el.click(function(){
|
2012-09-12 16:26:53 +00:00
|
|
|
self.pos.flush();
|
|
|
|
});
|
|
|
|
},
|
2014-01-17 17:58:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// this is used to notify the user if the pos is connected to the proxy
|
|
|
|
module.ProxyStatusWidget = module.StatusWidget.extend({
|
|
|
|
template: 'ProxyStatusWidget',
|
2014-01-26 21:55:28 +00:00
|
|
|
set_smart_status: function(status){
|
|
|
|
if(status.status === 'connected'){
|
|
|
|
var warning = false;
|
|
|
|
var msg = ''
|
|
|
|
if(this.pos.config.iface_scan_via_proxy){
|
|
|
|
var scanner = status.drivers.scanner ? status.drivers.scanner.status : false;
|
|
|
|
if( scanner != 'connected' && scanner != 'connecting'){
|
|
|
|
warning = true;
|
|
|
|
msg += _t('Scanner');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( this.pos.config.iface_print_via_proxy ||
|
|
|
|
this.pos.config.iface_cashdrawer ){
|
|
|
|
var printer = status.drivers.escpos ? status.drivers.escpos.status : false;
|
|
|
|
if( printer != 'connected' && printer != 'connecting'){
|
|
|
|
warning = true;
|
|
|
|
msg = msg ? msg + ' & ' : msg;
|
|
|
|
msg += _t('Printer');
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 12:22:20 +00:00
|
|
|
if( this.pos.config.iface_electronic_scale ){
|
|
|
|
var scale = status.drivers.scale ? status.drivers.scale.status : false;
|
|
|
|
if( scale != 'connected' && scale != 'connecting' ){
|
|
|
|
warning = true;
|
|
|
|
msg = msg ? msg + ' & ' : msg;
|
|
|
|
msg += _t('Scale');
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 21:55:28 +00:00
|
|
|
msg = msg ? msg + ' ' + _t('Offline') : msg;
|
|
|
|
this.set_status(warning ? 'warning' : 'connected', msg);
|
|
|
|
}else{
|
|
|
|
this.set_status(status.status,'');
|
|
|
|
}
|
|
|
|
},
|
2012-09-12 16:26:53 +00:00
|
|
|
start: function(){
|
|
|
|
var self = this;
|
2014-01-17 17:58:30 +00:00
|
|
|
|
2014-01-27 00:22:03 +00:00
|
|
|
this.set_smart_status(this.pos.proxy.get('status'));
|
2014-01-17 17:58:30 +00:00
|
|
|
|
2014-01-27 00:22:03 +00:00
|
|
|
this.pos.proxy.on('change:status',this,function(eh,status){ //FIXME remove duplicate changes
|
|
|
|
self.set_smart_status(status.newValue);
|
2014-01-17 17:58:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$el.click(function(){
|
|
|
|
self.pos.connect_to_proxy();
|
2012-09-12 16:26:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
// The PosWidget is the main widget that contains all other widgets in the PointOfSale.
|
|
|
|
// It is mainly composed of :
|
|
|
|
// - a header, containing the list of orders
|
2013-05-23 06:02:23 +00:00
|
|
|
// - a leftpane, containing the list of bought products (orderlines)
|
2012-05-11 16:02:23 +00:00
|
|
|
// - a rightpane, containing the screens (see pos_screens.js)
|
|
|
|
// - an actionbar on the bottom, containing various action buttons
|
|
|
|
// - popups
|
|
|
|
// - an onscreen keyboard
|
|
|
|
// a screen_selector which controls the switching between screens and the showing/closing of popups
|
|
|
|
|
|
|
|
module.PosWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'PosWidget',
|
2013-05-23 06:02:23 +00:00
|
|
|
init: function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super(arguments[0],{});
|
2012-11-14 17:00:06 +00:00
|
|
|
|
2014-01-10 17:17:46 +00:00
|
|
|
this.pos = new module.PosModel(this.session,{pos_widget:this});
|
2012-05-21 16:57:21 +00:00
|
|
|
this.pos_widget = this; //So that pos_widget's childs have pos_widget set automatically
|
|
|
|
|
2012-05-04 10:27:37 +00:00
|
|
|
this.numpad_visible = true;
|
|
|
|
this.leftpane_visible = true;
|
|
|
|
this.leftpane_width = '440px';
|
|
|
|
this.cashier_controls_visible = true;
|
2013-09-05 10:43:57 +00:00
|
|
|
|
2013-10-08 15:19:40 +00:00
|
|
|
FastClick.attach(document.body);
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2013-12-17 15:15:50 +00:00
|
|
|
|
|
|
|
disable_rubberbanding: function(){
|
|
|
|
// prevent the pos body from being scrollable.
|
|
|
|
document.body.addEventListener('touchmove',function(event){
|
|
|
|
var node = event.target;
|
|
|
|
while(node){
|
|
|
|
if(node.classList && node.classList.contains('touch-scrollable')){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
},
|
2014-01-10 17:17:46 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
start: function() {
|
2012-04-26 10:05:48 +00:00
|
|
|
var self = this;
|
2012-10-31 10:31:48 +00:00
|
|
|
return self.pos.ready.done(function() {
|
2013-12-05 17:53:25 +00:00
|
|
|
// remove default webclient handlers that induce click delay
|
|
|
|
$(document).off();
|
|
|
|
$(window).off();
|
|
|
|
$('html').off();
|
|
|
|
$('body').off();
|
|
|
|
$(self.$el).parent().off();
|
|
|
|
$('document').off();
|
|
|
|
$('.oe_web_client').off();
|
|
|
|
$('.openerp_webclient_container').off();
|
|
|
|
|
2012-05-25 12:15:39 +00:00
|
|
|
self.build_currency_template();
|
|
|
|
self.renderElement();
|
2013-05-23 06:02:23 +00:00
|
|
|
|
2012-08-09 17:21:13 +00:00
|
|
|
self.$('.neworder-button').click(function(){
|
|
|
|
self.pos.add_new_order();
|
|
|
|
});
|
2013-09-05 10:43:57 +00:00
|
|
|
|
|
|
|
self.$('.deleteorder-button').click(function(){
|
2014-06-13 14:19:05 +00:00
|
|
|
if( !self.pos.get('selectedOrder').is_empty() ){
|
|
|
|
self.screen_selector.show_popup('confirm',{
|
|
|
|
message: _t('Destroy Current Order ?'),
|
|
|
|
comment: _t('You will lose any data associated with the current order'),
|
|
|
|
confirm: function(){
|
|
|
|
self.pos.delete_current_order();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
self.pos.delete_current_order();
|
|
|
|
}
|
2013-09-05 10:43:57 +00:00
|
|
|
});
|
2013-05-23 06:02:23 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
//when a new order is created, add an order button widget
|
2012-05-25 12:15:39 +00:00
|
|
|
self.pos.get('orders').bind('add', function(new_order){
|
2012-05-11 16:02:23 +00:00
|
|
|
var new_order_button = new module.OrderButtonWidget(null, {
|
|
|
|
order: new_order,
|
2012-05-25 12:15:39 +00:00
|
|
|
pos: self.pos
|
2012-05-11 16:02:23 +00:00
|
|
|
});
|
2013-11-05 14:19:03 +00:00
|
|
|
new_order_button.appendTo(this.$('.orders'));
|
2012-05-11 16:02:23 +00:00
|
|
|
new_order_button.selectOrder();
|
2012-05-25 12:15:39 +00:00
|
|
|
}, self);
|
2012-05-11 16:02:23 +00:00
|
|
|
|
2013-09-17 10:14:20 +00:00
|
|
|
self.pos.add_new_order();
|
2012-04-26 10:05:48 +00:00
|
|
|
|
2012-05-25 12:15:39 +00:00
|
|
|
self.build_widgets();
|
2012-04-26 10:05:48 +00:00
|
|
|
|
2013-12-16 14:35:59 +00:00
|
|
|
if(self.pos.config.iface_big_scrollbars){
|
2013-11-06 16:17:23 +00:00
|
|
|
self.$el.addClass('big-scrollbars');
|
|
|
|
}
|
|
|
|
|
2012-07-17 16:25:17 +00:00
|
|
|
self.screen_selector.set_default_screen();
|
|
|
|
|
|
|
|
self.pos.barcode_reader.connect();
|
|
|
|
|
2012-04-26 10:05:48 +00:00
|
|
|
instance.webclient.set_content_full_screen(true);
|
2012-05-16 13:01:42 +00:00
|
|
|
|
2013-12-16 14:35:59 +00:00
|
|
|
if (!self.pos.session) {
|
2012-07-03 11:47:41 +00:00
|
|
|
self.screen_selector.show_popup('error', 'Sorry, we could not create a user session');
|
2013-12-16 14:35:59 +00:00
|
|
|
}else if(!self.pos.config){
|
2012-07-03 11:47:41 +00:00
|
|
|
self.screen_selector.show_popup('error', 'Sorry, we could not find any PoS Configuration for this session');
|
2012-05-09 09:55:55 +00:00
|
|
|
}
|
2013-05-23 06:02:23 +00:00
|
|
|
|
2013-09-17 10:14:20 +00:00
|
|
|
self.$('.loader').animate({opacity:0},1500,'swing',function(){self.$('.loader').addClass('oe_hidden');});
|
2012-05-16 13:01:42 +00:00
|
|
|
|
2013-03-27 12:55:41 +00:00
|
|
|
self.pos.flush();
|
|
|
|
|
2012-10-31 10:31:48 +00:00
|
|
|
}).fail(function(){ // error when loading models data from the backend
|
2012-05-25 12:15:39 +00:00
|
|
|
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_session_opening']], ['res_id'])
|
|
|
|
.pipe( _.bind(function(res){
|
2012-08-14 15:30:53 +00:00
|
|
|
return instance.session.rpc('/web/action/load', {'action_id': res[0]['res_id']})
|
2012-05-25 12:15:39 +00:00
|
|
|
.pipe(_.bind(function(result){
|
|
|
|
var action = result.result;
|
|
|
|
this.do_action(action);
|
|
|
|
}, this));
|
|
|
|
}, self));
|
|
|
|
});
|
2012-04-26 10:05:48 +00:00
|
|
|
},
|
2014-01-10 17:17:46 +00:00
|
|
|
loading_progress: function(fac){
|
|
|
|
this.$('.loader .loader-feedback').removeClass('oe_hidden');
|
|
|
|
this.$('.loader .progress').css({'width': ''+Math.floor(fac*100)+'%'});
|
|
|
|
},
|
|
|
|
loading_message: function(msg,progress){
|
|
|
|
this.$('.loader .loader-feedback').removeClass('oe_hidden');
|
|
|
|
this.$('.loader .message').text(msg);
|
|
|
|
if(typeof progress !== 'undefined'){
|
|
|
|
this.loading_progress(progress);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loading_skip: function(callback){
|
|
|
|
if(callback){
|
|
|
|
this.$('.loader .loader-feedback').removeClass('oe_hidden');
|
|
|
|
this.$('.loader .button.skip').removeClass('oe_hidden');
|
|
|
|
this.$('.loader .button.skip').off('click');
|
|
|
|
this.$('.loader .button.skip').click(callback);
|
|
|
|
}else{
|
|
|
|
this.$('.loader .button.skip').addClass('oe_hidden');
|
|
|
|
}
|
|
|
|
},
|
2012-07-17 16:25:17 +00:00
|
|
|
// This method instantiates all the screens, widgets, etc. If you want to add new screens change the
|
|
|
|
// startup screen, etc, override this method.
|
2012-05-11 16:02:23 +00:00
|
|
|
build_widgets: function() {
|
2012-07-19 15:25:19 +00:00
|
|
|
var self = this;
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2012-05-14 14:31:21 +00:00
|
|
|
// -------- Screens ---------
|
|
|
|
|
2012-07-09 15:53:51 +00:00
|
|
|
this.product_screen = new module.ProductScreenWidget(this,{});
|
2013-11-06 10:32:55 +00:00
|
|
|
this.product_screen.appendTo(this.$('.screens'));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.receipt_screen = new module.ReceiptScreenWidget(this, {});
|
2013-11-06 10:32:55 +00:00
|
|
|
this.receipt_screen.appendTo(this.$('.screens'));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.payment_screen = new module.PaymentScreenWidget(this, {});
|
2013-11-06 10:32:55 +00:00
|
|
|
this.payment_screen.appendTo(this.$('.screens'));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2014-06-13 14:19:05 +00:00
|
|
|
this.clientlist_screen = new module.ClientListScreenWidget(this, {});
|
|
|
|
this.clientlist_screen.appendTo(this.$('.screens'));
|
2012-05-03 16:27:46 +00:00
|
|
|
|
2012-07-09 15:53:51 +00:00
|
|
|
this.scale_screen = new module.ScaleScreenWidget(this,{});
|
2013-11-06 10:32:55 +00:00
|
|
|
this.scale_screen.appendTo(this.$('.screens'));
|
2012-05-03 16:40:32 +00:00
|
|
|
|
2012-05-14 14:31:21 +00:00
|
|
|
|
2014-06-13 14:19:05 +00:00
|
|
|
// -------- Popups ---------
|
2012-05-06 21:34:39 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.error_popup = new module.ErrorPopupWidget(this, {});
|
2013-11-05 14:31:28 +00:00
|
|
|
this.error_popup.appendTo(this.$el);
|
2012-05-07 12:39:32 +00:00
|
|
|
|
2014-06-13 14:19:05 +00:00
|
|
|
this.error_barcode_popup = new module.ErrorBarcodePopupWidget(this, {});
|
|
|
|
this.error_barcode_popup.appendTo(this.$el);
|
2012-05-14 14:31:21 +00:00
|
|
|
|
2012-09-18 13:37:32 +00:00
|
|
|
this.error_session_popup = new module.ErrorSessionPopupWidget(this, {});
|
2013-11-05 14:31:28 +00:00
|
|
|
this.error_session_popup.appendTo(this.$el);
|
2012-05-14 14:31:21 +00:00
|
|
|
|
2012-09-05 16:42:21 +00:00
|
|
|
this.choose_receipt_popup = new module.ChooseReceiptPopupWidget(this, {});
|
2013-11-05 14:31:28 +00:00
|
|
|
this.choose_receipt_popup.appendTo(this.$el);
|
2012-09-05 16:42:21 +00:00
|
|
|
|
2013-04-11 12:07:19 +00:00
|
|
|
this.error_no_client_popup = new module.ErrorNoClientPopupWidget(this, {});
|
2013-11-05 14:31:28 +00:00
|
|
|
this.error_no_client_popup.appendTo(this.$el);
|
2013-04-11 12:07:19 +00:00
|
|
|
|
|
|
|
this.error_invoice_transfer_popup = new module.ErrorInvoiceTransferPopupWidget(this, {});
|
2013-11-05 14:31:28 +00:00
|
|
|
this.error_invoice_transfer_popup.appendTo(this.$el);
|
2013-04-11 12:07:19 +00:00
|
|
|
|
2014-06-13 14:19:05 +00:00
|
|
|
this.confirm_popup = new module.ConfirmPopupWidget(this,{});
|
|
|
|
this.confirm_popup.appendTo(this.$el);
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
// -------- Misc ---------
|
|
|
|
|
2014-01-17 17:58:30 +00:00
|
|
|
this.close_button = new module.HeaderButtonWidget(this,{
|
|
|
|
label: _t('Close'),
|
|
|
|
action: function(){ self.close(); },
|
|
|
|
});
|
|
|
|
this.close_button.appendTo(this.$('.pos-rightheader'));
|
|
|
|
|
2012-07-03 11:47:41 +00:00
|
|
|
this.notification = new module.SynchNotificationWidget(this,{});
|
2013-11-05 14:19:03 +00:00
|
|
|
this.notification.appendTo(this.$('.pos-rightheader'));
|
2012-07-03 11:47:41 +00:00
|
|
|
|
2014-01-17 17:58:30 +00:00
|
|
|
if(this.pos.config.use_proxy){
|
|
|
|
this.proxy_status = new module.ProxyStatusWidget(this,{});
|
|
|
|
this.proxy_status.appendTo(this.$('.pos-rightheader'));
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:47:41 +00:00
|
|
|
this.username = new module.UsernameWidget(this,{});
|
|
|
|
this.username.replace(this.$('.placeholder-UsernameWidget'));
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.action_bar = new module.ActionBarWidget(this);
|
2013-11-06 10:32:55 +00:00
|
|
|
this.action_bar.replace(this.$(".placeholder-RightActionBar"));
|
2012-05-11 16:02:23 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.paypad = new module.PaypadWidget(this, {});
|
2013-11-05 14:19:03 +00:00
|
|
|
this.paypad.replace(this.$('.placeholder-PaypadWidget'));
|
2012-05-11 16:02:23 +00:00
|
|
|
|
|
|
|
this.numpad = new module.NumpadWidget(this);
|
2013-11-05 14:19:03 +00:00
|
|
|
this.numpad.replace(this.$('.placeholder-NumpadWidget'));
|
2012-05-11 16:02:23 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.order_widget = new module.OrderWidget(this, {});
|
2013-11-05 14:19:03 +00:00
|
|
|
this.order_widget.replace(this.$('.placeholder-OrderWidget'));
|
2012-05-03 16:27:46 +00:00
|
|
|
|
2012-06-11 14:04:41 +00:00
|
|
|
this.onscreen_keyboard = new module.OnscreenKeyboardWidget(this, {
|
2012-05-03 16:27:46 +00:00
|
|
|
'keyboard_model': 'simple'
|
|
|
|
});
|
2013-11-05 14:58:44 +00:00
|
|
|
this.onscreen_keyboard.replace(this.$('.placeholder-OnscreenKeyboardWidget'));
|
2012-07-19 15:25:19 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
// -------- Screen Selector ---------
|
2012-05-16 13:01:42 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.screen_selector = new module.ScreenSelector({
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos,
|
2012-05-02 15:30:00 +00:00
|
|
|
screen_set:{
|
2012-07-09 15:53:51 +00:00
|
|
|
'products': this.product_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
'payment' : this.payment_screen,
|
2012-07-09 15:53:51 +00:00
|
|
|
'scale': this.scale_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
'receipt' : this.receipt_screen,
|
2014-06-13 14:19:05 +00:00
|
|
|
'clientlist': this.clientlist_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-05-06 21:34:39 +00:00
|
|
|
popup_set:{
|
2012-05-07 12:39:32 +00:00
|
|
|
'error': this.error_popup,
|
2014-06-13 14:19:05 +00:00
|
|
|
'error-barcode': this.error_barcode_popup,
|
2012-05-14 14:31:21 +00:00
|
|
|
'error-session': this.error_session_popup,
|
2012-09-05 16:42:21 +00:00
|
|
|
'choose-receipt': this.choose_receipt_popup,
|
2013-04-11 12:07:19 +00:00
|
|
|
'error-no-client': this.error_no_client_popup,
|
|
|
|
'error-invoice-transfer': this.error_invoice_transfer_popup,
|
2014-06-13 14:19:05 +00:00
|
|
|
'confirm': this.confirm_popup,
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2014-06-13 14:19:05 +00:00
|
|
|
default_screen: 'products',
|
|
|
|
default_mode: 'cashier',
|
2012-04-26 11:26:55 +00:00
|
|
|
});
|
2012-07-12 17:00:13 +00:00
|
|
|
|
2012-09-12 16:12:29 +00:00
|
|
|
if(this.pos.debug){
|
|
|
|
this.debug_widget = new module.DebugWidget(this);
|
2013-11-05 14:19:03 +00:00
|
|
|
this.debug_widget.appendTo(this.$('.pos-content'));
|
2012-09-12 16:12:29 +00:00
|
|
|
}
|
2013-12-17 15:15:50 +00:00
|
|
|
|
|
|
|
this.disable_rubberbanding();
|
2013-12-17 17:06:54 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-08 15:40:30 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
changed_pending_operations: function () {
|
|
|
|
var self = this;
|
2012-04-24 17:20:47 +00:00
|
|
|
this.synch_notification.on_change_nbr_pending(self.pos.get('nbr_pending_operations').length);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
// shows or hide the numpad and related controls like the paypad.
|
2012-05-04 10:27:37 +00:00
|
|
|
set_numpad_visible: function(visible){
|
2012-07-12 17:00:13 +00:00
|
|
|
if(visible !== this.numpad_visible){
|
2012-05-04 10:27:37 +00:00
|
|
|
this.numpad_visible = visible;
|
|
|
|
if(visible){
|
2012-07-03 11:47:41 +00:00
|
|
|
this.numpad.show();
|
|
|
|
this.paypad.show();
|
2012-05-04 10:27:37 +00:00
|
|
|
}else{
|
2012-07-03 11:47:41 +00:00
|
|
|
this.numpad.hide();
|
|
|
|
this.paypad.hide();
|
2012-05-04 10:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
//shows or hide the leftpane (contains the list of orderlines, the numpad, the paypad, etc.)
|
2012-05-04 10:27:37 +00:00
|
|
|
set_leftpane_visible: function(visible){
|
2012-07-12 17:00:13 +00:00
|
|
|
if(visible !== this.leftpane_visible){
|
2012-05-04 10:27:37 +00:00
|
|
|
this.leftpane_visible = visible;
|
|
|
|
if(visible){
|
2014-06-13 14:19:05 +00:00
|
|
|
this.$('.pos-leftpane').removeClass('oe_hidden');
|
|
|
|
this.$('.rightpane').css({'left':this.leftpane_width});
|
2012-05-04 10:27:37 +00:00
|
|
|
}else{
|
2014-06-13 14:19:05 +00:00
|
|
|
this.$('.pos-leftpane').addClass('oe_hidden');
|
|
|
|
this.$('.rightpane').css({'left':'0px'});
|
2012-05-04 10:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
close: function() {
|
2012-08-06 15:40:54 +00:00
|
|
|
var self = this;
|
2013-09-23 15:04:31 +00:00
|
|
|
|
|
|
|
function close(){
|
2013-12-18 14:56:02 +00:00
|
|
|
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_client_pos_menu']], ['res_id']).pipe(function(res) {
|
|
|
|
window.location = '/web#action=' + res[0]['res_id'];
|
|
|
|
});
|
2013-09-23 15:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var draft_order = _.find( self.pos.get('orders').models, function(order){
|
|
|
|
return order.get('orderLines').length !== 0 && order.get('paymentLines').length === 0;
|
|
|
|
});
|
|
|
|
if(draft_order){
|
|
|
|
if (confirm(_t("Pending orders will be lost.\nAre you sure you want to leave this session?"))) {
|
|
|
|
return close();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return close();
|
|
|
|
}
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
destroy: function() {
|
2013-09-02 15:59:07 +00:00
|
|
|
this.pos.destroy();
|
2012-04-24 16:25:46 +00:00
|
|
|
instance.webclient.set_content_full_screen(false);
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|