From 77bf081f1719cc0486c6b3cf0547ca82c3f007ac Mon Sep 17 00:00:00 2001 From: Mazen Abdo Date: Sun, 24 Aug 2025 13:37:30 +0300 Subject: [PATCH] fix --- odex25_hr/hr_base/models/hr_base.py | 32 ++++++++--------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/odex25_hr/hr_base/models/hr_base.py b/odex25_hr/hr_base/models/hr_base.py index 90cd409c0..955d76eff 100644 --- a/odex25_hr/hr_base/models/hr_base.py +++ b/odex25_hr/hr_base/models/hr_base.py @@ -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):