| 1 |
import { _t } from "@web/core/l10n/translation"; |
| 2 |
import { TicketScreen } from "@point_of_sale/app/screens/ticket_screen/ticket_screen"; |
| 3 |
import { useService } from "@web/core/utils/hooks"; |
| 4 |
import { patch } from "@web/core/utils/patch"; |
| 5 |
|
| 6 |
/** |
| 7 |
* Prevent refunding ewallet/gift card lines. |
| 8 |
*/ |
| 9 |
patch(TicketScreen.prototype, { |
| 10 |
setup() { |
| 11 |
super.setup(...arguments); |
| 12 |
this.notification = useService("notification"); |
| 13 |
}, |
| 14 |
_onUpdateSelectedOrderline() { |
| 15 |
const order = this.getSelectedOrder(); |
| 16 |
if (!order) { |
| 17 |
return this.numberBuffer.reset(); |
| 18 |
} |
| 19 |
const selectedOrderlineId = this.getSelectedOrderlineId(); |
| 20 |
const orderline = order.lines.find((line) => line.id == selectedOrderlineId); |
| 21 |
if (orderline && this._isEWalletGiftCard(orderline)) { |
| 22 |
this._showNotAllowedRefundNotification(); |
| 23 |
return this.numberBuffer.reset(); |
| 24 |
} |
| 25 |
return super._onUpdateSelectedOrderline(...arguments); |
| 26 |
}, |
| 27 |
_prepareAutoRefundOnOrder(order) { |
| 28 |
const selectedOrderlineId = this.getSelectedOrderlineId(); |
| 29 |
const orderline = order.lines.find((line) => line.id == selectedOrderlineId); |
| 30 |
if (this._isEWalletGiftCard(orderline)) { |
| 31 |
this._showNotAllowedRefundNotification(); |
| 32 |
return false; |
| 33 |
} |
| 34 |
return super._prepareAutoRefundOnOrder(...arguments); |
| 35 |
}, |
| 36 |
_showNotAllowedRefundNotification() { |
| 37 |
this.notification.add( |
| 38 |
_t( |
| 39 |
"Refunding a top up or reward product for an eWallet or gift card program is not allowed." |
| 40 |
), |
| 41 |
5000 |
| 42 |
); |
| 43 |
}, |
| 44 |
_isEWalletGiftCard(orderline) { |
| 45 |
if (orderline.is_reward_line) { |
| 46 |
const reward = orderline.reward_id; |
| 47 |
const program = reward && reward.program_id; |
| 48 |
if (program && ["gift_card", "ewallet"].includes(program.program_type)) { |
| 49 |
return true; |
| 50 |
} |
| 51 |
} |
| 52 |
return false; |
| 53 |
}, |
| 54 |
}); |