Skip to content
Snippets Groups Projects
Commit 92e420ea authored by Victor Piryns (pivi)'s avatar Victor Piryns (pivi)
Browse files

[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#117259

X-original-commit: b39642bf
Signed-off-by: default avatarXavier Bol (xbo) <xbo@odoo.com>
Signed-off-by: default avatarPiryns Victor (pivi) <pivi@odoo.com>
parent 508f2a9a
No related branches found
No related tags found
No related merge requests found
......@@ -296,7 +296,14 @@ class AccountAnalyticLine(models.Model):
# set timesheet UoM from the AA company (AA implies uom)
if not vals.get('product_uom_id') and all(v in vals for v in ['account_id', 'project_id']): # project_id required to check this is timesheet flow
analytic_account = self.env['account.analytic.account'].sudo().browse(vals['account_id'])
vals['product_uom_id'] = analytic_account.company_id.project_time_mode_id.id
uom_id = analytic_account.company_id.project_time_mode_id.id
if not uom_id:
company_id = vals.get('company_id', False)
if not company_id:
project = self.env['project.project'].browse(vals.get('project_id'))
company_id = project.analytic_account_id.company_id.id or project.company_id.id
uom_id = self.env['res.company'].browse(company_id).project_time_mode_id.id
vals['product_uom_id'] = uom_id
return vals
def _timesheet_postprocess(self, values):
......
......@@ -570,3 +570,12 @@ class TestTimesheet(TestCommonTimesheet):
self.env.company.timesheet_encode_uom_id = self.env.ref('uom.product_uom_day')
self.assertEqual(project.total_timesheet_time, 8, "Total timesheet time should be 8 hours")
self.assertEqual(project.timesheet_encode_uom_id.name, 'Days', "Timesheet encode uom should be 'Days'")
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.assertEqual(timesheet.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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment