diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index fc9282d7892..cbf2cbe305c 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -373,7 +373,7 @@ class AccountAnalyticLine(models.Model): vals['partner_id'] = data.partner_id.id if not vals.get('product_uom_id'): 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) + vals['product_uom_id'] = uom_id_per_company.get(company.id, company.project_time_mode_id.id) or self.env.company.project_time_mode_id.id return vals_list def _timesheet_postprocess(self, values): diff --git a/addons/hr_timesheet/tests/test_performance.py b/addons/hr_timesheet/tests/test_performance.py index b5663d3d54e..f0d0082e573 100644 --- a/addons/hr_timesheet/tests/test_performance.py +++ b/addons/hr_timesheet/tests/test_performance.py @@ -2,7 +2,9 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.hr_timesheet.tests.test_timesheet import TestCommonTimesheet +from odoo.tests import tagged +@tagged('post_install', '-at_install') class TestPerformanceTimesheet(TestCommonTimesheet): def test_timesheet_preprocess(self): @@ -13,7 +15,7 @@ class TestPerformanceTimesheet(TestCommonTimesheet): } for i in range(17) for project in projects]) self.env.invalidate_all() self.env.registry.clear_cache() - with self.assertQueryCount(5): + with self.assertQueryCount(8): self.env['account.analytic.line']._timesheet_preprocess([ {'task_id': task.id} for task in tasks for _i in range(10) ]) diff --git a/addons/hr_timesheet/tests/test_timesheet.py b/addons/hr_timesheet/tests/test_timesheet.py index 92d7d6574ae..a571b33d4ab 100644 --- a/addons/hr_timesheet/tests/test_timesheet.py +++ b/addons/hr_timesheet/tests/test_timesheet.py @@ -594,6 +594,14 @@ class TestTimesheet(TestCommonTimesheet): 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") + # Remove the company also on the project to be sure we find a UoM + self.project_customer.company_id = False + timesheet_with_project.with_user(self.user_employee).write( + {'unit_amount': 2.0, 'project_id': self.project_customer.id}) + self.assertEqual(timesheet_with_project.product_uom_id, self.env.company.project_time_mode_id, + "The product_uom_id of the timesheet should be equal to the company uom " + "if the project's analytic account and the project have 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({