[IMP] hr_timesheet: make it easier to encode timesheets

In this commit, we do two small changes to make it easier to encode
timesheets.  The main issue is that we want to solve the following
situation: a user clicks on a cell in a timesheet grid view to open a
list view, then clicks on 'Create' to create a new timesheet. This will
open a form view, but some fields which could be prefilled are not
filled.

- do not reset task_id in some cases. This is important for the onchange
  call which comes after a default_get, when there is a default project
value set.
- do not set employee_id if there is default_employee_id in context
  This is useful when we open timesheets from the 'All Timesheets'
menu item, then add a new line, select a different employee, and open it
in the grid view (by clicking on the + icon from a cell).  This opens a
list view, which is editable, but when we create a new entry, it ignores
the employee value.

Note: a commit in enterprise adds support for properly passing contexts
in grid view, see
https://github.com/odoo/enterprise/commit/f23003917f18b52bb69483cdaac3cb2164230aa6

Task: #35414
This commit is contained in:
Kishan Gajjar
2018-05-11 16:19:26 +02:00
committed by Géry Debongnie
parent 02deb4a662
commit c1f04bef83
+4 -3
View File
@@ -11,7 +11,7 @@ class AccountAnalyticLine(models.Model):
@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'):
if not self.env.context.get('default_employee_id') and 'employee_id' in field_list and result.get('user_id'):
result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', result['user_id'])], limit=1).id
return result
@@ -23,10 +23,11 @@ class AccountAnalyticLine(models.Model):
@api.onchange('project_id')
def onchange_project_id(self):
# reset task when changing project
self.task_id = False
# force domain on task when project is set
if self.project_id:
if self.project_id != self.task_id.project_id:
# reset task when changing project
self.task_id = False
return {'domain': {
'task_id': [('project_id', '=', self.project_id.id)]
}}