From cf5dbef72bcb92859c18c948df58e9dc7203701e Mon Sep 17 00:00:00 2001 From: andreparames Date: Wed, 14 Mar 2018 15:05:45 +0100 Subject: [PATCH] pos_payment_terminal: inform user of transaction status --- .../static/src/js/pos_payment_terminal.js | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/pos_payment_terminal/static/src/js/pos_payment_terminal.js b/pos_payment_terminal/static/src/js/pos_payment_terminal.js index adace081..ef30340f 100755 --- a/pos_payment_terminal/static/src/js/pos_payment_terminal.js +++ b/pos_payment_terminal/static/src/js/pos_payment_terminal.js @@ -24,23 +24,36 @@ odoo.define('pos_payment_terminal.pos_payment_terminal', function (require) { var self = this; self._super(parents, options); self.on('change:status', this, function(eh, status) { + if(!self.pos.chrome.screens) { + return; + } + var paymentwidget = self.pos.chrome.screens.payment; var drivers = status.newValue.drivers; var order = self.pos.get_order(); + var in_transaction = false; Object.keys(drivers).forEach(function(driver_name) { + if (drivers[driver_name].hasOwnProperty("in_transaction")) { + in_transaction = in_transaction || drivers[driver_name].in_transaction; + } + var transactions = drivers[driver_name].latest_transactions; if(!!transactions && transactions.hasOwnProperty(order.uid)) { order.transactions = transactions[order.uid]; + var order_total = Math.round(order.get_total_with_tax() * 100.0); var paid_total = order.transactions.map(function(t) { return t.amount_cents; }).reduce(function add(a, b) { return a + b; }, 0); + if(order_total === paid_total) { - self.pos.chrome.screens.payment.validate_order(); + paymentwidget.validate_order(); } } }); + order.in_transaction = in_transaction; + paymentwidget.order_changes(); }); }, payment_terminal_transaction_start: function(line_cid, currency_iso, currency_decimals){ @@ -66,22 +79,40 @@ odoo.define('pos_payment_terminal.pos_payment_terminal', function (require) { screens.PaymentScreenWidget.include({ render_paymentlines : function(){ - this._super.apply(this, arguments); + this._super.apply(this, arguments); var self = this; this.$('.paymentlines-container').unbind('click').on('click', '.payment-terminal-transaction-start', function(event){ // Why this "on" thing links severaltime the button to the action if I don't use "unlink" to reset the button links before ? //console.log(event.target); + self.pos.get_order().in_transaction = true; + self.order_changes(); self.pos.proxy.payment_terminal_transaction_start($(this).data('cid'), self.pos.currency.name, self.pos.currency.decimals); }); }, + order_changes: function(){ + this._super.apply(this, arguments); + var order = this.pos.get_order(); + if (!order) { + return; + } else if (order.in_transaction) { + self.$('.next').html(''); + } else { + self.$('.next').html('Validate '); + } + } }); var _orderproto = models.Order.prototype; models.Order = models.Order.extend({ + initialize: function(){ + _orderproto.initialize.apply(this, arguments); + this.in_transaction = false; + }, export_as_JSON: function() { var vals = _orderproto.export_as_JSON.apply(this, arguments); vals['transactions'] = this.transactions || {}; return vals; } - }) + }); + });