Merge pull request #4294 from expsa/maz_ba_ox

fix
This commit is contained in:
mazenmuhamad 2025-08-24 11:49:11 +03:00 committed by GitHub
commit b771dc518f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 16 deletions

View File

@ -84,7 +84,7 @@ class HrEmployee(models.Model):
r_name = fields.Char("Name")
# fields of page work information in employees view
emp_no = fields.Char(string="Employee number", tracking=True)
emp_no = fields.Char(string="Employee number", tracking=True, default=lambda self: self._default_emp_code())
english_name = fields.Char(string="English Name")
home_no = fields.Char()
present_address = fields.Char()
@ -250,21 +250,25 @@ class HrEmployee(models.Model):
gosi_years = fields.Integer(string="GOSI Years", compute='_compute_gosi_years', store=True,
help='GOSI Years According To The New activation Date Until Today')
# @api.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])])
#
# 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 '/'
#
# return str(seq)
@api.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])])
numbers = []
for emp in emp_seq:
if emp.emp_no and emp.emp_no.isdigit():
numbers.append(int(emp.emp_no))
max_number = max(numbers) if numbers else 0
if seq.isdigit() and int(seq) != (max_number + 1):
currnt_sequence = self.env['ir.sequence'].search([('code', '=', 'hr.employee')], limit=1)
if currnt_sequence:
currnt_sequence.sudo().write({'number_next_actual': max_number + 1})
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
return str(seq)
@api.depends('new_gosi')
def _compute_gosi_years(self):