diff options
| author | Antoine Prieels <anp@odoo.com> | 2020-08-27 09:50:57 +0000 |
|---|---|---|
| committer | Antoine Prieels <anp@odoo.com> | 2020-08-28 06:18:48 +0000 |
| commit | eaae65941177dcf89d03251343de3cb4e7866003 (patch) | |
| tree | b2e8f16a5e74882b00b68f2d670ca42d5809b7c8 /addons/pos_restaurant/static/src/js/Screens | |
| parent | 9b67f6ee0783e8b02edb260b3ba5a0322187a416 (diff) | |
[IMP] pos_restaurant(_adyen): Keep tab open
As long as the payment is not validated, the cashier can add products
to the order, even if the payment has been completed. The amount
authorized can be adjusted if the payment interface implements the
canBeAdjusted method.
closes odoo/odoo#56639
Taskid: 2117032
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_restaurant/static/src/js/Screens')
3 files changed, 36 insertions, 1 deletions
diff --git a/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js b/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js index 257f028f291..472f7cad6a8 100644 --- a/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js +++ b/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js @@ -2,10 +2,32 @@ odoo.define('pos_restaurant.PosResPaymentScreen', function (require) { 'use strict'; const PaymentScreen = require('point_of_sale.PaymentScreen'); + const { useListener } = require('web.custom_hooks'); const Registries = require('point_of_sale.Registries'); const PosResPaymentScreen = (PaymentScreen) => class extends PaymentScreen { + constructor() { + super(...arguments); + useListener('send-payment-adjust', this._sendPaymentAdjust); + } + + async _sendPaymentAdjust({ detail: line }) { + const previous_amount = line.get_amount(); + const amount_diff = line.order.get_total_with_tax() - line.order.get_total_paid(); + line.set_amount(previous_amount + amount_diff); + line.set_payment_status('waiting'); + + const payment_terminal = line.payment_method.payment_terminal; + const isAdjustSuccessful = await payment_terminal.send_payment_adjust(line.cid); + if (isAdjustSuccessful) { + line.set_payment_status('done'); + } else { + line.set_amount(previous_amount); + line.set_payment_status('done'); + } + } + get nextScreen() { const order = this.currentOrder; if (!this.env.pos.config.set_tip_after_payment || order.is_tipped) { @@ -13,7 +35,7 @@ odoo.define('pos_restaurant.PosResPaymentScreen', function (require) { } // Take the first payment method as the main payment. const mainPayment = order.get_paymentlines()[0]; - if (mainPayment.canBeTipped()) { + if (mainPayment.canBeAdjusted()) { return 'TipScreen'; } return super.nextScreen; diff --git a/addons/pos_restaurant/static/src/js/Screens/TicketScreen.js b/addons/pos_restaurant/static/src/js/Screens/TicketScreen.js index b3f7e128a81..83ca91882bf 100644 --- a/addons/pos_restaurant/static/src/js/Screens/TicketScreen.js +++ b/addons/pos_restaurant/static/src/js/Screens/TicketScreen.js @@ -73,6 +73,13 @@ odoo.define('pos_restaurant.TicketScreen', function (require) { } async setTip(order, serverId, amount) { try { + const paymentline = order.get_paymentlines()[0]; + if (paymentline.payment_method.payment_terminal) { + paymentline.amount += amount; + this.env.pos.set_order(order, {silent: true}); + await paymentline.payment_method.payment_terminal.send_payment_adjust(paymentline.cid); + } + if (!amount) { await this.setNoTip(); } else { diff --git a/addons/pos_restaurant/static/src/js/Screens/TipScreen.js b/addons/pos_restaurant/static/src/js/Screens/TipScreen.js index 84091103542..ae3561e233a 100644 --- a/addons/pos_restaurant/static/src/js/Screens/TipScreen.js +++ b/addons/pos_restaurant/static/src/js/Screens/TipScreen.js @@ -75,6 +75,12 @@ odoo.define('pos_restaurant.TipScreen', function (require) { order.set_tip(amount); order.finalized = true; + const paymentline = this.env.pos.get_order().get_paymentlines()[0]; + if (paymentline.payment_method.payment_terminal) { + paymentline.amount += amount; + await paymentline.payment_method.payment_terminal.send_payment_adjust(paymentline.cid); + } + // set_tip calls add_product which sets the new line as the selected_orderline const tip_line = order.selected_orderline; await this.rpc({ |
