From 785f1f6680ef186c8b9ddefb514bc74d8371b8be Mon Sep 17 00:00:00 2001 From: younes Date: Sun, 24 Aug 2025 13:58:44 +0100 Subject: [PATCH 1/2] Fix bug --- odex25_hr/hr_base/models/hr_base.py | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/odex25_hr/hr_base/models/hr_base.py b/odex25_hr/hr_base/models/hr_base.py index 354429488..8ffa9fd23 100644 --- a/odex25_hr/hr_base/models/hr_base.py +++ b/odex25_hr/hr_base/models/hr_base.py @@ -27,6 +27,24 @@ class HrEmployee(models.Model): _inherit = "hr.employee" _order = 'id' + @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])]) + + # Get the maximum current employee number + max_number = 0 + if emp_seq: + max_number = max(int(emp.emp_no) for emp in emp_seq if emp.emp_no and emp.emp_no.isdigit()) + + # 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) + # iqama fields in employee view identity_number = fields.Char(compute_sudo=True, compute='_compute_identity_number', string='Identity Number',store=True) iqama_creat_date = fields.Date(related="iqama_number.issue_date", readonly=True,string="Iqama Issue Date") @@ -249,25 +267,7 @@ class HrEmployee(models.Model): help='New participants who have no prior periods of contribution under the GOSI.') 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])]) - - # Get the maximum current employee number - max_number = 0 - if emp_seq: - max_number = max(int(emp.emp_no) for emp in emp_seq if emp.emp_no and emp.emp_no.isdigit()) - - # 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.depends('new_gosi') def _compute_gosi_years(self): From c14feae4d38f8f6b428346dac77bc73dbd8d48d7 Mon Sep 17 00:00:00 2001 From: younes Date: Sun, 24 Aug 2025 14:04:06 +0100 Subject: [PATCH 2/2] Fix bug --- odex25_hr/hr_base/models/hr_base.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/odex25_hr/hr_base/models/hr_base.py b/odex25_hr/hr_base/models/hr_base.py index f1cb0deb5..0cb07c6b9 100644 --- a/odex25_hr/hr_base/models/hr_base.py +++ b/odex25_hr/hr_base/models/hr_base.py @@ -105,7 +105,7 @@ class HrEmployee(models.Model): emp_no = fields.Char( string="Employee number", tracking=True, - default=lambda self: self.env['ir.sequence'].next_by_code('hr.employee') + default=lambda self: self._default_emp_code() ) english_name = fields.Char(string="English Name") home_no = fields.Char() @@ -271,11 +271,7 @@ class HrEmployee(models.Model): help='New participants who have no prior periods of contribution under the GOSI.') gosi_years = fields.Integer(string="GOSI Years", compute='_compute_gosi_years', store=True, help='GOSI Years According To The New activation Date Until Today') -<<<<<<< HEAD - -======= ->>>>>>> 5eaada3d742d71839972b574c7532eabc21a7459 @api.depends('new_gosi') def _compute_gosi_years(self): for emp in self: