Browse Source

pos_payment_terminal: inform user of transaction status

pull/440/head
andreparames 7 years ago
committed by Sylvain LE GAL
parent
commit
31dbfa32de
  1. 37
      pos_payment_terminal/static/src/js/pos_payment_terminal.js

37
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; var self = this;
self._super(parents, options); self._super(parents, options);
self.on('change:status', this, function(eh, status) { 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 drivers = status.newValue.drivers;
var order = self.pos.get_order(); var order = self.pos.get_order();
var in_transaction = false;
Object.keys(drivers).forEach(function(driver_name) { 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; var transactions = drivers[driver_name].latest_transactions;
if(!!transactions && transactions.hasOwnProperty(order.uid)) { if(!!transactions && transactions.hasOwnProperty(order.uid)) {
order.transactions = transactions[order.uid]; order.transactions = transactions[order.uid];
var order_total = Math.round(order.get_total_with_tax() * 100.0); var order_total = Math.round(order.get_total_with_tax() * 100.0);
var paid_total = order.transactions.map(function(t) { var paid_total = order.transactions.map(function(t) {
return t.amount_cents; return t.amount_cents;
}).reduce(function add(a, b) { }).reduce(function add(a, b) {
return a + b; return a + b;
}, 0); }, 0);
if(order_total === paid_total) { 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){ 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({ screens.PaymentScreenWidget.include({
render_paymentlines : function(){ render_paymentlines : function(){
this._super.apply(this, arguments);
this._super.apply(this, arguments);
var self = this; var self = this;
this.$('.paymentlines-container').unbind('click').on('click', '.payment-terminal-transaction-start', function(event){ 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 ? // 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); //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); 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('<img src="/web/static/src/img/spin.png" style="animation: fa-spin 1s infinite steps(12);width: 20px;height: auto;vertical-align: middle;">');
} else {
self.$('.next').html('Validate <i class="fa fa-angle-double-right"></i>');
}
}
}); });
var _orderproto = models.Order.prototype; var _orderproto = models.Order.prototype;
models.Order = models.Order.extend({ models.Order = models.Order.extend({
initialize: function(){
_orderproto.initialize.apply(this, arguments);
this.in_transaction = false;
},
export_as_JSON: function() { export_as_JSON: function() {
var vals = _orderproto.export_as_JSON.apply(this, arguments); var vals = _orderproto.export_as_JSON.apply(this, arguments);
vals['transactions'] = this.transactions || {}; vals['transactions'] = this.transactions || {};
return vals; return vals;
} }
})
});
}); });
Loading…
Cancel
Save