From 900e77fe5fe426ca55cddc4f1ce0141a45b60287 Mon Sep 17 00:00:00 2001 From: Waleed Mohsen Date: Fri, 19 Apr 2019 20:54:21 +0300 Subject: [PATCH] Accept changing ticket category without changing sub category When you update a ticket by changing ticket category and save, the module not validate if the sub category belong to the changed category. --- website_support/models/website_support_ticket.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/website_support/models/website_support_ticket.py b/website_support/models/website_support_ticket.py index b48346794..b209b1fc0 100644 --- a/website_support/models/website_support_ticket.py +++ b/website_support/models/website_support_ticket.py @@ -109,6 +109,14 @@ def _default_approval_id(self): sla_alert_ids = fields.Many2many('website.support.sla.alert', string="SLA Alerts", help="Keep record of SLA alerts sent so we do not resend them") + #add constrains on sub_category_id + @api.constrains('sub_category_id') + def _check_subcategory(self): + # if the sub_category_id not a child of the selected category then raise an error. + if any(ticket.sub_category_id and ticket.sub_category_id.parent_category_id != ticket.category for ticket in self): + raise ValidationError(_('Error: Your selected sub category not a child of the parent category.')) + return True + @api.multi @api.depends('subject', 'ticket_number') def name_get(self): @@ -799,4 +807,4 @@ def send_reply(self): else: #Change the ticket state to staff replied staff_replied = self.env['ir.model.data'].get_object('website_support','website_ticket_state_staff_replied') - self.ticket_id.state = staff_replied.id \ No newline at end of file + self.ticket_id.state = staff_replied.id