From bf696b054e52edd275352054af47059761f2743c Mon Sep 17 00:00:00 2001 From: sofiagvaladze Date: Wed, 17 Apr 2024 13:56:26 +0000 Subject: [PATCH] [FIX] hr_recruitment_survey: correct the rule The survey.survey_user_input_rule_survey_user_read rule is override in both hr_appraisal_survey and in hr_recruitment_survey. The problem arises when both modules are installed. If so, the domain is taken from the module that is installed the last. This should not be case, instead domain should be combined. On top of it, the domain is not corrected when the app is unistalled. This commit fixes that too task - 3597033 closes odoo/odoo#163138 X-original-commit: 5d4b5175855041efd6174fe5e35f06ede3b62818 Related: odoo/enterprise#61363 Signed-off-by: Bertrand Dossogne (bedo) Signed-off-by: Sofie Gvaladze (sgv) --- addons/hr_recruitment_survey/__init__.py | 16 ++++++++++++++++ addons/hr_recruitment_survey/__manifest__.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/addons/hr_recruitment_survey/__init__.py b/addons/hr_recruitment_survey/__init__.py index f2cd96d8c83..40820b4f849 100644 --- a/addons/hr_recruitment_survey/__init__.py +++ b/addons/hr_recruitment_survey/__init__.py @@ -3,3 +3,19 @@ from . import models from . import wizard from . import controllers + + +def _correct_survey_rule(env): + # if hr_appraisal_survey is alrady installed we need to override survey.survey_user_input_rule_survey_user_read + # because otherwise domain that is set in hr_appraisal_survey is wiped out + if env['ir.module.module'].search([('name', '=', 'hr_appraisal_survey'), ('state', '=', 'installed')]): + record = env.ref("survey.survey_user_input_rule_survey_user_read", raise_if_not_found=False) + if record: + record.domain_force = [('applicant_id', '=', False), ('survey_id.survey_type', '!=', 'appraisal')] + + +def uninstall_hook(env): + rule = env.ref("survey.survey_user_input_rule_survey_user_read", raise_if_not_found=False) + if rule: + domain = "('applicant_id', '=', False)" + rule.domain_force = rule.domain_force.replace(domain, "(1, '=', 1)") diff --git a/addons/hr_recruitment_survey/__manifest__.py b/addons/hr_recruitment_survey/__manifest__.py index 9bc22bb22c0..508a89a946b 100644 --- a/addons/hr_recruitment_survey/__manifest__.py +++ b/addons/hr_recruitment_survey/__manifest__.py @@ -22,4 +22,6 @@ to allow you to define interviews for different jobs. 'data/hr_job_demo.xml', ], 'license': 'LGPL-3', + 'post_init_hook': '_correct_survey_rule', + 'uninstall_hook': 'uninstall_hook', }