fix
This commit is contained in:
parent
1a60dc2fbd
commit
c30ff7831e
|
|
@ -6,6 +6,8 @@ from num2words import num2words
|
|||
from odoo import api, exceptions, fields, models, _
|
||||
from odoo.exceptions import ValidationError, Warning
|
||||
from odoo.tools.translate import _
|
||||
from datetime import date
|
||||
|
||||
|
||||
class HrEmployeePublic(models.Model):
|
||||
_inherit = 'hr.employee.public'
|
||||
|
|
@ -252,23 +254,42 @@ class HrEmployee(models.Model):
|
|||
|
||||
@api.model
|
||||
def _default_emp_code(self):
|
||||
seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
|
||||
try:
|
||||
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))
|
||||
# Get all employee numbers that are digits
|
||||
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
|
||||
# Safely get the maximum number
|
||||
if numbers:
|
||||
max_number = max(numbers)
|
||||
else:
|
||||
max_number = 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 '/'
|
||||
# Check if sequence needs to be updated
|
||||
if seq and seq != '/' and seq.isdigit():
|
||||
seq_number = int(seq)
|
||||
if seq_number != (max_number + 1):
|
||||
current_sequence = self.env['ir.sequence'].search([('code', '=', 'hr.employee')], limit=1)
|
||||
if current_sequence:
|
||||
current_sequence.sudo().write({'number_next_actual': max_number + 1})
|
||||
seq = self.env['ir.sequence'].next_by_code('hr.employee') or str(max_number + 1)
|
||||
|
||||
return str(seq)
|
||||
# Ensure we always return a valid string
|
||||
if not seq or seq == '/':
|
||||
seq = str(max_number + 1)
|
||||
|
||||
return str(seq)
|
||||
|
||||
except Exception as e:
|
||||
# Log the error and return a fallback value
|
||||
# _logger.error("Error in _default_emp_code: %s", str(e))
|
||||
# Return a timestamp-based fallback or simple increment
|
||||
return str(int(time.time()) % 1000000) # Last 6 digits of timestamp
|
||||
|
||||
@api.depends('new_gosi')
|
||||
def _compute_gosi_years(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue