commit
d1e5e7b568
|
|
@ -31,16 +31,23 @@ 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])])
|
||||
max_number = max(
|
||||
(int(emp.emp_no) for emp in emp_seq if emp.emp_no and emp.emp_no.isdigit()),
|
||||
default=0
|
||||
)
|
||||
|
||||
max_number = 0
|
||||
for emp in emp_seq:
|
||||
if emp.emp_no and emp.emp_no.isdigit():
|
||||
try:
|
||||
num = int(emp.emp_no)
|
||||
if num > max_number and num < 2000000000:
|
||||
max_number = num
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
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)
|
||||
if currnt_sequence:
|
||||
safe_number = min(max_number + 1, 2147483647)
|
||||
currnt_sequence.write({'number_next_actual': safe_number})
|
||||
safe_next = min(max_number + 1, 1999999999)
|
||||
currnt_sequence.sudo().write({'number_next_actual': safe_next})
|
||||
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
|
||||
|
||||
return str(seq)
|
||||
|
|
|
|||
Loading…
Reference in New Issue