41 lines
1.5 KiB
Python
Executable File
41 lines
1.5 KiB
Python
Executable File
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import models, fields, api
|
|
|
|
class sos_department(models.Model):
|
|
_name = 'sos_departments'
|
|
_description = 'Departments in Sosaley'
|
|
|
|
|
|
name = fields.Char(string="Department Name")
|
|
short_form = fields.Char(string="Short Text")
|
|
process_incharge = fields.Many2one('res.users', string='Process Incharge')
|
|
users_line_ids = fields.One2many('sos_departments_user_lines','ref_id', string='Users')
|
|
|
|
_sql_constraints = [
|
|
('uniq_department_name', 'unique(name)', 'Department name must be unique.'),
|
|
]
|
|
class sos_department_line(models.Model):
|
|
_name = 'sos_departments_user_lines'
|
|
_description = 'Users in department'
|
|
|
|
ref_id = fields.Many2one('sos_departments', string="Departments", ondelete="cascade")
|
|
users = fields.Many2one('res.users', string='Users')
|
|
# @api.onchange('users')
|
|
# def _onchange_users(self):
|
|
# if self.users:
|
|
# domain = [('users', '=', self.users.id)]
|
|
# if self.id and isinstance(self.id, int): # Only add if it's a real ID
|
|
# domain.append(('id', '!=', self.id))
|
|
|
|
# existing_line = self.env['sos_departments_user_lines'].search(domain, limit=1)
|
|
# if existing_line:
|
|
# return {
|
|
# 'warning': {
|
|
# 'title': 'User Already Assigned',
|
|
# 'message': f"This user is already assigned to {existing_line.ref_id.name}."
|
|
# }
|
|
# }
|
|
|
|
|
|
|