Debian Codegraph @

addons/pos_viva_com/static/src/app/screens/payment_screen/payment_screen.js

raw
1 import { PaymentScreen } from "@point_of_sale/app/screens/payment_screen/payment_screen";
2 import { patch } from "@web/core/utils/patch";
3 import { onMounted } from "@odoo/owl";
4
5 patch(PaymentScreen.prototype, {
6 setup() {
7 super.setup(...arguments);
8 onMounted(() => {
9 const pendingPaymentLine = this.currentOrder.payment_ids.find(
10 (paymentLine) =>
11 paymentLine.payment_method_id.use_payment_terminal === "viva_com" &&
12 !paymentLine.isDone() &&
13 paymentLine.getPaymentStatus() !== "pending"
14 );
15 if (!pendingPaymentLine) {
16 return;
17 }
18 });
19 },
20
21 async addNewPaymentLine(paymentMethod) {
22 if (paymentMethod.use_payment_terminal === "viva_com" && this.isRefundOrder) {
23 const refundedOrder = this.currentOrder.lines[0]?.refunded_orderline_id?.order_id;
24 const amountDue = Math.abs(this.currentOrder.remainingDue);
25 const matchedPaymentLine = refundedOrder.payment_ids.find(
26 (line) =>
27 line.payment_method_id.use_payment_terminal === "viva_com" &&
28 line.amount === amountDue
29 );
30 if (matchedPaymentLine) {
31 const paymentLineAddedSuccessfully = await super.addNewPaymentLine(paymentMethod);
32 if (paymentLineAddedSuccessfully) {
33 const newPaymentLine = this.paymentLines.at(-1);
34 newPaymentLine.updateRefundPaymentLine(matchedPaymentLine);
35 }
36 return paymentLineAddedSuccessfully;
37 }
38 }
39
40 return await super.addNewPaymentLine(paymentMethod);
41 },
42 });