feat: prevent refunding cancelled pos orders on both server and client side

This commit is contained in:
Suherdy Yacob 2026-06-05 15:40:46 +07:00
parent 3ce178a631
commit 383bf63f19
2 changed files with 22 additions and 1 deletions

View File

@ -1,4 +1,5 @@
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.exceptions import UserError
class PosOrder(models.Model):
_inherit = 'pos.order'
@ -8,3 +9,9 @@ class PosOrder(models.Model):
# Existing Odoo/POS fields renamed for clarity
user_id = fields.Many2one('res.users', string='Session User', help='Odoo user who opened the session')
employee_id = fields.Many2one('hr.employee', string='Order Taker', help='Employee who uses the cash register')
def _refund(self):
for order in self:
if order.state == 'cancel':
raise UserError(_("You cannot refund a cancelled order."))
return super()._refund()

View File

@ -2,6 +2,8 @@
import { patch } from "@web/core/utils/patch";
import { TicketScreen } from "@point_of_sale/app/screens/ticket_screen/ticket_screen";
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
import { _t } from "@web/core/l10n/translation";
patch(TicketScreen.prototype, {
async setOrder(order) {
@ -25,5 +27,17 @@ patch(TicketScreen.prototype, {
}
return super.setOrder(order);
},
async onDoRefund() {
const order = this.getSelectedOrder();
if (order && order.state === 'cancel') {
this.dialog.add(AlertDialog, {
title: _t("Refund Blocked"),
body: _t("You cannot refund a cancelled order."),
});
return;
}
return super.onDoRefund();
}
});