119 lines
3.9 KiB
Python
119 lines
3.9 KiB
Python
# pyrefly: ignore [missing-import]
|
|
from odoo import api, fields, models
|
|
# pyrefly: ignore [missing-import]
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class EducationHostelComplaint(models.Model):
|
|
_name = 'education.hostel.complaint'
|
|
_description = 'Hostel Complaint'
|
|
_inherit = ['mail.thread', 'mail.activity.mixin']
|
|
_order = 'submitted_date desc, id desc'
|
|
|
|
name = fields.Char(
|
|
string='Reference',
|
|
required=True,
|
|
copy=False,
|
|
readonly=True,
|
|
default=lambda self: self.env['ir.sequence'].next_by_code('education.hostel.complaint'),
|
|
index=True,
|
|
)
|
|
student_id = fields.Many2one(
|
|
'education.student',
|
|
string='Student',
|
|
required=True,
|
|
ondelete='restrict',
|
|
index=True,
|
|
tracking=True,
|
|
)
|
|
hostel_id = fields.Many2one(
|
|
'education.hostel',
|
|
string='Hostel',
|
|
required=True,
|
|
ondelete='restrict',
|
|
index=True,
|
|
)
|
|
room_id = fields.Many2one(
|
|
'education.hostel.room',
|
|
string='Room',
|
|
ondelete='set null',
|
|
index=True,
|
|
)
|
|
category = fields.Selection([
|
|
('maintenance', 'Maintenance'),
|
|
('cleanliness', 'Cleanliness'),
|
|
('food', 'Food'),
|
|
('security', 'Security'),
|
|
('roommate', 'Roommate Issue'),
|
|
('other', 'Other'),
|
|
], string='Category', required=True, default='maintenance', tracking=True)
|
|
title = fields.Char(string='Title', required=True)
|
|
description = fields.Text(string='Description')
|
|
priority = fields.Selection([
|
|
('0', 'Normal'),
|
|
('1', 'Low'),
|
|
('2', 'High'),
|
|
('3', 'Urgent'),
|
|
], string='Priority', default='0')
|
|
state = fields.Selection([
|
|
('draft', 'Draft'),
|
|
('submitted', 'Submitted'),
|
|
('in_progress', 'In Progress'),
|
|
('resolved', 'Resolved'),
|
|
('closed', 'Closed'),
|
|
], string='Status', default='draft', required=True, tracking=True, index=True)
|
|
assigned_to = fields.Many2one(
|
|
'res.users',
|
|
string='Assigned To',
|
|
tracking=True,
|
|
domain=[('share', '=', False)],
|
|
)
|
|
resolution = fields.Text(string='Resolution')
|
|
submitted_date = fields.Date(string='Submitted Date', tracking=True)
|
|
resolved_date = fields.Date(string='Resolved Date', tracking=True)
|
|
company_id = fields.Many2one(
|
|
'res.company',
|
|
string='Company',
|
|
required=True,
|
|
default=lambda self: self.env.company,
|
|
index=True,
|
|
)
|
|
|
|
# ── Workflow ──────────────────────────────────────────────────────────────
|
|
|
|
def action_submit(self):
|
|
for rec in self:
|
|
rec.state = 'submitted'
|
|
rec.submitted_date = fields.Date.today()
|
|
rec.message_post(body="Complaint submitted.")
|
|
|
|
def action_start_progress(self):
|
|
for rec in self:
|
|
if not rec.assigned_to:
|
|
raise ValidationError("Please assign the complaint to a staff member before starting.")
|
|
rec.state = 'in_progress'
|
|
|
|
def action_resolve(self):
|
|
for rec in self:
|
|
if not rec.resolution:
|
|
raise ValidationError("Please provide a resolution note before marking as resolved.")
|
|
rec.state = 'resolved'
|
|
rec.resolved_date = fields.Date.today()
|
|
|
|
def action_close(self):
|
|
self.write({'state': 'closed'})
|
|
|
|
def action_reopen(self):
|
|
for rec in self:
|
|
if rec.state == 'closed':
|
|
rec.state = 'resolved'
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if not vals.get('name') or vals.get('name') == '/':
|
|
vals['name'] = (
|
|
self.env['ir.sequence'].next_by_code('education.hostel.complaint') or '/'
|
|
)
|
|
return super().create(vals_list)
|