1 function openerp_pos_widgets(instance, module){ //module is instance.point_of_sale
2 var QWeb = instance.web.qweb,
5 // The ImageCache is used to hide the latency of the application cache on-disk access in chrome
6 // that causes annoying flickering on product pictures. Why the hell a simple access to
7 // the application cache involves such latency is beyond me, hopefully one day this can be
9 module.ImageCache = instance.web.Class.extend({
10 init: function(options){
11 options = options || {};
12 this.max_size = options.max_size || 500;
15 this.access_time = {};
18 get_image_uncached: function(url){
19 var img = new Image();
23 // returns a DOM Image object from an url, and cache the last 500 (by default) results
24 get_image: function(url){
25 var cached = this.cache[url];
27 this.access_time[url] = (new Date()).getTime();
30 var img = new Image();
32 while(this.size >= this.max_size){
34 var oldestTime = (new Date()).getTime();
35 for(var url in this.cache){
36 var time = this.access_time[url];
37 if(time <= oldestTime){
43 delete this.cache[oldestUrl];
44 delete this.access_time[oldestUrl];
48 this.cache[url] = img;
49 this.access_time[url] = (new Date()).getTime();
56 module.NumpadWidget = module.PosBaseWidget.extend({
57 template:'NumpadWidget',
58 init: function(parent, options) {
60 this.state = new module.NumpadState();
63 this.state.bind('change:mode', this.changedMode, this);
65 this.$el.find('.numpad-backspace').click(_.bind(this.clickDeleteLastChar, this));
66 this.$el.find('.numpad-minus').click(_.bind(this.clickSwitchSign, this));
67 this.$el.find('.number-char').click(_.bind(this.clickAppendNewChar, this));
68 this.$el.find('.mode-button').click(_.bind(this.clickChangeMode, this));
70 clickDeleteLastChar: function() {
71 return this.state.deleteLastChar();
73 clickSwitchSign: function() {
74 return this.state.switchSign();
76 clickAppendNewChar: function(event) {
78 newChar = event.currentTarget.innerText || event.currentTarget.textContent;
79 return this.state.appendNewChar(newChar);
81 clickChangeMode: function(event) {
82 var newMode = event.currentTarget.attributes['data-mode'].nodeValue;
83 return this.state.changeMode(newMode);
85 changedMode: function() {
86 var mode = this.state.get('mode');
87 $('.selected-mode').removeClass('selected-mode');
88 $(_.str.sprintf('.mode-button[data-mode="%s"]', mode), this.$el).addClass('selected-mode');
92 // The paypad allows to select the payment method (cashRegisters)
93 // used to pay the order.
94 module.PaypadWidget = module.PosBaseWidget.extend({
95 template: 'PaypadWidget',
96 renderElement: function() {
100 this.pos.get('cashRegisters').each(function(cashRegister) {
101 var button = new module.PaypadButtonWidget(self,{
103 pos_widget : self.pos_widget,
104 cashRegister: cashRegister,
106 button.appendTo(self.$el);
111 module.PaypadButtonWidget = module.PosBaseWidget.extend({
112 template: 'PaypadButtonWidget',
113 init: function(parent, options){
114 this._super(parent, options);
115 this.cashRegister = options.cashRegister;
117 renderElement: function() {
121 this.$el.click(function(){
122 if (self.pos.get('selectedOrder').get('screen') === 'receipt'){ //TODO Why ?
123 console.warn('TODO should not get there...?');
126 self.pos.get('selectedOrder').addPaymentLine(self.cashRegister);
127 self.pos_widget.screen_selector.set_current_screen('payment');
132 module.OrderlineWidget = module.PosBaseWidget.extend({
133 template: 'OrderlineWidget',
134 init: function(parent, options) {
135 this._super(parent,options);
137 this.model = options.model;
138 this.order = options.order;
140 this.model.bind('change', this.refresh, this);
142 renderElement: function() {
145 this.$el.click(function(){
146 self.order.selectLine(self.model);
147 self.trigger('order_line_selected');
149 if(this.model.is_selected()){
150 this.$el.addClass('selected');
154 this.renderElement();
155 this.trigger('order_line_refreshed');
158 this.model.unbind('change',this.refresh,this);
163 module.OrderWidget = module.PosBaseWidget.extend({
164 template:'OrderWidget',
165 init: function(parent, options) {
166 this._super(parent,options);
167 this.display_mode = options.display_mode || 'numpad'; // 'maximized' | 'actionbar' | 'numpad'
168 this.set_numpad_state(options.numpadState);
169 this.pos.bind('change:selectedOrder', this.change_selected_order, this);
170 this.bind_orderline_events();
171 this.orderlinewidgets = [];
173 set_numpad_state: function(numpadState) {
174 if (this.numpadState) {
175 this.numpadState.unbind('set_value', this.set_value);
177 this.numpadState = numpadState;
178 if (this.numpadState) {
179 this.numpadState.bind('set_value', this.set_value, this);
180 this.numpadState.reset();
183 set_value: function(val) {
184 var order = this.pos.get('selectedOrder');
185 if (order.get('orderLines').length !== 0) {
186 var mode = this.numpadState.get('mode');
187 if( mode === 'quantity'){
188 order.getSelectedLine().set_quantity(val);
189 }else if( mode === 'discount'){
190 order.getSelectedLine().set_discount(val);
191 }else if( mode === 'price'){
192 order.getSelectedLine().set_unit_price(val);
196 change_selected_order: function() {
197 this.currentOrderLines.unbind();
198 this.bind_orderline_events();
199 this.renderElement();
201 bind_orderline_events: function() {
202 this.currentOrderLines = (this.pos.get('selectedOrder')).get('orderLines');
203 this.currentOrderLines.bind('add', function(){ this.renderElement(true);}, this);
204 this.currentOrderLines.bind('remove', this.renderElement, this);
206 update_numpad: function() {
207 this.selected_line = this.pos.get('selectedOrder').getSelectedLine();
208 if (this.numpadState)
209 this.numpadState.reset();
211 renderElement: function(goto_bottom) {
213 var scroller = this.$('.order-scroller')[0];
214 var scrollbottom = true;
217 var overflow_bottom = scroller.scrollHeight - scroller.clientHeight;
218 scrollTop = scroller.scrollTop;
219 if( !goto_bottom && scrollTop < 0.9 * overflow_bottom){
220 scrollbottom = false;
225 // freeing subwidgets
227 for(var i = 0, len = this.orderlinewidgets.length; i < len; i++){
228 this.orderlinewidgets[i].destroy();
230 this.orderlinewidgets = [];
232 var $content = this.$('.orderlines');
233 this.currentOrderLines.each(_.bind( function(orderLine) {
234 var line = new module.OrderlineWidget(this, {
236 order: this.pos.get('selectedOrder'),
238 line.on('order_line_selected', self, self.update_numpad);
239 line.on('order_line_refreshed', self, self.update_summary);
240 line.appendTo($content);
241 self.orderlinewidgets.push(line);
243 this.update_numpad();
244 this.update_summary();
246 scroller = this.$('.order-scroller')[0];
249 scroller.scrollTop = scroller.scrollHeight - scroller.clientHeight;
251 scroller.scrollTop = scrollTop;
255 update_summary: function(){
256 var order = this.pos.get('selectedOrder');
257 var total = order ? order.getTotalTaxIncluded() : 0;
258 var taxes = order ? total - order.getTotalTaxExcluded() : 0;
259 this.$('.summary .total > .value').html(this.format_currency(total));
260 this.$('.summary .total .subentry .value').html(this.format_currency(taxes));
262 set_display_mode: function(mode){
263 if(this.display_mode !== mode){
264 this.display_mode = mode;
265 this.renderElement();
271 module.PaymentlineWidget = module.PosBaseWidget.extend({
272 template: 'PaymentlineWidget',
273 init: function(parent, options) {
274 this._super(parent,options);
275 this.payment_line = options.payment_line;
276 this.payment_line.bind('change', this.changedAmount, this);
278 changeAmount: function(event) {
279 var newAmount = event.currentTarget.value;
280 var amount = parseFloat(newAmount);
282 this.amount = amount;
283 this.payment_line.set_amount(amount);
286 checkAmount: function(e){
287 if (e.which !== 0 && e.charCode !== 0) {
288 if(isNaN(String.fromCharCode(e.charCode))){
289 return (String.fromCharCode(e.charCode) === "." && e.currentTarget.value.toString().split(".").length < 2)?true:false;
294 changedAmount: function() {
295 if (this.amount !== this.payment_line.get_amount()){
296 this.renderElement();
299 renderElement: function() {
301 this.name = this.payment_line.get_cashregister().get('journal_id')[1];
303 this.$('input').keypress(_.bind(this.checkAmount, this))
304 .keyup(function(event){
305 self.changeAmount(event);
307 this.$('.delete-payment-line').click(function() {
308 self.trigger('delete_payment_line', self);
312 var val = this.$('input')[0].value;
313 this.$('input')[0].focus();
314 this.$('input')[0].value = val;
315 this.$('input')[0].select();
319 module.OrderButtonWidget = module.PosBaseWidget.extend({
320 template:'OrderButtonWidget',
321 init: function(parent, options) {
322 this._super(parent,options);
325 this.order = options.order;
326 this.order.bind('destroy',this.destroy, this );
327 this.order.bind('change', this.renderElement, this );
328 this.pos.bind('change:selectedOrder', this.renderElement,this );
330 renderElement:function(){
333 this.$el.click(function(){
336 if( this.order === this.pos.get('selectedOrder') ){
337 this.$el.addClass('selected-order');
340 selectOrder: function(event) {
342 selectedOrder: this.order
346 this.order.unbind('destroy', this.destroy, this);
347 this.order.unbind('change', this.renderElement, this);
348 this.pos.unbind('change:selectedOrder', this.renderElement, this);
353 module.ActionButtonWidget = instance.web.Widget.extend({
354 template:'ActionButtonWidget',
355 icon_template:'ActionButtonWidgetWithIcon',
356 init: function(parent, options){
357 this._super(parent, options);
358 this.label = options.label || 'button';
359 this.rightalign = options.rightalign || false;
360 this.click_action = options.click;
361 this.disabled = options.disabled || false;
363 this.icon = options.icon;
364 this.template = this.icon_template;
367 set_disabled: function(disabled){
368 if(this.disabled != disabled){
369 this.disabled = !!disabled;
370 this.renderElement();
373 renderElement: function(){
375 if(this.click_action && !this.disabled){
376 this.$el.click(_.bind(this.click_action, this));
381 module.ActionBarWidget = instance.web.Widget.extend({
382 template:'ActionBarWidget',
383 init: function(parent, options){
384 this._super(parent,options);
385 this.button_list = [];
387 this.visibility = {};
389 set_element_visible: function(element, visible, action){
390 if(visible != this.visibility[element]){
391 this.visibility[element] = !!visible;
393 this.$('.'+element).removeClass('oe_hidden');
395 this.$('.'+element).addClass('oe_hidden');
398 if(visible && action){
399 this.action[element] = action;
400 this.$('.'+element).off('click').click(action);
403 set_button_disabled: function(name, disabled){
404 var b = this.buttons[name];
406 b.set_disabled(disabled);
409 destroy_buttons:function(){
410 for(var i = 0; i < this.button_list.length; i++){
411 this.button_list[i].destroy();
413 this.button_list = [];
417 get_button_count: function(){
418 return this.button_list.length;
420 add_new_button: function(button_options){
421 var button = new module.ActionButtonWidget(this,button_options);
422 this.button_list.push(button);
423 if(button_options.name){
424 this.buttons[button_options.name] = button;
426 button.appendTo(this.$('.pos-actionbar-button-list'));
430 this.$el.removeClass('oe_hidden');
433 this.$el.addClass('oe_hidden');
437 module.CategoryButton = module.PosBaseWidget.extend({
439 module.ProductCategoriesWidget = module.PosBaseWidget.extend({
440 template: 'ProductCategoriesWidget',
441 init: function(parent, options){
443 this._super(parent,options);
444 this.product_type = options.product_type || 'all'; // 'all' | 'weightable'
445 this.onlyWeightable = options.onlyWeightable || false;
446 this.category = this.pos.root_category;
447 this.breadcrumb = [];
448 this.subcategories = [];
452 // changes the category. if undefined, sets to root category
453 set_category : function(category){
454 var db = this.pos.db;
456 this.category = db.get_category_by_id(db.root_category_id);
458 this.category = category;
460 this.breadcrumb = [];
461 var ancestors_ids = db.get_category_ancestors_ids(this.category.id);
462 for(var i = 1; i < ancestors_ids.length; i++){
463 this.breadcrumb.push(db.get_category_by_id(ancestors_ids[i]));
465 if(this.category.id !== db.root_category_id){
466 this.breadcrumb.push(this.category);
468 this.subcategories = db.get_category_by_id(db.get_category_childs_ids(this.category.id));
471 get_image_url: function(category){
472 return instance.session.url('/web/binary/image', {model: 'pos.category', field: 'image_medium', id: category.id});
475 renderElement: function(){
479 var hasimages = false; //if none of the subcategories have images, we don't display buttons with icons
480 _.each(this.subcategories, function(category){
486 _.each(this.subcategories, function(category){
488 var button = QWeb.render('CategoryButton',{category:category});
489 var button = _.str.trim(button);
490 var button = $(button);
491 button.find('img').replaceWith(self.pos_widget.image_cache.get_image(self.get_image_url(category)));
493 var button = QWeb.render('CategorySimpleButton',{category:category});
494 button = _.str.trim(button); // we remove whitespace between buttons to fix spacing
495 var button = $(button);
498 button.appendTo(this.$('.category-list')).click(function(event){
499 var id = category.id;
500 var cat = self.pos.db.get_category_by_id(id);
501 self.set_category(cat);
502 self.renderElement();
505 // breadcrumb click actions
506 this.$(".oe-pos-categories-list a").click(function(event){
507 var id = $(event.target).data("category-id");
508 var category = self.pos.db.get_category_by_id(id);
509 self.set_category(category);
510 self.renderElement();
513 this.search_and_categories();
515 if(this.pos.iface_vkeyboard && this.pos_widget.onscreen_keyboard){
516 this.pos_widget.onscreen_keyboard.connect(this.$('.searchbox input'));
520 set_product_type: function(type){ // 'all' | 'weightable'
521 this.product_type = type;
522 this.reset_category();
525 // resets the current category to the root category
526 reset_category: function(){
528 this.renderElement();
531 // empties the content of the search box
532 clear_search: function(){
533 var products = this.pos.db.get_product_by_category(this.category.id);
534 this.pos.get('products').reset(products);
535 this.$('.searchbox input').val('').focus();
536 this.$('.search-clear').fadeOut();
539 // filters the products, and sets up the search callbacks
540 search_and_categories: function(category){
543 // find all products belonging to the current category
544 var products = this.pos.db.get_product_by_category(this.category.id);
545 self.pos.get('products').reset(products);
547 // filter the products according to the search string
548 this.$('.searchbox input').keyup(function(event){
549 query = $(this).val().toLowerCase();
551 if(event.which === 13){
552 if( self.pos.get('products').size() === 1 ){
553 self.pos.get('selectedOrder').addProduct(self.pos.get('products').at(0));
557 var products = self.pos.db.search_product_in_category(self.category.id, query);
558 self.pos.get('products').reset(products);
559 self.$('.search-clear').fadeIn();
562 var products = self.pos.db.get_product_by_category(self.category.id);
563 self.pos.get('products').reset(products);
564 self.$('.search-clear').fadeOut();
568 //reset the search when clicking on reset
569 this.$('.search-clear').click(function(){
575 module.ProductListWidget = module.ScreenWidget.extend({
576 template:'ProductListWidget',
577 init: function(parent, options) {
579 this._super(parent,options);
580 this.model = options.model;
581 this.productwidgets = [];
582 this.weight = options.weight || 0;
583 this.show_scale = options.show_scale || false;
584 this.next_screen = options.next_screen || false;
585 this.click_product_action = options.click_product_action;
587 this.pos.get('products').bind('reset', function(){
588 self.renderElement();
591 renderElement: function() {
595 var products = this.pos.get('products').models || [];
597 _.each(products,function(product,i){
598 var $product = $(QWeb.render('Product',{ widget:self, product: products[i] }));
599 $product.find('img').replaceWith(self.pos_widget.image_cache.get_image(products[i].get_image_url()));
600 $product.appendTo(self.$('.product-list'));
602 this.$el.delegate('a','click',function(){
603 self.click_product_action(new module.Product(self.pos.db.get_product_by_id(+$(this).data('product-id'))));
609 module.UsernameWidget = module.PosBaseWidget.extend({
610 template: 'UsernameWidget',
611 init: function(parent, options){
612 var options = options || {};
613 this._super(parent,options);
614 this.mode = options.mode || 'cashier';
616 set_user_mode: function(mode){
621 this.renderElement();
623 get_name: function(){
625 if(this.mode === 'cashier'){
626 user = this.pos.get('cashier') || this.pos.get('user');
628 user = this.pos.get('selectedOrder').get_client() || this.pos.get('user');
638 module.HeaderButtonWidget = module.PosBaseWidget.extend({
639 template: 'HeaderButtonWidget',
640 init: function(parent, options){
641 options = options || {};
642 this._super(parent, options);
643 this.action = options.action;
644 this.label = options.label;
646 renderElement: function(){
650 this.$el.click(function(){
655 show: function(){ this.$el.removeClass('oe_hidden'); },
656 hide: function(){ this.$el.addClass('oe_hidden'); },
659 // The debug widget lets the user control and monitor the hardware and software status
660 // without the use of the proxy
661 module.DebugWidget = module.PosBaseWidget.extend({
662 template: "DebugWidget",
664 admin_badge: '0410100000006',
665 client_badge: '0420200000004',
666 invalid_ean: '1232456',
667 soda_33cl: '5449000000996',
668 oranges_kg: '2100002031410',
669 lemon_price: '2301000001560',
670 unknown_product: '9900000000004',
674 'scan_item_error_unrecognized',
686 this.$el.draggable();
687 this.$('.toggle').click(function(){
688 var content = self.$('.content');
691 content.animate({'height':'0'},200);
693 content.css({'height':'auto'});
695 self.minimized = !self.minimized;
697 this.$('.button.accept_payment').click(function(){
698 self.pos.proxy.debug_accept_payment();
700 this.$('.button.reject_payment').click(function(){
701 self.pos.proxy.debug_reject_payment();
703 this.$('.button.set_weight').click(function(){
704 var kg = Number(self.$('input.weight').val());
706 self.pos.proxy.debug_set_weight(kg);
709 this.$('.button.reset_weight').click(function(){
710 self.$('input.weight').val('');
711 self.pos.proxy.debug_reset_weight();
713 this.$('.button.custom_ean').click(function(){
714 var ean = self.pos.barcode_reader.sanitize_ean(self.$('input.ean').val() || '0');
715 self.$('input.ean').val(ean);
716 self.pos.barcode_reader.scan('ean13',ean);
718 this.$('.button.reference').click(function(){
719 self.pos.barcode_reader.scan('reference',self.$('input.ean').val());
721 _.each(this.eans, function(ean, name){
722 self.$('.button.'+name).click(function(){
723 self.$('input.ean').val(ean);
724 self.pos.barcode_reader.scan('ean13',ean);
727 _.each(this.events, function(name){
728 self.pos.proxy.add_notification(name,function(){
729 self.$('.event.'+name).stop().clearQueue().css({'background-color':'#6CD11D'});
730 self.$('.event.'+name).animate({'background-color':'#1E1E1E'},2000);
733 self.pos.proxy.add_notification('help_needed',function(){
734 self.$('.status.help_needed').addClass('on');
736 self.pos.proxy.add_notification('help_canceled',function(){
737 self.$('.status.help_needed').removeClass('on');
739 self.pos.proxy.add_notification('transaction_start',function(){
740 self.$('.status.transaction').addClass('on');
742 self.pos.proxy.add_notification('transaction_end',function(){
743 self.$('.status.transaction').removeClass('on');
745 self.pos.proxy.add_notification('weighting_start',function(){
746 self.$('.status.weighting').addClass('on');
748 self.pos.proxy.add_notification('weighting_end',function(){
749 self.$('.status.weighting').removeClass('on');
754 // ---------- Main Point of Sale Widget ----------
756 // this is used to notify the user that data is being synchronized on the network
757 module.SynchNotificationWidget = module.PosBaseWidget.extend({
758 template: "SynchNotificationWidget",
759 init: function(parent, options){
760 options = options || {};
761 this._super(parent, options);
763 renderElement: function() {
766 this.$el.click(function(){
772 this.pos.bind('change:nbr_pending_operations', function(){
773 self.renderElement();
776 get_nbr_pending: function(){
777 return this.pos.get('nbr_pending_operations');
782 // The PosWidget is the main widget that contains all other widgets in the PointOfSale.
783 // It is mainly composed of :
784 // - a header, containing the list of orders
785 // - a leftpane, containing the list of bought products (orderlines)
786 // - a rightpane, containing the screens (see pos_screens.js)
787 // - an actionbar on the bottom, containing various action buttons
789 // - an onscreen keyboard
790 // a screen_selector which controls the switching between screens and the showing/closing of popups
792 module.PosWidget = module.PosBaseWidget.extend({
793 template: 'PosWidget',
795 this._super(arguments[0],{});
797 instance.web.blockUI();
799 this.pos = new module.PosModel(this.session);
800 this.pos.pos_widget = this;
801 this.pos_widget = this; //So that pos_widget's childs have pos_widget set automatically
803 this.numpad_visible = true;
804 this.left_action_bar_visible = true;
805 this.leftpane_visible = true;
806 this.leftpane_width = '440px';
807 this.cashier_controls_visible = true;
808 this.image_cache = new module.ImageCache(); // for faster products image display
810 FastClick.attach(document.body);
816 return self.pos.ready.done(function() {
817 $('.oe_tooltip').remove(); // remove tooltip from the start session button
819 self.build_currency_template();
820 self.renderElement();
822 self.$('.neworder-button').click(function(){
823 self.pos.add_new_order();
826 self.$('.deleteorder-button').click(function(){
827 self.pos.delete_current_order();
830 //when a new order is created, add an order button widget
831 self.pos.get('orders').bind('add', function(new_order){
832 var new_order_button = new module.OrderButtonWidget(null, {
836 new_order_button.appendTo(this.$('.orders'));
837 new_order_button.selectOrder();
840 self.pos.add_new_order();
842 self.build_widgets();
844 if(self.pos.iface_big_scrollbars){
845 self.$el.addClass('big-scrollbars');
848 self.screen_selector.set_default_screen();
851 self.pos.barcode_reader.connect();
853 instance.webclient.set_content_full_screen(true);
855 if (!self.pos.get('pos_session')) {
856 self.screen_selector.show_popup('error', 'Sorry, we could not create a user session');
857 }else if(!self.pos.get('pos_config')){
858 self.screen_selector.show_popup('error', 'Sorry, we could not find any PoS Configuration for this session');
861 instance.web.unblockUI();
862 self.$('.loader').animate({opacity:0},1500,'swing',function(){self.$('.loader').addClass('oe_hidden');});
866 }).fail(function(){ // error when loading models data from the backend
867 instance.web.unblockUI();
868 return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_session_opening']], ['res_id'])
869 .pipe( _.bind(function(res){
870 return instance.session.rpc('/web/action/load', {'action_id': res[0]['res_id']})
871 .pipe(_.bind(function(result){
872 var action = result.result;
873 this.do_action(action);
879 // This method instantiates all the screens, widgets, etc. If you want to add new screens change the
880 // startup screen, etc, override this method.
881 build_widgets: function() {
884 // -------- Screens ---------
886 this.product_screen = new module.ProductScreenWidget(this,{});
887 this.product_screen.appendTo(this.$('.screens'));
889 this.receipt_screen = new module.ReceiptScreenWidget(this, {});
890 this.receipt_screen.appendTo(this.$('.screens'));
892 this.payment_screen = new module.PaymentScreenWidget(this, {});
893 this.payment_screen.appendTo(this.$('.screens'));
895 this.welcome_screen = new module.WelcomeScreenWidget(this,{});
896 this.welcome_screen.appendTo(this.$('.screens'));
898 this.client_payment_screen = new module.ClientPaymentScreenWidget(this, {});
899 this.client_payment_screen.appendTo(this.$('.screens'));
901 this.scale_invite_screen = new module.ScaleInviteScreenWidget(this, {});
902 this.scale_invite_screen.appendTo(this.$('.screens'));
904 this.scale_screen = new module.ScaleScreenWidget(this,{});
905 this.scale_screen.appendTo(this.$('.screens'));
907 // -------- Popups ---------
909 this.help_popup = new module.HelpPopupWidget(this, {});
910 this.help_popup.appendTo(this.$el);
912 this.error_popup = new module.ErrorPopupWidget(this, {});
913 this.error_popup.appendTo(this.$el);
915 this.error_product_popup = new module.ProductErrorPopupWidget(this, {});
916 this.error_product_popup.appendTo(this.$el);
918 this.error_session_popup = new module.ErrorSessionPopupWidget(this, {});
919 this.error_session_popup.appendTo(this.$el);
921 this.choose_receipt_popup = new module.ChooseReceiptPopupWidget(this, {});
922 this.choose_receipt_popup.appendTo(this.$el);
924 this.error_negative_price_popup = new module.ErrorNegativePricePopupWidget(this, {});
925 this.error_negative_price_popup.appendTo(this.$el);
927 this.error_no_client_popup = new module.ErrorNoClientPopupWidget(this, {});
928 this.error_no_client_popup.appendTo(this.$el);
930 this.error_invoice_transfer_popup = new module.ErrorInvoiceTransferPopupWidget(this, {});
931 this.error_invoice_transfer_popup.appendTo(this.$el);
933 // -------- Misc ---------
935 this.notification = new module.SynchNotificationWidget(this,{});
936 this.notification.appendTo(this.$('.pos-rightheader'));
938 this.username = new module.UsernameWidget(this,{});
939 this.username.replace(this.$('.placeholder-UsernameWidget'));
941 this.action_bar = new module.ActionBarWidget(this);
942 this.action_bar.replace(this.$(".placeholder-RightActionBar"));
944 this.left_action_bar = new module.ActionBarWidget(this);
945 this.left_action_bar.replace(this.$('.placeholder-LeftActionBar'));
947 this.paypad = new module.PaypadWidget(this, {});
948 this.paypad.replace(this.$('.placeholder-PaypadWidget'));
950 this.numpad = new module.NumpadWidget(this);
951 this.numpad.replace(this.$('.placeholder-NumpadWidget'));
953 this.order_widget = new module.OrderWidget(this, {});
954 this.order_widget.replace(this.$('.placeholder-OrderWidget'));
956 this.onscreen_keyboard = new module.OnscreenKeyboardWidget(this, {
957 'keyboard_model': 'simple'
959 this.onscreen_keyboard.replace(this.$('.placeholder-OnscreenKeyboardWidget'));
961 this.close_button = new module.HeaderButtonWidget(this,{
963 action: function(){ self.close(); },
965 this.close_button.appendTo(this.$('.pos-rightheader'));
967 this.client_button = new module.HeaderButtonWidget(this,{
968 label: _t('Self-Checkout'),
969 action: function(){ self.screen_selector.set_user_mode('client'); },
971 this.client_button.appendTo(this.$('.pos-rightheader'));
974 // -------- Screen Selector ---------
976 this.screen_selector = new module.ScreenSelector({
979 'products': this.product_screen,
980 'payment' : this.payment_screen,
981 'client_payment' : this.client_payment_screen,
982 'scale_invite' : this.scale_invite_screen,
983 'scale': this.scale_screen,
984 'receipt' : this.receipt_screen,
985 'welcome' : this.welcome_screen,
988 'help': this.help_popup,
989 'error': this.error_popup,
990 'error-product': this.error_product_popup,
991 'error-session': this.error_session_popup,
992 'error-negative-price': this.error_negative_price_popup,
993 'choose-receipt': this.choose_receipt_popup,
994 'error-no-client': this.error_no_client_popup,
995 'error-invoice-transfer': this.error_invoice_transfer_popup,
997 default_client_screen: 'welcome',
998 default_cashier_screen: 'products',
999 default_mode: this.pos.iface_self_checkout ? 'client' : 'cashier',
1003 this.debug_widget = new module.DebugWidget(this);
1004 this.debug_widget.appendTo(this.$('.pos-content'));
1008 changed_pending_operations: function () {
1010 this.synch_notification.on_change_nbr_pending(self.pos.get('nbr_pending_operations').length);
1012 // shows or hide the numpad and related controls like the paypad.
1013 set_numpad_visible: function(visible){
1014 if(visible !== this.numpad_visible){
1015 this.numpad_visible = visible;
1017 this.set_left_action_bar_visible(false);
1020 this.order_widget.set_display_mode('numpad');
1024 if(this.order_widget.display_mode === 'numpad'){
1025 this.order_widget.set_display_mode('maximized');
1030 set_left_action_bar_visible: function(visible){
1031 if(visible !== this.left_action_bar_visible){
1032 this.left_action_bar_visible = visible;
1034 this.set_numpad_visible(false);
1035 this.left_action_bar.show();
1036 this.order_widget.set_display_mode('actionbar');
1038 this.left_action_bar.hide();
1039 if(this.order_widget.display_mode === 'actionbar'){
1040 this.order_widget.set_display_mode('maximized');
1046 //shows or hide the leftpane (contains the list of orderlines, the numpad, the paypad, etc.)
1047 set_leftpane_visible: function(visible){
1048 if(visible !== this.leftpane_visible){
1049 this.leftpane_visible = visible;
1051 this.$('.pos-leftpane').removeClass('oe_hidden').animate({'width':this.leftpane_width},500,'swing');
1052 this.$('.pos-rightpane').animate({'left':this.leftpane_width},500,'swing');
1054 var leftpane = this.$('.pos-leftpane');
1055 leftpane.animate({'width':'0px'},500,'swing', function(){ leftpane.addClass('oe_hidden'); });
1056 this.$('.pos-rightpane').animate({'left':'0px'},500,'swing');
1060 //shows or hide the controls in the PosWidget that are specific to the cashier ( Orders, close button, etc. )
1061 set_cashier_controls_visible: function(visible){
1062 if(visible !== this.cashier_controls_visible){
1063 this.cashier_controls_visible = visible;
1065 this.$('.pos-rightheader').removeClass('oe_hidden');
1067 this.$('.pos-rightheader').addClass('oe_hidden');
1075 return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_client_pos_menu']], ['res_id']).pipe(
1076 _.bind(function(res) {
1077 return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
1078 var action = result;
1079 action.context = _.extend(action.context || {}, {'cancel_action': {type: 'ir.actions.client', tag: 'reload'}});
1081 this.do_action(action);
1086 var draft_order = _.find( self.pos.get('orders').models, function(order){
1087 return order.get('orderLines').length !== 0 && order.get('paymentLines').length === 0;
1090 if (confirm(_t("Pending orders will be lost.\nAre you sure you want to leave this session?"))) {
1097 destroy: function() {
1099 instance.webclient.set_content_full_screen(false);