oca-hr/odoo-bringout-oca-hr-hr_employee_id/hr_employee_id/models/hr_employee.py
Ernad Husremovic dfcda4100c Move all OCA HR modules from oca-technical to dedicated oca-hr submodule
Reorganized 67 HR-related modules for better structure:
- Moved all odoo-bringout-oca-hr-* packages from packages/oca-technical/
- Now organized in dedicated packages/oca-hr/ submodule
- Includes attendance, expense, holiday, employee, and contract modules
- Maintains all module functionality while improving project organization

This creates a cleaner separation between general technical modules
and HR-specific functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-30 17:11:28 +02:00

69 lines
2.2 KiB
Python

# Copyright 2011, 2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# Copyright 2016 OpenSynergy Indonesia
# Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
import random
import string
from odoo import _, api, fields, models
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
class HrEmployee(models.Model):
"""Implement company wide unique identification number."""
_inherit = "hr.employee"
identification_id = fields.Char(string="Identification No", copy=False)
_sql_constraints = [
(
"identification_id_uniq",
"unique(identification_id)",
"The Employee Number must be unique across the company(s).",
),
]
@api.model
def _generate_identification_id(self):
"""Generate a random employee identification number"""
company = self.env.user.company_id
steps = 0
for _retry in range(50):
employee_id = False
if company.employee_id_gen_method == "sequence":
if not company.employee_id_sequence:
_logger.warning("No sequence configured for employee ID generation")
return employee_id
employee_id = company.employee_id_sequence.next_by_id()
elif company.employee_id_gen_method == "random":
employee_id_random_digits = company.employee_id_random_digits
rnd = random.SystemRandom()
employee_id = "".join(
rnd.choice(string.digits) for x in range(employee_id_random_digits)
)
if self.search_count([("identification_id", "=", employee_id)]):
steps += 1
continue
return employee_id
raise UserError(
_("Unable to generate unique Employee ID in %d steps.") % (steps,)
)
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for record in records:
if not record.identification_id:
record.identification_id = record._generate_identification_id()
return records