Merge pull request #4496 from expsa/maz_base_emp

fix
This commit is contained in:
mazenmuhamad 2025-09-01 16:50:24 +03:00 committed by GitHub
commit 67e3711ead
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 8 deletions

View File

@ -31,14 +31,12 @@ class HrEmployee(models.Model):
def _default_emp_code(self):
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
emp_seq = self.env['hr.employee'].search([('active', 'in', [False, True])])
# Get the maximum current employee number
max_number = 0
if emp_seq:
max_number = max(int(emp.emp_no) for emp in emp_seq if emp.emp_no and emp.emp_no.isdigit())
# Ensure the sequence matches the max number + 1
if int(seq) != (max_number + 1):
max_number = max(
(int(emp.emp_no) for emp in emp_seq if emp.emp_no and emp.emp_no.isdigit()),
default=0
)
seq_number = int(seq) if str(seq).isdigit() else 0
if seq_number != (max_number + 1):
currnt_sequence = self.env['ir.sequence'].search([('code', '=', 'hr.employee')], limit=1)
currnt_sequence.write({'number_next_actual': max_number + 1})
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'