19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-25 12:00:11 +01:00
parent e1d89e11e3
commit a1f02d8cc7
225 changed files with 2335 additions and 775 deletions

View file

@ -558,8 +558,9 @@ class HrEmployee(models.Model):
If no valid version is found, we return the very first version of the employee.
"""
self.ensure_one()
versions = self.version_ids.filtered_domain([('date_version', '<=', date)])
return max(versions, key=lambda v: v.date_version) if versions else self.version_ids[0]
active_versions = self.version_ids.filtered(lambda v: v.active)
versions = active_versions.filtered_domain([('date_version', '<=', date)])
return max(versions, key=lambda v: v.date_version) if versions else active_versions[0]
def create_version(self, values):
self.ensure_one()
@ -837,19 +838,15 @@ class HrEmployee(models.Model):
(accessible on employee by inherits)."""
working_now = []
# We loop over all the employee tz and the resource calendar_id to detect working hours in batch.
all_employee_tz = set(self.mapped('tz'))
for tz in all_employee_tz:
employee_ids = self.filtered(lambda e: e.tz == tz)
resource_calendar_ids = employee_ids.sudo().mapped('resource_calendar_id')
for calendar_id in resource_calendar_ids:
res_employee_ids = employee_ids.sudo().filtered(lambda e: e.resource_calendar_id.id == calendar_id.id)
start_dt = fields.Datetime.now()
stop_dt = start_dt + timedelta(hours=1)
from_datetime = utc.localize(start_dt).astimezone(timezone(tz or 'UTC'))
to_datetime = utc.localize(stop_dt).astimezone(timezone(tz or 'UTC'))
for tz_info, employee_ids in self.filtered('resource_calendar_id').grouped('tz').items():
calendar_by_employee = employee_ids.grouped('resource_calendar_id')
tz = timezone(tz_info or 'UTC')
from_datetime = utc.localize(fields.Datetime.now()).astimezone(tz)
to_datetime = from_datetime + timedelta(hours=1)
for calendar_id, res_employee_ids in calendar_by_employee.items():
# Getting work interval of the first is working. Functions called on resource_calendar_id
# are waiting for singleton
work_interval = res_employee_ids[0].resource_calendar_id._work_intervals_batch(from_datetime, to_datetime)[False]
work_interval = calendar_id._work_intervals_batch(from_datetime, to_datetime)[False]
# Employee that is not supposed to work have empty items.
if len(work_interval._items) > 0:
# The employees should be working now according to their work schedule
@ -1026,29 +1023,36 @@ class HrEmployee(models.Model):
'|', ('email_normalized', 'in', employee_emails),
('login', 'in', employee_emails),
])
emp_by_email = self.grouped(lambda employee: email_normalize(employee.work_email))
duplicate_emails = [email for email, employees in emp_by_email.items() if email and len(employees) > 1]
old_users = []
new_users = []
users_without_emails = []
users_with_invalid_emails = []
users_with_existing_email = []
employees_with_duplicate_email = []
for employee in self:
normalized_email = email_normalize(employee.work_email)
if employee.user_id:
old_users.append(employee.name)
continue
if not employee.work_email:
users_without_emails.append(employee.name)
continue
if not tools.email_normalize(employee.work_email):
if not normalized_email:
users_with_invalid_emails.append(employee.name)
continue
if email_normalize(employee.work_email) in conflicting_users.mapped('email_normalized'):
if normalized_email in conflicting_users.mapped('email_normalized'):
users_with_existing_email.append(employee.name)
continue
if normalized_email in duplicate_emails:
employees_with_duplicate_email.append(employee.name)
continue
new_users.append({
'create_employee_id': employee.id,
'name': employee.name,
'phone': employee.work_phone,
'login': tools.email_normalize(employee.work_email),
'login': normalized_email,
'partner_id': employee.work_contact_id.id,
})
@ -1078,6 +1082,10 @@ class HrEmployee(models.Model):
message = _('User already exists with the same email for Employees %s', ', '.join(users_with_existing_email))
next_action = _get_user_creation_notification_action(message, 'warning', next_action)
if employees_with_duplicate_email:
message = _('The following employees have the same work email address: %s', ', '.join(employees_with_duplicate_email))
next_action = _get_user_creation_notification_action(message, 'warning', next_action)
return next_action
def _compute_display_name(self):

View file

@ -217,11 +217,12 @@ class HrVersion(models.Model):
@api.depends("private_country_id")
def _compute_allowed_country_state_ids(self):
states = self.env["res.country.state"].search([])
for version in self:
if version.private_country_id:
version.allowed_country_state_ids = version.private_country_id.state_ids
else:
versions_with_countries = self.filtered("private_country_id")
for version in versions_with_countries:
version.allowed_country_state_ids = version.private_country_id.state_ids
if versions_without_countries := (self - versions_with_countries):
states = self.env["res.country.state"].search([])
for version in versions_without_countries:
version.allowed_country_state_ids = states
@api.constrains('employee_id', 'contract_date_start', 'contract_date_end')