From 58dec20ccfbf5b76e55e7782bcde94860c01c116 Mon Sep 17 00:00:00 2001 From: Dossogne Bertrand Date: Thu, 4 Jan 2024 09:48:45 +0100 Subject: [PATCH] [FIX] hr, hr_contract: fix employee attendance data fetch Before this commit, _get_calendar_attendances was calling the calendar method get_work_duration_data without specifying the company in the domain, ending up in wrong data if global leaves that don't concern the employee are concerning the calendar. This commit adds a domain for that method call so that only relevent global leaves are taken into account. closes odoo/odoo#148043 --- addons/hr/models/hr_employee.py | 7 ++++++- addons/hr_contract/models/hr_employee.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/hr/models/hr_employee.py b/addons/hr/models/hr_employee.py index 465ed1615a5..063fa1dd3bd 100644 --- a/addons/hr/models/hr_employee.py +++ b/addons/hr/models/hr_employee.py @@ -517,7 +517,12 @@ class HrEmployeePrivate(models.Model): def _get_calendar_attendances(self, date_from, date_to): self.ensure_one() employee_timezone = timezone(self.tz) if self.tz else None - return self.resource_calendar_id.with_context(employee_timezone=employee_timezone).get_work_duration_data(date_from, date_to) + return self.resource_calendar_id\ + .with_context(employee_timezone=employee_timezone)\ + .get_work_duration_data( + date_from, + date_to, + domain=[('company_id', 'in', [False, self.company_id.id])]) # --------------------------------------------------------- # Business Methods diff --git a/addons/hr_contract/models/hr_employee.py b/addons/hr_contract/models/hr_employee.py index 7f92bdb8001..4c5b17d75f2 100644 --- a/addons/hr_contract/models/hr_employee.py +++ b/addons/hr_contract/models/hr_employee.py @@ -146,7 +146,12 @@ class Employee(models.Model): if not valid_contracts: return super()._get_calendar_attendances(date_from, date_to) employee_timezone = timezone(self.tz) if self.tz else None - return valid_contracts.resource_calendar_id.with_context(employee_timezone=employee_timezone).get_work_duration_data(date_from, date_to) + return valid_contracts.resource_calendar_id\ + .with_context(employee_timezone=employee_timezone)\ + .get_work_duration_data( + date_from, + date_to, + domain=[('company_id', 'in', [False, self.company_id.id])]) def write(self, vals): res = super().write(vals)