This commit is contained in:
Mazen Abdo 2025-08-24 12:16:39 +03:00
parent 75a2837a12
commit 531ef4e180
1 changed files with 9 additions and 5 deletions

View File

@ -252,20 +252,24 @@ class HrEmployee(models.Model):
@api.model
def _default_emp_code(self):
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
# حاول تجيب الرقم من sequence
seq = self.env['ir.sequence'].next_by_code('hr.employee')
if not seq or not str(seq).isdigit():
return "1"
emp_seq = self.env['hr.employee'].search([('active', 'in', [False, True])])
numbers = [int(emp.emp_no) for emp in emp_seq if emp.emp_no and emp.emp_no.isdigit()]
max_number = max(numbers) if numbers else 0
# Ensure the sequence matches the max number + 1
if int(seq) != (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 '/'
if currnt_sequence:
currnt_sequence.write({'number_next_actual': max_number + 1})
seq = self.env['ir.sequence'].next_by_code('hr.employee') or (max_number + 1)
return str(seq)
@api.depends('new_gosi')
def _compute_gosi_years(self):
for emp in self: