From fcd8540c79221295007aa1182b0f1fe8db4bce72 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 12 Jun 2015 12:28:36 +0200 Subject: [PATCH] Cleaner inheritance implementation in pos_customer_display Better debug logs in hw_* modules for LCD and Telium --- hw_customer_display/controllers/main.py | 4 +- .../controllers/main.py | 5 +- .../static/src/js/customer_display.js | 85 ++++++++++--------- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/hw_customer_display/controllers/main.py b/hw_customer_display/controllers/main.py index 6d40289b..e2184f7b 100644 --- a/hw_customer_display/controllers/main.py +++ b/hw_customer_display/controllers/main.py @@ -174,5 +174,7 @@ class CustomerDisplayProxy(hw_proxy.Proxy): '/hw_proxy/send_text_customer_display', type='json', auth='none', cors='*') def send_text_customer_display(self, text_to_display): - logger.debug('LCD: Call send_text_customer_display') + logger.debug( + 'LCD: Call send_text_customer_display with text=%s', + text_to_display) driver.push_task('display', text_to_display) diff --git a/hw_telium_payment_terminal/controllers/main.py b/hw_telium_payment_terminal/controllers/main.py index 3dbd1b7f..2d916535 100644 --- a/hw_telium_payment_terminal/controllers/main.py +++ b/hw_telium_payment_terminal/controllers/main.py @@ -224,7 +224,6 @@ class TeliumPaymentTerminalDriver(Thread): payment_info_dict = simplejson.loads(payment_info) assert isinstance(payment_info_dict, dict), \ 'payment_info_dict should be a dict' - logger.debug("payment_info_dict = %s" % payment_info_dict) try: logger.debug( 'Opening serial port %s for payment terminal with baudrate %d' @@ -280,5 +279,7 @@ class TeliumPaymentTerminalProxy(hw_proxy.Proxy): '/hw_proxy/payment_terminal_transaction_start', type='json', auth='none', cors='*') def payment_terminal_transaction_start(self, payment_info): - logger.debug('Telium: Call payment_terminal_transaction_start') + logger.debug( + 'Telium: Call payment_terminal_transaction_start with ' + 'payment_info=%s', payment_info) driver.push_task('transaction_start', payment_info) diff --git a/pos_customer_display/static/src/js/customer_display.js b/pos_customer_display/static/src/js/customer_display.js index 7f6723c8..9f6afed4 100755 --- a/pos_customer_display/static/src/js/customer_display.js +++ b/pos_customer_display/static/src/js/customer_display.js @@ -199,51 +199,52 @@ openerp.pos_customer_display = function(instance){ return res; }; - var _super_update_payment_summary_ = module.PaymentScreenWidget.prototype.update_payment_summary; - module.PaymentScreenWidget.prototype.update_payment_summary = function(){ - res = _super_update_payment_summary_.call(this); - var currentOrder = this.pos.get('selectedOrder'); - var paidTotal = currentOrder.getPaidTotal(); - var dueTotal = currentOrder.getTotalTaxIncluded(); - var change = paidTotal > dueTotal ? paidTotal - dueTotal : 0; - if (change) { - change_rounded = change.toFixed(2); - this.pos.prepare_text_customer_display('update_payment', {'change': change_rounded}); - } - return res; - }; + module.PaymentScreenWidget.include({ + update_payment_summary: function(){ + res = this._super(); + var currentOrder = this.pos.get('selectedOrder'); + var paidTotal = currentOrder.getPaidTotal(); + var dueTotal = currentOrder.getTotalTaxIncluded(); + var change = paidTotal > dueTotal ? paidTotal - dueTotal : 0; + if (change) { + change_rounded = change.toFixed(2); + this.pos.prepare_text_customer_display('update_payment', {'change': change_rounded}); + } + return res; + }, + }); - var _super_closePOS_ = module.PosWidget.prototype.close; - module.PosWidget.prototype.close = function(){ - this.pos.prepare_text_customer_display('closePOS', {}); - return _super_closePOS_.call(this); - }; + module.PosWidget.include({ + close: function(){ + this._super(); + this.pos.prepare_text_customer_display('closePOS', {}); + }, + }); - var _super_proxy_start_ = module.ProxyStatusWidget.prototype.start; - module.ProxyStatusWidget.prototype.start = function(){ - res = _super_proxy_start_.call(this); - this.pos.prepare_text_customer_display('openPOS', {}); - return res; - }; + module.ProxyStatusWidget.include({ + start: function(){ + this._super(); + this.pos.prepare_text_customer_display('openPOS', {}); + }, + }); /* Handle Button "Display Total to Customer" */ - var _super_OrderWidget_init_ = module.OrderWidget.prototype.init; - module.OrderWidget.prototype.init = function(parent, options){ - _super_OrderWidget_init_.call(this, parent, options); - var self = this; - this.prepare_text_customer_display = function(event){ - self.pos.prepare_text_customer_display('addPaymentline', {}); - event.stopPropagation(); - }; - }; - - var _super_update_summary_ = module.OrderWidget.prototype.update_summary; - module.OrderWidget.prototype.update_summary = function(){ - _super_update_summary_.call(this); - if (this.pos.config.iface_customer_display){ - this.el.querySelector('.show-total-to-customer') - .addEventListener('click', this.prepare_text_customer_display); - } - }; + /* TODO: understand why Odoo sends the prepare_text_customer_display + 3 times to the Posbox/LCD when the user clicks on the button + 'Show total to customer' */ + module.OrderWidget.include({ + update_summary: function(){ + console.log('MY update_summary'); + this._super(); + var self = this; + if (this.pos.config.iface_customer_display){ + console.log('.addEventListener'); + this.el.querySelector('.show-total-to-customer') + .removeEventListener('click', function(){self.pos.prepare_text_customer_display('addPaymentline', {})}); + this.el.querySelector('.show-total-to-customer') + .addEventListener('click', function(){self.pos.prepare_text_customer_display('addPaymentline', {})}); + } + }, + }); };