From 38f897e0a8a0c098e0d23cb86e3181d4b40108e1 Mon Sep 17 00:00:00 2001 From: "Laurent Stukkens (LTU)" Date: Wed, 15 Dec 2021 09:07:43 +0000 Subject: [PATCH] [IMP] hr_timesheet,project: use name_get to add Internal project's company Before this commit: - The name of the company was appended to the name of the Internal Project, having it even when only one Company was in the database. After this commit: - The name of the company will only be appended by the name_get when more than one company is present in the database. task-2608812 Closes: #79926 Related: odoo/enterprise#20514 Signed-off-by: Laurent Stukkens (ltu) --- addons/hr_timesheet/models/project.py | 10 ++++++++++ addons/hr_timesheet/models/res_company.py | 2 +- addons/project/views/project_views.xml | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 89962337715..5271b6fd8b7 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -183,6 +183,16 @@ class Project(models.Model): project._create_analytic_account() return super(Project, self).write(values) + def name_get(self): + res = super().name_get() + if len(self.env.context.get('allowed_company_ids', [])) <= 1: + return res + name_mapping = dict(res) + for project in self: + if project.is_internal_project: + name_mapping[project.id] = f'{name_mapping[project.id]} - {project.company_id.name}' + return list(name_mapping.items()) + @api.model def _init_data_analytic_account(self): self.search([('analytic_account_id', '=', False), ('allow_timesheets', '=', True)])._create_analytic_account() diff --git a/addons/hr_timesheet/models/res_company.py b/addons/hr_timesheet/models/res_company.py index de1ba261311..888c8ae7225 100644 --- a/addons/hr_timesheet/models/res_company.py +++ b/addons/hr_timesheet/models/res_company.py @@ -61,7 +61,7 @@ class ResCompany(models.Model): for company in self: company = company.with_company(company) results += [{ - 'name': _('Internal - %s', company.name), + 'name': _('Internal'), 'allow_timesheets': True, 'company_id': company.id, 'type_ids': type_ids, diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml index 1a8b2b1f9f3..91317a6f3f6 100644 --- a/addons/project/views/project_views.xml +++ b/addons/project/views/project_views.xml @@ -551,7 +551,7 @@ - + @@ -648,7 +648,7 @@ project.project - + @@ -677,7 +677,7 @@
- +