[FIX] hr_timesheet: create timesheet with default employee in context
Before this commit, the default employee set in the context to create a timesheet is unused in the create method. This commit uses the context to set the employee when no user and no employee are given in the vals parameter. task-2702636 Part-of: odoo/odoo#108605
This commit is contained in:
committed by
Xavier Bol (xbo)
parent
cec042e8f9
commit
dd9ee7e493
@@ -145,12 +145,13 @@ class AccountAnalyticLine(models.Model):
|
||||
continue
|
||||
if not vals.get('name'):
|
||||
vals['name'] = '/'
|
||||
employee_id = vals.get('employee_id')
|
||||
user_id = vals.get('user_id', default_user_id)
|
||||
employee_id = vals.get('employee_id', self._context.get('default_employee_id', False))
|
||||
if employee_id and employee_id not in employee_ids:
|
||||
employee_ids.append(employee_id)
|
||||
elif user_id not in user_ids:
|
||||
user_ids.append(user_id)
|
||||
else:
|
||||
user_id = vals.get('user_id', default_user_id)
|
||||
if user_id not in user_ids:
|
||||
user_ids.append(user_id)
|
||||
|
||||
# 2/ Search all employees related to user_ids and employee_ids, in the selected companies
|
||||
employees = self.env['hr.employee'].sudo().search([
|
||||
@@ -176,7 +177,7 @@ class AccountAnalyticLine(models.Model):
|
||||
for vals in vals_list:
|
||||
if not vals.get('project_id'):
|
||||
continue
|
||||
employee_in_id = vals.get('employee_id')
|
||||
employee_in_id = vals.get('employee_id', self._context.get('default_employee_id', False))
|
||||
if employee_in_id:
|
||||
if employee_in_id in valid_employee_per_id:
|
||||
vals['user_id'] = valid_employee_per_id[employee_in_id].sudo().user_id.id # (A) OK
|
||||
|
||||
@@ -555,3 +555,12 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
self.project_customer.analytic_account_id.company_id = False
|
||||
timesheet = self.env['account.analytic.line'].with_user(self.user_employee).create({'unit_amount': 1.0, 'project_id': self.project_customer.id})
|
||||
self.assertFalse(timesheet.product_uom_id, "The product_uom_id of the timesheet should be set to False for its analytic account has no company_id")
|
||||
|
||||
def test_create_timesheet_with_default_employee_in_context(self):
|
||||
timesheet = self.env['account.analytic.line'].with_context(default_employee_id=self.empl_employee.id).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': 'Timesheet with default employee in context',
|
||||
'unit_amount': 3,
|
||||
})
|
||||
self.assertEqual(timesheet.employee_id, self.empl_employee)
|
||||
|
||||
Reference in New Issue
Block a user