Skip to content
Snippets Groups Projects
Commit 9b927325 authored by Jérome Maes's avatar Jérome Maes
Browse files

[FIX] hr_timesheet: changing project resets the employee

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.
parent 8decf4c9
Branches
Tags
No related merge requests found
......@@ -41,6 +41,13 @@ class AccountAnalyticLine(models.Model):
@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)
......@@ -62,11 +69,4 @@ class AccountAnalyticLine(models.Model):
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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment