[FIX] hr_timesheet:allow timesheet creation on companyless account

This commit's purpose is to allow the creation of timesheet even if the
analytic account of the project has no company_id

closes odoo/odoo#112906

Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
damr
2023-02-16 17:57:11 +01:00
committed by Xavier BOL (xbo)
parent 374a98be6c
commit a0a0f06ce3
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -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):
@@ -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")