Skip to content

Commit

Permalink
[FIX] hr_timesheet: changing project resets the employee
Browse files Browse the repository at this point in the history
The preprocess method checked if the project_id value
was given to determine if it was a timesheet or a normal
analytic line (since a timesheet is an AAL with project_id).
The problem came in the write, when changing only the project
value, the preprocess use the timesheet case, but since the
employee field was not changed, no value was passed, and it
compute the default one. So changing the project of an existing
timesheet reset the employee to the current one.
  • Loading branch information
jem-odoo committed Apr 9, 2018
1 parent 8decf4c commit 9b92732
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions addons/hr_timesheet/models/hr_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def _compute_department_id(self):

@api.model
def create(self, vals):
# compute employee only for timesheet lines, makes no sense for other lines
if not vals.get('employee_id') and vals.get('project_id'):
if vals.get('user_id'):
ts_user_id = vals['user_id']
else:
ts_user_id = self._default_user()
vals['employee_id'] = self.env['hr.employee'].search([('user_id', '=', ts_user_id)], limit=1).id
vals = self._timesheet_preprocess(vals)
return super(AccountAnalyticLine, self).create(vals)

Expand All @@ -62,11 +69,4 @@ def _timesheet_preprocess(self, vals):
if vals.get('employee_id') and not vals.get('user_id'):
employee = self.env['hr.employee'].browse(vals['employee_id'])
vals['user_id'] = employee.user_id.id
# compute employee only for timesheet lines, makes no sense for other lines
if not vals.get('employee_id') and vals.get('project_id'):
if vals.get('user_id'):
ts_user_id = vals['user_id']
else:
ts_user_id = self._default_user()
vals['employee_id'] = self.env['hr.employee'].search([('user_id', '=', ts_user_id)], limit=1).id
return vals

0 comments on commit 9b92732

Please sign in to comment.