<commit_before># © 2014-2015 Tecnativa S.L. - <NAME>
# © 2016 Tecnativa S.L. - <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
    _inherit = "res.partner"

    department_id = fields.Many2one(
        "res.partner.department", "Department", oldname="department"
    )


class ResPartnerDepartment(models.Model):
    _name = "res.partner.department"
    _order = "parent_path"
    _parent_order = "name"
    _parent_store = True
    _description = "Department"

    name = fields.Char(required=True, translate=True)
    parent_id = fields.Many2one(
        "res.partner.department", "Parent department", ondelete="restrict"
    )
    child_ids = fields.One2many(
        "res.partner.department", "parent_id", "Child departments"
    )
    parent_path = fields.Char(index=True)

    @api.constrains("parent_id")
    def _check_parent_id(self):
        if not self._check_recursion():
            raise ValidationError(_("Error! You cannot create recursive departments."))<commit_msg>[MIG]partner_contact_department: Migration to 13.0<commit_after># © 2014-2015 Tecnativa S.L. - <NAME>
# © 2016 Tecnativa S.L. - <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
    _inherit = "res.partner"

    department_id = fields.Many2one("res.partner.department", "Department")


class ResPartnerDepartment(models.Model):
    _name = "res.partner.department"
    _order = "parent_path"
    _parent_order = "name"
    _parent_store = True
    _description = "Department"

    name = fields.Char(required=True, translate=True)
    parent_id = fields.Many2one(
        "res.partner.department", "Parent department", ondelete="restrict"
    )
    child_ids = fields.One2many(
        "res.partner.department", "parent_id", "Child departments"
    )
    parent_path = fields.Char(index=True)

    @api.constrains("parent_id")
    def _check_parent_id(self):
        if not self._check_recursion():
            raise ValidationError(_("Error! You cannot create recursive departments."))
{'fraction_non_alphanumeric': 0.1238390092879257, 'fraction_numerical': 0.016364440513047324, 'mean_word_length': 3.654320987654321, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741869', 'n_tokens_mistral': 792, 'n_tokens_neox': 731, 'n_words': 156}