| 1 |
import { patch } from "@web/core/utils/patch"; |
| 2 |
import { _t } from "@web/core/l10n/translation"; |
| 3 |
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; |
| 4 |
import { TicketScreen } from "@point_of_sale/app/screens/ticket_screen/ticket_screen"; |
| 5 |
|
| 6 |
patch(TicketScreen.prototype, { |
| 7 |
async onDoRefund() { |
| 8 |
await super.onDoRefund(...arguments); |
| 9 |
const order = this.getSelectedOrder(); |
| 10 |
const discountLines = order.discountLines; |
| 11 |
const destinationOrder = this.pos.getOrder(); |
| 12 |
|
| 13 |
if (discountLines?.length && destinationOrder) { |
| 14 |
const percentage = order.globalDiscountPc; |
| 15 |
this.pos.applyDiscount(percentage, destinationOrder); |
| 16 |
} |
| 17 |
}, |
| 18 |
|
| 19 |
_onUpdateSelectedOrderline() { |
| 20 |
const selectedOrderlineId = this.getSelectedOrderlineId(); |
| 21 |
const orderline = this.getSelectedOrder().lines.find( |
| 22 |
(line) => line.id == selectedOrderlineId |
| 23 |
); |
| 24 |
if (orderline && orderline.product_id.id === this.pos.config.discount_product_id?.id) { |
| 25 |
return this.dialog.add(AlertDialog, { |
| 26 |
title: _t("Error"), |
| 27 |
body: _t("You cannot edit a discount line."), |
| 28 |
}); |
| 29 |
} |
| 30 |
return super._onUpdateSelectedOrderline(...arguments); |
| 31 |
}, |
| 32 |
}); |