| 1 |
import { registry } from "@web/core/registry"; |
| 2 |
import { Base } from "./related_models"; |
| 3 |
const { DateTime } = luxon; |
| 4 |
|
| 5 |
export class PosPayment extends Base { |
| 6 |
static pythonModel = "pos.payment"; |
| 7 |
|
| 8 |
setup(vals) { |
| 9 |
super.setup(...arguments); |
| 10 |
this.payment_date = DateTime.now(); |
| 11 |
this.amount = vals.amount || 0; |
| 12 |
this.ticket = vals.ticket || ""; |
| 13 |
} |
| 14 |
|
| 15 |
isSelected() { |
| 16 |
return this.pos_order_id?.uiState?.selected_paymentline_uuid === this.uuid; |
| 17 |
} |
| 18 |
|
| 19 |
setAmount(value) { |
| 20 |
this.pos_order_id.assertEditable(); |
| 21 |
this.amount = this.pos_order_id.currency.round(parseFloat(value) || 0); |
| 22 |
} |
| 23 |
|
| 24 |
getAmount() { |
| 25 |
return this.amount || 0; |
| 26 |
} |
| 27 |
|
| 28 |
getPaymentStatus() { |
| 29 |
return this.payment_status; |
| 30 |
} |
| 31 |
|
| 32 |
setPaymentStatus(value) { |
| 33 |
this.payment_status = value; |
| 34 |
} |
| 35 |
|
| 36 |
isDone() { |
| 37 |
return this.getPaymentStatus() |
| 38 |
? this.getPaymentStatus() === "done" || this.getPaymentStatus() === "reversed" |
| 39 |
: true; |
| 40 |
} |
| 41 |
|
| 42 |
setCashierReceipt(value) { |
| 43 |
this.cashier_receipt = value; |
| 44 |
} |
| 45 |
|
| 46 |
setReceiptInfo(value) { |
| 47 |
this.ticket += value; |
| 48 |
} |
| 49 |
|
| 50 |
isElectronic() { |
| 51 |
return Boolean(this.getPaymentStatus()); |
| 52 |
} |
| 53 |
|
| 54 |
async pay() { |
| 55 |
this.setPaymentStatus("waiting"); |
| 56 |
|
| 57 |
return this.handlePaymentResponse( |
| 58 |
await this.payment_method_id.payment_terminal.sendPaymentRequest(this.uuid) |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
handlePaymentResponse(isPaymentSuccessful) { |
| 63 |
if (isPaymentSuccessful) { |
| 64 |
this.setPaymentStatus("done"); |
| 65 |
if (this.payment_method_id.payment_method_type !== "qr_code") { |
| 66 |
this.can_be_reversed = this.payment_method_id.payment_terminal.supports_reversals; |
| 67 |
} |
| 68 |
} else { |
| 69 |
this.setPaymentStatus("retry"); |
| 70 |
} |
| 71 |
return isPaymentSuccessful; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* @param {object} - refundedPaymentLine |
| 76 |
* Override in dependent modules to update the refund payment line with the refunded payment line |
| 77 |
*/ |
| 78 |
updateRefundPaymentLine(refundedPaymentLine) {} |
| 79 |
} |
| 80 |
|
| 81 |
registry.category("pos_available_models").add(PosPayment.pythonModel, PosPayment); |