Files
repair/odoo/addons/dsrpt_repair_technicians/models/technician.py
2026-02-13 15:04:50 +07:00

67 lines
2.4 KiB
Python

from odoo import api, fields, models
from odoo.exceptions import ValidationError
class RepairTechnician(models.Model):
_name = "repair.technician"
_description = "Repair Technician"
_order = "name"
name = fields.Char(required=True)
user_id = fields.Many2one("res.users", string="User")
zone_ids = fields.Many2many("repair.fsm.zone", string="FSM Zones")
active = fields.Boolean(default=True)
schedule_ids = fields.One2many("repair.technician.schedule", "technician_id", string="Weekly Schedule")
exception_ids = fields.One2many("repair.technician.exception", "technician_id", string="Exceptions")
class RepairTechnicianSchedule(models.Model):
_name = "repair.technician.schedule"
_description = "Repair Technician Weekly Schedule"
_order = "technician_id, day_of_week, hour_from"
technician_id = fields.Many2one("repair.technician", required=True, ondelete="cascade")
day_of_week = fields.Selection(
selection=[
("0", "Monday"),
("1", "Tuesday"),
("2", "Wednesday"),
("3", "Thursday"),
("4", "Friday"),
("5", "Saturday"),
("6", "Sunday"),
],
required=True,
)
hour_from = fields.Float(required=True)
hour_to = fields.Float(required=True)
@api.constrains("hour_from", "hour_to")
def _check_hours(self):
for rec in self:
if rec.hour_from < 0 or rec.hour_to > 24 or rec.hour_to <= rec.hour_from:
raise ValidationError("Schedule hours must be between 0 and 24, and hour_to must be greater than hour_from.")
class RepairTechnicianException(models.Model):
_name = "repair.technician.exception"
_description = "Repair Technician Exception"
_order = "start_datetime desc"
technician_id = fields.Many2one("repair.technician", required=True, ondelete="cascade")
name = fields.Char(required=True)
exception_type = fields.Selection(
selection=[("positive", "Positive"), ("negative", "Negative")],
required=True,
default="negative",
)
start_datetime = fields.Datetime(required=True)
end_datetime = fields.Datetime(required=True)
note = fields.Text()
@api.constrains("start_datetime", "end_datetime")
def _check_dates(self):
for rec in self:
if rec.end_datetime <= rec.start_datetime:
raise ValidationError("Exception end must be after start.")