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 | |
| 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')
5 files changed, 66 insertions, 3 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({ diff --git a/addons/pos_restaurant/static/src/js/floors.js b/addons/pos_restaurant/static/src/js/floors.js index 7e4d73271b0..d271f88fe39 100644 --- a/addons/pos_restaurant/static/src/js/floors.js +++ b/addons/pos_restaurant/static/src/js/floors.js @@ -381,11 +381,15 @@ models.PosModel = models.PosModel.extend({ var _super_paymentline = models.Paymentline.prototype; models.Paymentline = models.Paymentline.extend({ /** - * Override this method to be able to show the tip screen which allow + * Override this method to be able to show the 'Adjust Authorisation' button + * on a validated payment_line and to show the tip screen which allow * tipping even after payment. By default, this returns true for all * non-cash payment. */ - canBeTipped: function() { + canBeAdjusted: function() { + if (this.payment_method.payment_terminal) { + return this.payment_method.payment_terminal.canBeAdjusted(this.cid); + } return !this.payment_method.is_cash_count; }, }); diff --git a/addons/pos_restaurant/static/src/js/payment.js b/addons/pos_restaurant/static/src/js/payment.js new file mode 100644 index 00000000000..355d67425d2 --- /dev/null +++ b/addons/pos_restaurant/static/src/js/payment.js @@ -0,0 +1,24 @@ +odoo.define('pos_restaurant.PaymentInterface', function (require) { + "use strict"; + + var PaymentInterface = require('point_of_sale.PaymentInterface'); + + PaymentInterface.include({ + /** + * Return true if the amount that was authorized can be modified, + * false otherwise + * @param {string} cid - The id of the paymentline + */ + canBeAdjusted(cid) { + return false; + }, + + /** + * Called when the amount authorized by a payment request should + * be adjusted to account for a new order line, it can only be called if + * canBeAdjusted returns True + * @param {string} cid - The id of the paymentline + */ + send_payment_adjust: function (cid) {}, + }); +}); |
