Browse Source

pos_payment_terminal: inform user of transaction status

pull/389/head
andreparames 7 years ago
committed by Denis Roussel
parent
commit
cf5dbef72b
  1. 35
      pos_payment_terminal/static/src/js/pos_payment_terminal.js

35
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){
@ -71,17 +84,35 @@ odoo.define('pos_payment_terminal.pos_payment_terminal', function (require) {
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('<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;
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;
}
})
});
});
Loading…
Cancel
Save