From 56948bb245b89fb6d4b6e6800a75f92c129aa1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Wed, 7 Jun 2017 13:00:58 +0200 Subject: [PATCH] [FIX] hr_timesheet: set correct default value for timesheet When logging timesheet, no employee is set by default on the UI. The employee is deduced from the user_id in the create, but we want to see it on the list view even if it is not saved yet. --- addons/hr_timesheet/hr_timesheet.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 74704a459f2..d8d07c42fd8 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -7,6 +7,13 @@ from odoo import api, fields, models class AccountAnalyticLine(models.Model): _inherit = 'account.analytic.line' + @api.model + def default_get(self, field_list): + result = super(AccountAnalyticLine, self).default_get(field_list) + if 'employee_id' in field_list and result.get('user_id') and result.get('project_id'): + result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', result['user_id'])], limit=1).id + return result + task_id = fields.Many2one('project.task', 'Task') project_id = fields.Many2one('project.project', 'Project', domain=[('allow_timesheets', '=', True)])