[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) <xbo@odoo.com>
This commit is contained in:
committed by
Xavier Bol (xbo)
parent
9cbc7a2dc7
commit
1032eacb6c
@@ -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
|
||||
|
||||
@@ -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)],
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user