diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 96ba98a2431..1b669377921 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -338,7 +338,8 @@ class AccountAnalyticLine(models.Model): if not vals.get('partner_id'): vals['partner_id'] = data.partner_id.id if not vals.get('product_uom_id'): - vals['product_uom_id'] = uom_id_per_company.get(account_per_id[vals['account_id']].company_id, False) + company = account_per_id[vals['account_id']].company_id or data.company_id + vals['product_uom_id'] = uom_id_per_company.get(company.id, company.project_time_mode_id.id) return vals_list def _timesheet_postprocess(self, values): diff --git a/addons/hr_timesheet/tests/test_timesheet.py b/addons/hr_timesheet/tests/test_timesheet.py index b5b81687f2f..920abffdb0c 100644 --- a/addons/hr_timesheet/tests/test_timesheet.py +++ b/addons/hr_timesheet/tests/test_timesheet.py @@ -552,8 +552,17 @@ class TestTimesheet(TestCommonTimesheet): def test_create_timesheet_with_companyless_analytic_account(self): """ This test ensures that a timesheet can be created on an analytic account whose company_id is set to False""" 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") + timesheet_with_project = self.env['account.analytic.line'].with_user(self.user_employee).create( + {'unit_amount': 1.0, 'project_id': self.project_customer.id}) + self.assertEqual(timesheet_with_project.product_uom_id, self.project_customer.company_id.project_time_mode_id, + "The product_uom_id of the timesheet should be equal to the project's company uom " + "if the project's analytic account has no company_id and no task_id is defined in the vals") + timesheet_with_task = self.env['account.analytic.line'].with_user(self.user_employee).create({ + 'unit_amount': 1.0, 'task_id': self.task1.id + }) + self.assertEqual(timesheet_with_task.product_uom_id, self.task1.company_id.project_time_mode_id, + "The product_uom_id of the timesheet should be equal to the task's company uom " + "if the project's 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({