|
| 1 | +odoo.define("pos_customer_wallet_partner_is_user.PaymentScreen", function (require) { |
| 2 | + "use strict"; |
| 3 | + const PaymentScreen = require("point_of_sale.PaymentScreen"); |
| 4 | + |
| 5 | + const Registries = require("point_of_sale.Registries"); |
| 6 | + |
| 7 | + const IsUserPaymentScreen = (PaymentScreen_) => |
| 8 | + class extends PaymentScreen_ { |
| 9 | + /* eslint-disable no-unused-vars */ |
| 10 | + /** |
| 11 | + * Overload function. |
| 12 | + * |
| 13 | + * - If partner hasn't enabled functionality, don't allow wallet payments. |
| 14 | + * |
| 15 | + * @param {Boolean} isForceValidate - Passed to super. |
| 16 | + * @returns {Boolean} Whether the order is valid. |
| 17 | + */ |
| 18 | + async validateOrder(isForceValidate) { |
| 19 | + var partner = this.currentOrder.get_partner(); |
| 20 | + var [payment_wallet_amount, payment_lines_qty] = |
| 21 | + this.get_amount_debit_with_customer_wallet_journal(); |
| 22 | + var [product_wallet_amount, product_lines_qty] = |
| 23 | + this.get_amount_credit_with_customer_wallet_product(); |
| 24 | + /* eslint-enable no-unused-vars */ |
| 25 | + |
| 26 | + // If the partner is not a customer wallet user, and if a customer |
| 27 | + // wallet operation is being made (via the payment method or via the |
| 28 | + // wallet product), display an error. |
| 29 | + if ( |
| 30 | + (payment_lines_qty || product_lines_qty) && |
| 31 | + partner && |
| 32 | + !partner.is_customer_wallet_user |
| 33 | + ) { |
| 34 | + this.showPopup("ErrorPopup", { |
| 35 | + title: this.env._t("Customer cannot use customer wallet"), |
| 36 | + body: this.env._t( |
| 37 | + "Customer has not enabled the usage of a customer wallet. Before the user can use this payment method, they must enable it." |
| 38 | + ), |
| 39 | + }); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + await super.validateOrder(...arguments); |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + Registries.Component.extend(PaymentScreen, IsUserPaymentScreen); |
| 48 | + |
| 49 | + return IsUserPaymentScreen; |
| 50 | +}); |
0 commit comments