From 7655963ef90791db7f1bc48528829911c80f36dc Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Fri, 25 Feb 2022 10:24:14 +0000 Subject: [PATCH] [FIX] point_of_sale: payment by terminal when settle due When we want to settle the amount due by a customer, we can choose a payment method through a Popup. When the payement method choosed in the popup is linked to a terminal the payment line is added, but don't have a correct status, so we cannot send the request to the terminal. To correctly add the payment and related status, we are moving some logic that was set in the payment screen into the method that create the payment line on the order. closes odoo/odoo#85873 X-original-commit: 325772042c3d55034842e5710ab398237531e494 Signed-off-by: Masereel Pierre --- .../js/Screens/PaymentScreen/PaymentScreen.js | 15 +++++-------- addons/point_of_sale/static/src/js/models.js | 22 +++++++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js index 3155f111ab8..819f28d9952 100644 --- a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js @@ -58,20 +58,17 @@ odoo.define('point_of_sale.PaymentScreen', function (require) { } addNewPaymentLine({ detail: paymentMethod }) { // original function: click_paymentmethods - if (this.currentOrder.electronic_payment_in_progress()) { + let result = this.currentOrder.add_paymentline(paymentMethod); + if (result){ + NumberBuffer.reset(); + return true; + } + else{ this.showPopup('ErrorPopup', { title: this.env._t('Error'), body: this.env._t('There is already an electronic payment in progress.'), }); return false; - } else { - this.currentOrder.add_paymentline(paymentMethod); - NumberBuffer.reset(); - this.payment_interface = paymentMethod.payment_terminal; - if (this.payment_interface) { - this.currentOrder.selected_paymentline.set_payment_status('pending'); - } - return true; } } _updateSelectedPaymentline() { diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 4a57b3a8868..fc3f92d33ba 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2619,14 +2619,22 @@ class Order extends PosModel { /* ---- Payment Lines --- */ add_paymentline(payment_method) { this.assert_editable(); - var newPaymentline = Payment.create({},{order: this, payment_method:payment_method, pos: this.pos}); - this.paymentlines.add(newPaymentline); - this.select_paymentline(newPaymentline); - if(this.pos.config.cash_rounding){ - this.selected_paymentline.set_amount(0); + if (this.electronic_payment_in_progress()) { + return false; + } else { + var newPaymentline = Payment.create({},{order: this, payment_method:payment_method, pos: this.pos}); + this.paymentlines.add(newPaymentline); + this.select_paymentline(newPaymentline); + if(this.pos.config.cash_rounding){ + this.selected_paymentline.set_amount(0); + } + newPaymentline.set_amount(this.get_due()); + + if (payment_method.payment_terminal) { + newPaymentline.set_payment_status('pending'); + } + return newPaymentline; } - newPaymentline.set_amount(this.get_due()); - return newPaymentline; } get_paymentlines(){ return this.paymentlines;