From 07670d41a8a1d950fc0d4a3fd89baa9ae654e294 Mon Sep 17 00:00:00 2001 From: yograj tandel Date: Fri, 10 Sep 2021 13:18:50 +0000 Subject: [PATCH] [FIX] hr_timesheet: fix traceback after unistalling timesheet Currently when unistall the hr_timesheet and try to open the project menu it generates an traceback due to invalid field in domain of the action. so in this commit fix the traceback by adding the unistallation hook so domain will be replaced on unistallation of the hr_timesheet. also archive the internal project when unistalling the hr_timesheet. Task-2629395 closes odoo/odoo#78063 X-original-commit: 8fe71cd7ff412a01b6f7dbaf569f7b85fbffd631 Related: odoo/enterprise#21551 Signed-off-by: LTU-Odoo --- addons/hr_timesheet/__init__.py | 16 ++++++++++++++++ addons/hr_timesheet/__manifest__.py | 1 + 2 files changed, 17 insertions(+) diff --git a/addons/hr_timesheet/__init__.py b/addons/hr_timesheet/__init__.py index 5556aba9fe4..40e30693026 100644 --- a/addons/hr_timesheet/__init__.py +++ b/addons/hr_timesheet/__init__.py @@ -32,3 +32,19 @@ def create_internal_project(cr, registry): } for task in project_ids.task_ids.filtered(lambda t: t.company_id in admin.employee_ids.company_id)]) _check_exists_collaborators_for_project_sharing(env) + +def _uninstall_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + xml_ids = [ + 'project.open_view_project_all', + 'project.open_view_project_all_group_stage' + ] + for xml_id in xml_ids: + act_window = env.ref(xml_id, raise_if_not_found=False) + if act_window and act_window.domain and 'is_internal_project' in act_window.domain: + act_window.domain = [] + + # archive the internal projects + project_ids = env['res.company'].search([('internal_project_id', '!=', False)]).mapped('internal_project_id') + if project_ids: + project_ids.write({'active': False}) diff --git a/addons/hr_timesheet/__manifest__.py b/addons/hr_timesheet/__manifest__.py index c88c3de9d29..030603290fe 100644 --- a/addons/hr_timesheet/__manifest__.py +++ b/addons/hr_timesheet/__manifest__.py @@ -46,6 +46,7 @@ up a management by affair. 'application': False, 'auto_install': False, 'post_init_hook': 'create_internal_project', + 'uninstall_hook': '_uninstall_hook', 'assets': { 'web.assets_backend': [ 'hr_timesheet/static/src/scss/timesheets_task_form.scss',