From 1032eacb6c5f8f0f9afd3f281f947e6d1b0fc2cc Mon Sep 17 00:00:00 2001 From: Anna Janiszewska Date: Mon, 4 Mar 2024 14:44:02 +0100 Subject: [PATCH] [FIX] hr_timesheet: filter out ts for global time off Fix to avoid considering TS lines for projects linked to global time off closes odoo/odoo#157156 X-original-commit: 2e46a8e9179a83709638bdefc7e664837cbd8e92 Signed-off-by: Xavier Bol (xbo) --- addons/hr_timesheet/models/hr_timesheet.py | 11 +++++++---- .../models/account_analytic.py | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index d7087229b1a..7ffc2be565b 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -11,13 +11,16 @@ from odoo.osv import expression class AccountAnalyticLine(models.Model): _inherit = 'account.analytic.line' - @api.model - def _get_favorite_project_id(self, employee_id=False): + def _get_favorite_project_id_domain(self, employee_id=False): employee_id = employee_id or self.env.user.employee_id.id - last_timesheet_ids = self.search([ + return [ ('employee_id', '=', employee_id), ('project_id', '!=', False), - ], limit=5) + ] + + @api.model + def _get_favorite_project_id(self, employee_id=False): + last_timesheet_ids = self.search(self._get_favorite_project_id_domain(employee_id), limit=5) if len(last_timesheet_ids.project_id) == 1: return last_timesheet_ids.project_id.id return False diff --git a/addons/project_timesheet_holidays/models/account_analytic.py b/addons/project_timesheet_holidays/models/account_analytic.py index 258cbda1d09..48d7b3f4d2c 100644 --- a/addons/project_timesheet_holidays/models/account_analytic.py +++ b/addons/project_timesheet_holidays/models/account_analytic.py @@ -3,6 +3,7 @@ from odoo import api, fields, models, _ from odoo.exceptions import RedirectWarning, UserError +from odoo.osv import expression class AccountAnalyticLine(models.Model): @@ -44,3 +45,9 @@ class AccountAnalyticLine(models.Model): if not self.env.su and any(task.is_timeoff_task for task in self.task_id): raise UserError(_('You cannot create timesheets for a task that is linked to a time off type. Please use the Time Off application to request new time off instead.')) return super()._check_can_create() + + def _get_favorite_project_id_domain(self, employee_id=False): + return expression.AND([ + super()._get_favorite_project_id_domain(employee_id), + [('holiday_id', '=', False), ('global_leave_id', '=', False)], + ])