[FIX] hr_timesheet: timesheet uom fallback when AAL's company is False

Current behaviour:
When creating a timesheet, if in the vals passed the AAL doesn't
have a company (possible since it's not required), then the `uom`
of the timesheet is False, which doesn't make sense.

Expected behaviour:
The timesheet `uom` should fallback on the uom of the company
of the project.

Steps to reproduce:
- Install hr_timesheet, Accounting
- Activate the AAL in the settings
- Create a project with an AAL
- Remove the company on the AAL of the project
- In that project create a task and log some timesheet.
- `uom` field should be empty

Reason for the problem:
When setting the `product_uom_id` in the vals when creating/writing
a timesheet, we just take the `project_time_mode_id` on the company
linked to the AAL. The problem is that the company on an AAL is not
a required field, so it can be `False`, leading the setting the val
for `product_uom_id` to `False`.

Fix:
In case the AAL has no company, we get the `uom` from the company
linked to the project.

Affected versions:
- 14.0
- 15.0
- saas-15.2
- 16.0
- saas-16.1
- saas-16.2
- master

opw-3245671

closes odoo/odoo#117834

X-original-commit: 4cce77bd0288eeb3326ba57e91ef11d436f8a0ce
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
Signed-off-by: Piryns Victor (pivi) <pivi@odoo.com>
This commit is contained in:
Victor Piryns (pivi)
2023-04-06 07:42:52 +02:00
parent 374d55b3c8
commit e48e517072
2 changed files with 13 additions and 3 deletions
+2 -1
View File
@@ -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):
+11 -2
View File
@@ -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({