This commit is contained in:
Mazen Abdo 2025-08-24 13:37:30 +03:00
parent 7d92fe3ea8
commit 77bf081f17
1 changed files with 9 additions and 23 deletions

View File

@ -255,14 +255,11 @@ class HrEmployee(models.Model):
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))
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
if seq.isdigit() and int(seq) != (max_number + 1):
# 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 '/'
@ -273,23 +270,12 @@ class HrEmployee(models.Model):
def _compute_gosi_years(self):
for emp in self:
years = 0
gosi_date = emp.sudo().company_id.gosi_active_date
if emp.new_gosi and gosi_date:
try:
if isinstance(gosi_date, str):
date_activation = datetime.strptime(gosi_date, '%Y-%m-%d').date()
else:
date_activation = gosi_date
today = date.today()
years = today.year - date_activation.year - (
(today.month, today.day) < (date_activation.month, date_activation.day)
)
except Exception:
years = 0
emp.gosi_years = years
date_activation = datetime.strptime(str(emp.sudo().company_id.gosi_active_date), '%Y-%m-%d')
if emp.new_gosi==True:
if date_activation:
today = date.today()
years = today.year - date_activation.year - ((today.month, today.day) < (date_activation.month, date_activation.day))
emp.sudo().gosi_years = years
@api.constrains('gosi_date','new_gosi')
def _check_gosi_date(self):