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)], + ])