blob: 472f7cad6a8f9f35b27547870d2343cffe40fe90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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) {
return super.nextScreen;
}
// Take the first payment method as the main payment.
const mainPayment = order.get_paymentlines()[0];
if (mainPayment.canBeAdjusted()) {
return 'TipScreen';
}
return super.nextScreen;
}
};
Registries.Component.extend(PaymentScreen, PosResPaymentScreen);
return PosResPaymentScreen;
});
|