Odoo-Tutorial/education/models/education_class_group.py
2025-02-22 10:32:13 +07:00

21 lines
888 B
Python

from odoo import fields, models, api
from odoo.exceptions import ValidationError
class EductionClassGroup(models.Model):
_name = 'education.class.group'
_description = 'Education Class Group'
_order = 'sequence'
name = fields.Char(string='Name', translate=True, required=True)
parent_id = fields.Many2one('education.class.group', string='Parent Group', ondelete='restrict')
child_ids = fields.One2many('education.class.group', string='Child Groups', ondelete='restrict')
class_ids = fields.One2many('education.class', 'class_group_id', string='Class of Groups')
_parent_store = True
_parent_name = "parent_id"
parent_path = fields.Char(index=True)
@api.constraints('parent_id')
def _check_hierarchy(self):
if not self._check_recursion():
raise ValidationError('Error! You cannot create recursivecategories.')