36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from odoo import api, fields, models
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class AcademicLevel(models.Model):
|
|
_name = 'education.academic.level'
|
|
_description = 'Academic Level'
|
|
_order = 'sequence, name'
|
|
|
|
name = fields.Char(required=True, string='Level Name')
|
|
code = fields.Char(required=True, string='Level Code', index=True)
|
|
sequence = fields.Integer(default=10)
|
|
description = fields.Text(string='Description')
|
|
active = fields.Boolean(default=True)
|
|
company_id = fields.Many2one(
|
|
'res.company',
|
|
string='Company',
|
|
required=True,
|
|
default=lambda self: self.env.company,
|
|
index=True,
|
|
)
|
|
|
|
_sql_constraints = [
|
|
('uniq_academic_level_code_company', 'unique(code, company_id)', 'Academic level code must be unique per company.'),
|
|
]
|
|
|
|
@api.constrains('name', 'company_id')
|
|
def _check_unique_name(self):
|
|
for rec in self:
|
|
if self.search_count([
|
|
('company_id', '=', rec.company_id.id),
|
|
('name', '=ilike', rec.name),
|
|
('id', '!=', rec.id),
|
|
]):
|
|
raise ValidationError('Academic level name must be unique within a company.')
|