diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 7778eed399d..42ce7a8d4c8 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -327,7 +327,7 @@ 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[account_per_id[vals['account_id']].company_id] + vals['product_uom_id'] = uom_id_per_company.get(account_per_id[vals['account_id']].company_id, False) 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 0f2c3c5e500..4390e3bc70d 100644 --- a/addons/hr_timesheet/tests/test_timesheet.py +++ b/addons/hr_timesheet/tests/test_timesheet.py @@ -549,3 +549,9 @@ class TestTimesheet(TestCommonTimesheet): ('hr_timesheet.view_task_project_user_graph_inherited', '//field[@name="planned_hours"]', [None, 'Initially Planned Days']), ('hr_timesheet.timesheets_analysis_report_pivot_employee', '//field[@name="unit_amount"]', [None, 'Days Spent']), ]) + + 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")