2012-05-03 17:15:23 +00:00
|
|
|
|
|
|
|
// this file contains the screens definitions. Screens are the
|
|
|
|
// content of the right pane of the pos, containing the main functionalities.
|
|
|
|
// screens are contained in the PosWidget, in pos_widget.js
|
|
|
|
// all screens are present in the dom at all time, but only one is shown at the
|
|
|
|
// same time.
|
|
|
|
//
|
|
|
|
// transition between screens is made possible by the use of the screen_selector,
|
|
|
|
// which is responsible of hiding and showing the screens, as well as maintaining
|
|
|
|
// the state of the screens between different orders.
|
|
|
|
//
|
|
|
|
// all screens inherit from ScreenWidget. the only addition from the base widgets
|
|
|
|
// are show() and hide() which shows and hides the screen but are also used to
|
|
|
|
// bind and unbind actions on widgets and devices. The screen_selector guarantees
|
|
|
|
// that only one screen is shown at the same time and that show() is called after all
|
|
|
|
// hide()s
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
function openerp_pos_screens(instance, module){ //module is instance.point_of_sale
|
2012-05-03 17:15:23 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
|
|
|
|
module.ScreenSelector = instance.web.Class.extend({
|
|
|
|
init: function(options){
|
2012-06-11 14:04:41 +00:00
|
|
|
console.log("ScreenSelector Initialized");
|
2012-05-03 17:15:23 +00:00
|
|
|
this.pos = options.pos;
|
2012-05-04 09:48:25 +00:00
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
this.screen_set = options.screen_set || {};
|
2012-05-04 09:48:25 +00:00
|
|
|
|
2012-05-06 21:34:39 +00:00
|
|
|
this.popup_set = options.popup_set || {};
|
|
|
|
|
2012-05-04 09:48:25 +00:00
|
|
|
this.default_client_screen = options.default_client_screen;
|
|
|
|
this.default_cashier_screen = options.default_cashier_screen;
|
|
|
|
|
2012-05-06 21:34:39 +00:00
|
|
|
this.current_popup = null;
|
|
|
|
|
2012-05-08 12:37:01 +00:00
|
|
|
this.current_mode = options.default_mode || 'client';
|
2012-05-04 09:48:25 +00:00
|
|
|
|
2012-06-11 14:04:41 +00:00
|
|
|
this.current_screen = null;
|
2012-05-16 13:01:42 +00:00
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
for(screen_name in this.screen_set){
|
2012-06-11 14:04:41 +00:00
|
|
|
this.screen_set[screen_name].hide();
|
2012-05-03 17:15:23 +00:00
|
|
|
}
|
2012-05-06 21:34:39 +00:00
|
|
|
|
|
|
|
for(popup_name in this.popup_set){
|
|
|
|
this.popup_set[popup_name].hide();
|
|
|
|
}
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
this.selected_order = this.pos.get('selectedOrder');
|
2012-05-04 09:48:25 +00:00
|
|
|
this.selected_order.set({
|
|
|
|
user_mode : this.current_mode,
|
|
|
|
client_screen: this.default_client_screen,
|
|
|
|
cashier_screen: this.default_cashier_screen,
|
|
|
|
});
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
this.pos.bind('change:selectedOrder', this.load_saved_screen, this);
|
|
|
|
},
|
|
|
|
add_screen: function(screen_name, screen){
|
|
|
|
screen.hide();
|
|
|
|
this.screen_set[screen_name] = screen;
|
|
|
|
return this;
|
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
show_popup: function(name){
|
2012-05-06 21:34:39 +00:00
|
|
|
if(this.current_popup){
|
|
|
|
this.close_popup();
|
|
|
|
}
|
|
|
|
this.current_popup = this.popup_set[name];
|
|
|
|
this.current_popup.show();
|
|
|
|
},
|
|
|
|
close_popup: function(){
|
|
|
|
if(this.current_popup){
|
|
|
|
this.current_popup.hide();
|
|
|
|
this.current_popup = null;
|
|
|
|
}
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
load_saved_screen: function(){
|
2012-05-06 21:34:39 +00:00
|
|
|
this.close_popup();
|
2012-05-08 12:37:01 +00:00
|
|
|
|
|
|
|
var selectedOrder = this.pos.get('selectedOrder');
|
|
|
|
|
|
|
|
if(this.current_mode === 'client'){
|
|
|
|
this.set_current_screen(selectedOrder.get('client_screen') || this.default_client_screen);
|
|
|
|
}else if(this.current_mode === 'cashier'){
|
|
|
|
this.set_current_screen(selectedOrder.get('cashier_screen') || this.default_cashier_screen);
|
2012-05-04 09:48:25 +00:00
|
|
|
}
|
2012-05-08 12:37:01 +00:00
|
|
|
this.selected_order = selectedOrder;
|
2012-05-04 09:48:25 +00:00
|
|
|
},
|
|
|
|
set_user_mode: function(user_mode){
|
|
|
|
if(user_mode !== this.current_mode){
|
2012-05-06 21:34:39 +00:00
|
|
|
this.close_popup();
|
2012-05-04 09:48:25 +00:00
|
|
|
this.current_mode = user_mode;
|
|
|
|
this.load_saved_screen();
|
2012-05-03 17:15:23 +00:00
|
|
|
}
|
|
|
|
},
|
2012-05-08 12:37:01 +00:00
|
|
|
get_user_mode: function(){
|
|
|
|
return this.current_mode;
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
set_current_screen: function(screen_name){
|
|
|
|
var screen = this.screen_set[screen_name];
|
|
|
|
|
2012-05-06 21:34:39 +00:00
|
|
|
this.close_popup();
|
2012-05-04 09:48:25 +00:00
|
|
|
var selectedOrder = this.pos.get('selectedOrder');
|
|
|
|
if(this.current_mode === 'client'){
|
|
|
|
selectedOrder.set({'client_screen': screen_name});
|
|
|
|
}else{
|
|
|
|
selectedOrder.set({'cashier_screen': screen_name});
|
|
|
|
}
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
if(screen && screen !== this.current_screen){
|
|
|
|
if(this.current_screen){
|
2012-06-11 14:04:41 +00:00
|
|
|
this.current_screen.close();
|
2012-05-03 17:15:23 +00:00
|
|
|
this.current_screen.hide();
|
|
|
|
}
|
|
|
|
this.current_screen = screen;
|
|
|
|
this.current_screen.show();
|
|
|
|
}
|
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
set_default_screen: function(){
|
|
|
|
this.set_current_screen(this.current_mode === 'client' ? this.default_client_screen : this.default_cashier_screen);
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
module.ScreenWidget = module.PosBaseWidget.extend({
|
2012-06-11 14:04:41 +00:00
|
|
|
|
2012-05-23 15:25:35 +00:00
|
|
|
init: function(parent,options){
|
|
|
|
this._super(parent,options);
|
|
|
|
this.hidden = false;
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
show: function(){
|
2012-05-23 15:25:35 +00:00
|
|
|
this.hidden = false;
|
2012-05-03 17:15:23 +00:00
|
|
|
if(this.$element){
|
|
|
|
this.$element.show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hide: function(){
|
2012-05-23 15:25:35 +00:00
|
|
|
this.hidden = true;
|
2012-05-03 17:15:23 +00:00
|
|
|
if(this.$element){
|
|
|
|
this.$element.hide();
|
|
|
|
}
|
|
|
|
if(this.pos.barcode_reader){
|
|
|
|
this.pos.barcode_reader.reset_action_callbacks();
|
|
|
|
}
|
|
|
|
if(this.pos_widget.action_bar){
|
|
|
|
this.pos_widget.action_bar.destroy_buttons();
|
|
|
|
}
|
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
close: function(){
|
|
|
|
},
|
2012-05-23 15:25:35 +00:00
|
|
|
// we need this because some screens re-render themselves when they are hidden
|
|
|
|
// (due to some events, or magic, or both...) we must make sure they remain hidden.
|
|
|
|
// the good solution would probably be to make them not re-render themselves when they
|
|
|
|
// are hidden.
|
|
|
|
renderElement: function(){
|
|
|
|
this._super();
|
|
|
|
if(this.hidden){
|
|
|
|
if(this.$element){
|
|
|
|
this.$element.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
|
2012-06-11 14:04:41 +00:00
|
|
|
module.PopUpWidget = module.PosBaseWidget.extend({
|
|
|
|
show: function(){
|
|
|
|
if(this.$element){
|
|
|
|
this.$element.show();
|
|
|
|
}
|
|
|
|
},
|
2012-05-07 12:39:32 +00:00
|
|
|
hide: function(){
|
|
|
|
if(this.$element){
|
|
|
|
this.$element.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.HelpPopupWidget = module.PopUpWidget.extend({
|
2012-05-06 21:34:39 +00:00
|
|
|
template:'HelpPopupWidget',
|
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
this.pos.proxy.help_needed();
|
|
|
|
var self = this;
|
|
|
|
|
2012-05-07 12:39:32 +00:00
|
|
|
this.$element.find('.button').off('click').click(function(){
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.close_popup();
|
2012-05-07 12:39:32 +00:00
|
|
|
self.pos.proxy.help_canceled();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ReceiptPopupWidget = module.PopUpWidget.extend({
|
|
|
|
template:'ReceiptPopupWidget',
|
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
|
|
|
this.$element.find('.receipt').off('click').click(function(){
|
2012-05-23 15:25:35 +00:00
|
|
|
console.log('TODO receipt'); //TODO
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scan');
|
2012-05-07 12:39:32 +00:00
|
|
|
});
|
|
|
|
this.$element.find('.invoice').off('click').click(function(){
|
2012-05-23 15:25:35 +00:00
|
|
|
console.log('TODO invoice'); //TODO
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scan');
|
2012-05-07 12:39:32 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ErrorPopupWidget = module.PopUpWidget.extend({
|
|
|
|
template:'ErrorPopupWidget',
|
|
|
|
show: function(){
|
2012-05-08 15:40:30 +00:00
|
|
|
var self = this;
|
2012-05-07 12:39:32 +00:00
|
|
|
this._super();
|
|
|
|
this.pos.proxy.help_needed();
|
2012-05-08 15:40:30 +00:00
|
|
|
this.pos.proxy.scan_item_error_unrecognized();
|
|
|
|
|
|
|
|
this.pos.barcode_reader.save_callbacks();
|
|
|
|
this.pos.barcode_reader.reset_action_callbacks();
|
2012-06-11 14:04:41 +00:00
|
|
|
this.pos.barcode_reader.set_action_callback({
|
2012-05-08 15:40:30 +00:00
|
|
|
'cashier': function(ean){
|
|
|
|
clearInterval(this.intervalID);
|
|
|
|
self.pos.proxy.cashier_mode_activated();
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_user_mode('cashier');
|
2012-05-08 15:40:30 +00:00
|
|
|
},
|
2012-05-06 21:34:39 +00:00
|
|
|
});
|
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
close:function(){
|
2012-05-07 12:39:32 +00:00
|
|
|
this._super();
|
|
|
|
this.pos.proxy.help_canceled();
|
2012-05-08 15:40:30 +00:00
|
|
|
this.pos.barcode_reader.restore_callbacks();
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-14 14:31:21 +00:00
|
|
|
module.ErrorProductNotRecognizedPopupWidget = module.ErrorPopupWidget.extend({
|
|
|
|
template:'ErrorProductNotRecognizedPopupWidget',
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ErrorNoSessionPopupWidget = module.ErrorPopupWidget.extend({
|
|
|
|
template:'ErrorNoSessionPopupWidget',
|
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.BaseScreenWidget = module.ScreenWidget.extend({
|
|
|
|
|
|
|
|
show_numpad: true,
|
|
|
|
show_leftpane: true,
|
|
|
|
show_total: true,
|
|
|
|
|
|
|
|
help_button_action: function(){
|
|
|
|
this.pos_widget.screen_selector.show_popup('help');
|
|
|
|
},
|
|
|
|
|
|
|
|
logout_button_action: function(){
|
|
|
|
this.pos_widget.screen_selector.set_user_mode('client');
|
|
|
|
},
|
|
|
|
|
|
|
|
barcode_cashier_action: function(ean){
|
|
|
|
this.pos.proxy.cashier_mode_activated();
|
|
|
|
this.pos_widget.screen_selector.set_user_mode('cashier');
|
|
|
|
},
|
|
|
|
|
|
|
|
barcode_product_screen: 'scan',
|
|
|
|
barcode_product_error_popup: 'error',
|
|
|
|
barcode_product_action: function(ean){
|
|
|
|
if(this.pos_widget.scan_product(ean)){
|
|
|
|
this.pos.proxy.scan_item_success();
|
|
|
|
if(this.barcode_product_screen){
|
|
|
|
this.pos_widget.screen_selector.set_current_screen(this.barcode_product_screen);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(this.barcode_product_error_popup){
|
|
|
|
this.pos_widget.screen_selector.show_popup(this.barcode_product_error_popup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
barcode_client_action: function(ean){
|
|
|
|
this.pos.proxy.transaction_start();
|
|
|
|
//TODO 'log the client'
|
|
|
|
this.pos_widget.screen_selector.show_popup('receipt');
|
|
|
|
},
|
|
|
|
|
|
|
|
barcode_discount_action: function(ean){
|
|
|
|
var currentOrder = this.pos.get('selectedOrder');
|
|
|
|
var last_orderline = currentOrder.last_orderline;
|
|
|
|
if(last_orderline){
|
|
|
|
last_orderline.set_discount(ean.value)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-06-11 15:20:22 +00:00
|
|
|
var cashier_mode = this.pos_widget.screen_selector.get_user_mode() === 'cashier';
|
2012-05-03 17:15:23 +00:00
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
this.pos_widget.set_numpad_visible(this.show_numpad && cashier_mode);
|
|
|
|
this.pos_widget.set_leftpane_visible(this.show_leftpane);
|
|
|
|
this.pos_widget.set_cashier_controls_visible(cashier_mode);
|
2012-06-11 15:29:29 +00:00
|
|
|
this.pos_widget.action_bar.set_element_visible('total', this.show_total);
|
|
|
|
this.pos_widget.action_bar.set_element_visible('help-button', !cashier_mode, function(){ self.help_button_action(); });
|
|
|
|
this.pos_widget.action_bar.set_element_visible('logout-button', cashier_mode, function(){ self.logout_button_action(); });
|
|
|
|
this.pos_widget.action_bar.set_element_visible('close-button', cashier_mode);
|
2012-06-11 15:20:22 +00:00
|
|
|
|
|
|
|
this.pos.barcode_reader.set_action_callback({
|
|
|
|
'cashier': self.barcode_cashier_action ? function(ean){ self.barcode_cashier_action(ean); } : undefined ,
|
|
|
|
'product': self.barcode_product_action ? function(ean){ self.barcode_product_action(ean); } : undefined ,
|
|
|
|
'client' : self.barcode_client_action ? function(ean){ self.barcode_client_action(ean); } : undefined ,
|
|
|
|
'discount': self.barcode_discount_action ? function(ean){ self.barcode_discount_action(ean); } : undefined,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ScaleInviteScreenWidget = module.BaseScreenWidget.extend({
|
|
|
|
template:'ScaleInviteScreenWidget',
|
|
|
|
|
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
self.pos.proxy.weighting_start();
|
|
|
|
|
2012-05-04 09:48:25 +00:00
|
|
|
this.intervalID = setInterval(function(){
|
2012-05-03 17:15:23 +00:00
|
|
|
var weight = self.pos.proxy.weighting_read_kg();
|
|
|
|
if(weight > 0.001){
|
2012-05-06 21:34:39 +00:00
|
|
|
clearInterval(this.intervalID);
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scale_product');
|
2012-05-03 17:15:23 +00:00
|
|
|
}
|
|
|
|
},500);
|
|
|
|
|
|
|
|
this.pos_widget.action_bar.add_new_button(
|
|
|
|
{
|
|
|
|
label: 'back',
|
2012-05-06 21:34:39 +00:00
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',
|
2012-05-08 12:37:01 +00:00
|
|
|
click: function(){
|
2012-05-04 09:48:25 +00:00
|
|
|
clearInterval(this.intervalID);
|
2012-05-03 17:15:23 +00:00
|
|
|
self.pos.proxy.weighting_end();
|
2012-06-21 16:23:52 +00:00
|
|
|
if( self.pos_widget.screen_selector.get_user_mode() === 'client'){
|
|
|
|
self.pos_widget.screen_selector.set_current_screen('scan');
|
|
|
|
}else{
|
|
|
|
self.pos_widget.screen_selector.set_current_screen('products');
|
|
|
|
}
|
2012-05-03 17:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
close: function(){
|
2012-05-04 09:48:25 +00:00
|
|
|
this._super();
|
|
|
|
clearInterval(this.intervalID);
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.ScaleProductScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-03 17:15:23 +00:00
|
|
|
template:'ScaleProductSelectionScreenWidget',
|
2012-06-25 10:01:55 +00:00
|
|
|
renderElement: function(){
|
|
|
|
this._super();
|
2012-05-29 14:00:08 +00:00
|
|
|
this.product_categories_widget = new module.ProductCategoriesWidget(this,{
|
2012-05-03 17:15:23 +00:00
|
|
|
pos:this.pos,
|
2012-06-04 11:52:44 +00:00
|
|
|
product_type: 'weightable',
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
this.product_categories_widget.replace($('.placeholder-ProductCategoriesWidget'));
|
|
|
|
|
2012-05-29 13:31:41 +00:00
|
|
|
this.product_list_widget = new module.ProductListWidget(this,{
|
2012-05-29 16:39:44 +00:00
|
|
|
show_scale: true,
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
this.product_list_widget.replace($('.placeholder-ProductListWidget'));
|
|
|
|
},
|
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-06-11 15:20:22 +00:00
|
|
|
|
|
|
|
this.product_categories_widget.reset_category();
|
|
|
|
this.pos_widget.order_widget.set_numpad_state(this.pos_widget.numpad.state);
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
if(this.pos_widget.screen_selector.get_user_mode() === 'client'){
|
2012-06-11 15:20:22 +00:00
|
|
|
this.pos_widget.action_bar.add_new_button({
|
2012-05-08 12:37:01 +00:00
|
|
|
label: 'back',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',
|
|
|
|
click: function(){
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scan');
|
2012-05-08 12:37:01 +00:00
|
|
|
}
|
2012-06-11 15:20:22 +00:00
|
|
|
});
|
2012-05-08 12:37:01 +00:00
|
|
|
this.product_list_widget.set_next_screen('scan');
|
2012-06-11 15:20:22 +00:00
|
|
|
}else{
|
|
|
|
this.pos_widget.action_bar.add_new_button({
|
2012-05-08 12:37:01 +00:00
|
|
|
label: 'back',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',
|
|
|
|
click: function(){
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('products');
|
2012-05-08 12:37:01 +00:00
|
|
|
}
|
2012-06-11 15:20:22 +00:00
|
|
|
});
|
|
|
|
this.product_list_widget.set_next_screen('products');
|
2012-05-08 12:37:01 +00:00
|
|
|
}
|
2012-05-06 21:34:39 +00:00
|
|
|
|
|
|
|
this.pos.proxy.weighting_start();
|
|
|
|
this.last_weight = this.product_list_widget.weight;
|
|
|
|
this.intervalID = setInterval(function(){
|
|
|
|
var weight = self.pos.proxy.weighting_read_kg();
|
|
|
|
if(weight != self.last_weight){
|
2012-05-08 12:37:01 +00:00
|
|
|
self.product_list_widget.set_weight(weight);
|
2012-05-06 21:34:39 +00:00
|
|
|
self.last_weight = weight;
|
|
|
|
}
|
|
|
|
},500);
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
close: function(){
|
2012-05-03 17:15:23 +00:00
|
|
|
this._super();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos_widget.order_widget.set_numpad_state(null);
|
|
|
|
this.pos_widget.payment_screen.set_numpad_state(null);
|
2012-05-06 21:34:39 +00:00
|
|
|
clearInterval(this.intervalID);
|
|
|
|
this.pos.proxy.weighting_end();
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.ClientPaymentScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-03 17:15:23 +00:00
|
|
|
template:'ClientPaymentScreenWidget',
|
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
|
|
|
|
2012-06-04 16:26:07 +00:00
|
|
|
this.pos.proxy.payment_request(this.pos.get('selectedOrder').getDueLeft(),'card','info'); //TODO TOTAL
|
2012-05-03 17:15:23 +00:00
|
|
|
|
2012-05-06 21:34:39 +00:00
|
|
|
this.intervalID = setInterval(function(){
|
2012-05-03 17:15:23 +00:00
|
|
|
var payment = self.pos.proxy.is_payment_accepted();
|
|
|
|
if(payment === 'payment_accepted'){
|
2012-05-06 21:34:39 +00:00
|
|
|
clearInterval(this.intervalID);
|
2012-06-04 16:26:07 +00:00
|
|
|
|
2012-05-08 15:40:30 +00:00
|
|
|
var currentOrder = self.pos.get('selectedOrder');
|
2012-06-05 09:45:03 +00:00
|
|
|
|
|
|
|
//we get the first cashregister marked as self-checkout
|
|
|
|
var selfCheckoutRegisters = [];
|
|
|
|
for(var i = 0; i < this.pos.get('cashRegisters').models.length; i++){
|
|
|
|
var cashregister = this.pos.get('cashRegisters').models[i];
|
|
|
|
if(cashregister.self_checkout_payment_method){
|
|
|
|
selfCheckoutRegisters.push(cashregister);
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 16:26:07 +00:00
|
|
|
|
2012-06-05 09:45:03 +00:00
|
|
|
var cashregister = selfCheckoutRegisters[0] || this.pos.get('cashRegisters').models[0];
|
2012-06-04 16:26:07 +00:00
|
|
|
currentOrder.addPaymentLine(cashregister);
|
|
|
|
|
2012-05-08 15:40:30 +00:00
|
|
|
self.pos.push_order(currentOrder.exportAsJSON()).then(function() {
|
|
|
|
currentOrder.destroy();
|
|
|
|
self.pos.proxy.transaction_end();
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('welcome');
|
2012-05-08 15:40:30 +00:00
|
|
|
});
|
2012-05-03 17:15:23 +00:00
|
|
|
}else if(payment === 'payment_rejected'){
|
2012-05-06 21:34:39 +00:00
|
|
|
clearInterval(this.intervalID);
|
2012-05-03 17:15:23 +00:00
|
|
|
//TODO show a tryagain thingie ?
|
|
|
|
}
|
|
|
|
},500);
|
|
|
|
|
|
|
|
this.pos_widget.action_bar.add_new_button(
|
|
|
|
{
|
|
|
|
label: 'back',
|
2012-05-06 21:34:39 +00:00
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',
|
2012-05-03 17:15:23 +00:00
|
|
|
click: function(){ //TODO Go to ask for weighting screen
|
2012-05-06 21:34:39 +00:00
|
|
|
clearInterval(this.intervalID);
|
2012-05-03 17:15:23 +00:00
|
|
|
self.pos.proxy.payment_canceled();
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scan');
|
2012-05-03 17:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
close: function(){
|
2012-05-08 12:37:01 +00:00
|
|
|
this._super();
|
|
|
|
clearInterval(this.intervalID);
|
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.WelcomeScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-03 17:15:23 +00:00
|
|
|
template:'WelcomeScreenWidget',
|
2012-06-11 15:20:22 +00:00
|
|
|
|
|
|
|
show_numpad: false,
|
|
|
|
show_leftpane: false,
|
|
|
|
show_total: false,
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-06-04 15:04:59 +00:00
|
|
|
if(this.pos.use_scale){
|
|
|
|
this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'weight',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/scale.png',
|
|
|
|
click: function(){
|
|
|
|
self.pos_widget.screen_selector.set_current_screen('scale_invite');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.ScanProductScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-03 17:15:23 +00:00
|
|
|
template:'ScanProductScreenWidget',
|
2012-06-11 15:20:22 +00:00
|
|
|
|
|
|
|
show_numpad: false,
|
|
|
|
show_leftpane: true,
|
|
|
|
show_total: true,
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-06-04 15:04:59 +00:00
|
|
|
if(self.pos.use_scale){
|
|
|
|
this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'weight',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/scale.png',
|
2012-06-11 15:20:22 +00:00
|
|
|
click: function(){
|
2012-06-04 15:04:59 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scale_invite');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pos_widget.action_bar.add_new_button({
|
2012-05-03 17:15:23 +00:00
|
|
|
label: 'pay',
|
2012-05-06 21:34:39 +00:00
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-next.png',
|
2012-05-03 17:15:23 +00:00
|
|
|
click: function(){
|
2012-06-11 15:20:22 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('client_payment');
|
2012-05-03 17:15:23 +00:00
|
|
|
}
|
2012-06-04 15:04:59 +00:00
|
|
|
});
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.SearchProductScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-03 17:15:23 +00:00
|
|
|
template:'SearchProductScreenWidget',
|
2012-06-11 15:20:22 +00:00
|
|
|
|
|
|
|
show_numpad: true,
|
|
|
|
show_leftpane: true,
|
|
|
|
show_total: true,
|
|
|
|
|
2012-06-25 10:01:55 +00:00
|
|
|
renderElement: function(){
|
|
|
|
this._super();
|
2012-05-29 16:39:44 +00:00
|
|
|
this.product_categories_widget = new module.ProductCategoriesWidget(this,{});
|
2012-05-03 17:15:23 +00:00
|
|
|
this.product_categories_widget.replace($('.placeholder-ProductCategoriesWidget'));
|
|
|
|
|
2012-05-29 14:00:08 +00:00
|
|
|
this.product_list_widget = new module.ProductListWidget(this,{});
|
2012-05-03 17:15:23 +00:00
|
|
|
this.product_list_widget.replace($('.placeholder-ProductListWidget'));
|
|
|
|
},
|
2012-06-11 15:20:22 +00:00
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
show: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.product_categories_widget.reset_category();
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos_widget.order_widget.set_numpad_state(this.pos_widget.numpad.state);
|
2012-06-04 15:04:59 +00:00
|
|
|
|
|
|
|
if(this.pos.use_scale){
|
|
|
|
this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'weight',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/scale.png',
|
|
|
|
click: function(){
|
2012-06-21 16:23:52 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen('scale_invite');
|
2012-06-04 15:04:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
2012-06-11 15:20:22 +00:00
|
|
|
|
2012-06-11 14:04:41 +00:00
|
|
|
close: function(){
|
2012-05-03 17:15:23 +00:00
|
|
|
this._super();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos_widget.order_widget.set_numpad_state(null);
|
|
|
|
this.pos_widget.payment_screen.set_numpad_state(null);
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.ReceiptScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-03 17:15:23 +00:00
|
|
|
template: 'ReceiptScreenWidget',
|
2012-06-11 15:20:22 +00:00
|
|
|
|
|
|
|
show_numpad: true,
|
|
|
|
show_leftpane: true,
|
|
|
|
show_total: true,
|
|
|
|
|
2012-05-03 17:15:23 +00:00
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent,options);
|
|
|
|
this.model = options.model;
|
|
|
|
this.user = this.pos.get('user');
|
|
|
|
this.company = this.pos.get('company');
|
|
|
|
this.shop_obj = this.pos.get('shop');
|
|
|
|
},
|
2012-06-25 10:01:55 +00:00
|
|
|
renderElement: function() {
|
|
|
|
this._super();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos.bind('change:selectedOrder', this.change_selected_order, this);
|
|
|
|
this.change_selected_order();
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
2012-05-04 10:27:37 +00:00
|
|
|
show: function(){
|
|
|
|
this._super();
|
2012-05-06 21:34:39 +00:00
|
|
|
var self = this;
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-05-24 14:14:08 +00:00
|
|
|
this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'Print',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/printer.png',
|
|
|
|
click: function(){ self.print(); },
|
|
|
|
});
|
|
|
|
|
|
|
|
this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'Next Order',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-next.png',
|
|
|
|
click: function() { self.finishOrder(); },
|
|
|
|
});
|
2012-05-04 10:27:37 +00:00
|
|
|
},
|
2012-05-03 17:15:23 +00:00
|
|
|
print: function() {
|
|
|
|
window.print();
|
|
|
|
},
|
|
|
|
finishOrder: function() {
|
|
|
|
this.pos.get('selectedOrder').destroy();
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
change_selected_order: function() {
|
2012-05-03 17:15:23 +00:00
|
|
|
if (this.currentOrderLines)
|
|
|
|
this.currentOrderLines.unbind();
|
|
|
|
this.currentOrderLines = (this.pos.get('selectedOrder')).get('orderLines');
|
|
|
|
this.currentOrderLines.bind('add', this.refresh, this);
|
|
|
|
this.currentOrderLines.bind('change', this.refresh, this);
|
|
|
|
this.currentOrderLines.bind('remove', this.refresh, this);
|
|
|
|
if (this.currentPaymentLines)
|
|
|
|
this.currentPaymentLines.unbind();
|
|
|
|
this.currentPaymentLines = (this.pos.get('selectedOrder')).get('paymentLines');
|
|
|
|
this.currentPaymentLines.bind('all', this.refresh, this);
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
refresh: function() {
|
|
|
|
this.currentOrder = this.pos.get('selectedOrder');
|
2012-05-14 14:03:40 +00:00
|
|
|
$('.pos-receipt-container', this.$element).html(QWeb.render('PosTicket',{widget:this}));
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-06-11 15:20:22 +00:00
|
|
|
module.PaymentScreenWidget = module.BaseScreenWidget.extend({
|
2012-05-14 14:03:40 +00:00
|
|
|
template: 'PaymentScreenWidget',
|
2012-05-03 17:15:23 +00:00
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent,options);
|
|
|
|
this.model = options.model;
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos.bind('change:selectedOrder', this.change_selected_order, this);
|
2012-05-03 17:15:23 +00:00
|
|
|
this.bindPaymentLineEvents();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.bind_orderline_events();
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
show: function(){
|
|
|
|
this._super();
|
2012-05-06 21:34:39 +00:00
|
|
|
var self = this;
|
2012-05-04 10:27:37 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.set_numpad_state(this.pos_widget.numpad.state);
|
2012-05-24 13:39:30 +00:00
|
|
|
|
|
|
|
this.back_button = this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'Back',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',
|
|
|
|
click: function(){
|
|
|
|
self.pos_widget.screen_selector.set_current_screen('products');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
this.validate_button = this.pos_widget.action_bar.add_new_button({
|
|
|
|
label: 'Validate',
|
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/validate.png',
|
|
|
|
click: function(){
|
|
|
|
self.validateCurrentOrder();
|
|
|
|
},
|
|
|
|
});
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
2012-06-11 14:04:41 +00:00
|
|
|
close: function(){
|
2012-05-03 17:15:23 +00:00
|
|
|
this._super();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos_widget.order_widget.set_numpad_state(null);
|
|
|
|
this.pos_widget.payment_screen.set_numpad_state(null);
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
back: function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos_widget.screen_selector.set_current_screen('products');
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
validateCurrentOrder: function() {
|
2012-05-21 16:57:21 +00:00
|
|
|
var self = this;
|
|
|
|
var currentOrder = this.pos.get('selectedOrder');
|
|
|
|
|
2012-05-24 13:39:30 +00:00
|
|
|
this.validate_button.$element.attr('disabled','disabled'); //FIXME is the css actually using this attr ?
|
2012-05-21 16:57:21 +00:00
|
|
|
|
2012-05-24 13:39:30 +00:00
|
|
|
this.pos.push_order(currentOrder.exportAsJSON())
|
|
|
|
.then(function() {
|
|
|
|
self.validate_button.$element.removeAttr('disabled');
|
2012-06-04 15:04:59 +00:00
|
|
|
if(self.pos.use_proxy_printer){
|
|
|
|
self.pos.get('selectedOrder').destroy(); //finish order and go back to scan screen
|
|
|
|
}else{
|
|
|
|
self.pos_widget.screen_selector.set_current_screen('receipt');
|
|
|
|
}
|
2012-05-24 13:39:30 +00:00
|
|
|
});
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
bindPaymentLineEvents: function() {
|
|
|
|
this.currentPaymentLines = (this.pos.get('selectedOrder')).get('paymentLines');
|
|
|
|
this.currentPaymentLines.bind('add', this.addPaymentLine, this);
|
|
|
|
this.currentPaymentLines.bind('remove', this.renderElement, this);
|
|
|
|
this.currentPaymentLines.bind('all', this.updatePaymentSummary, this);
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
bind_orderline_events: function() {
|
2012-05-03 17:15:23 +00:00
|
|
|
this.currentOrderLines = (this.pos.get('selectedOrder')).get('orderLines');
|
|
|
|
this.currentOrderLines.bind('all', this.updatePaymentSummary, this);
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
change_selected_order: function() {
|
2012-05-03 17:15:23 +00:00
|
|
|
this.currentPaymentLines.unbind();
|
|
|
|
this.bindPaymentLineEvents();
|
|
|
|
this.currentOrderLines.unbind();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.bind_orderline_events();
|
2012-05-03 17:15:23 +00:00
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
addPaymentLine: function(newPaymentLine) {
|
2012-06-04 16:26:07 +00:00
|
|
|
console.log('addPaymentLine:',newPaymentLine);
|
2012-05-03 17:15:23 +00:00
|
|
|
var x = new module.PaymentlineWidget(null, {
|
2012-05-22 10:32:25 +00:00
|
|
|
payment_line: newPaymentLine
|
2012-05-03 17:15:23 +00:00
|
|
|
});
|
|
|
|
x.on_delete.add(_.bind(this.deleteLine, this, x));
|
2012-05-22 10:32:25 +00:00
|
|
|
x.appendTo(this.$('#paymentlines'));
|
2012-05-03 17:15:23 +00:00
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this._super();
|
2012-05-22 10:32:25 +00:00
|
|
|
this.$('#paymentlines').empty();
|
2012-05-03 17:15:23 +00:00
|
|
|
this.currentPaymentLines.each(_.bind( function(paymentLine) {
|
|
|
|
this.addPaymentLine(paymentLine);
|
|
|
|
}, this));
|
|
|
|
this.updatePaymentSummary();
|
|
|
|
},
|
|
|
|
deleteLine: function(lineWidget) {
|
|
|
|
this.currentPaymentLines.remove([lineWidget.model]);
|
|
|
|
},
|
|
|
|
updatePaymentSummary: function() {
|
|
|
|
var currentOrder, dueTotal, paidTotal, remaining, remainingAmount;
|
|
|
|
currentOrder = this.pos.get('selectedOrder');
|
|
|
|
paidTotal = currentOrder.getPaidTotal();
|
|
|
|
dueTotal = currentOrder.getTotal();
|
|
|
|
this.$element.find('#payment-due-total').html(dueTotal.toFixed(2));
|
|
|
|
this.$element.find('#payment-paid-total').html(paidTotal.toFixed(2));
|
|
|
|
remainingAmount = dueTotal - paidTotal;
|
|
|
|
remaining = remainingAmount > 0 ? 0 : (-remainingAmount).toFixed(2);
|
|
|
|
$('#payment-remaining').html(remaining);
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
set_numpad_state: function(numpadState) {
|
2012-05-03 17:15:23 +00:00
|
|
|
if (this.numpadState) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this.numpadState.unbind('set_value', this.set_value);
|
2012-05-03 17:15:23 +00:00
|
|
|
this.numpadState.unbind('change:mode', this.setNumpadMode);
|
|
|
|
}
|
|
|
|
this.numpadState = numpadState;
|
|
|
|
if (this.numpadState) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this.numpadState.bind('set_value', this.set_value, this);
|
2012-05-03 17:15:23 +00:00
|
|
|
this.numpadState.bind('change:mode', this.setNumpadMode, this);
|
|
|
|
this.numpadState.reset();
|
|
|
|
this.setNumpadMode();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setNumpadMode: function() {
|
|
|
|
this.numpadState.set({mode: 'payment'});
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
set_value: function(val) {
|
2012-05-03 17:15:23 +00:00
|
|
|
this.currentPaymentLines.last().set({amount: val});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|