-
-
Notifications
You must be signed in to change notification settings - Fork 812
[19.0][MIG] hr_recruitment #5612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hbrunn
wants to merge
1
commit into
OCA:19.0
Choose a base branch
from
hbrunn:19.0-hr_recruitment
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
openupgrade_scripts/scripts/hr_recruitment/19.0.1.1/post-migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # Copyright 2026 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| _deleted_xmlids = [ | ||
| "hr_recruitment.hr_candidate_comp_rule", | ||
| "hr_recruitment.hr_candidate_interviewer_rule", | ||
| "hr_recruitment.hr_candidate_user_rule", | ||
| ] | ||
|
|
||
|
|
||
| def hr_candidate2hr_applicant(env): | ||
| """ | ||
| hr.candidate and hr.applicant have been merged. Copy data for nonstored related | ||
| v18 fields from hr_candidate to hr_applicant where they are stored in v19. | ||
| """ | ||
| field_names = [ | ||
| "availability", | ||
| "color", | ||
| "email_from", | ||
| "email_normalized", | ||
| "employee_id", | ||
| "linkedin_profile", | ||
| "partner_id", | ||
| "partner_name", | ||
| "partner_phone", | ||
| "partner_phone_sanitized", | ||
| "type_id", | ||
| "message_bounce", | ||
| ] | ||
| updates = ", ".join( | ||
| f"{field_name} = hr_candidate.{field_name}" for field_name in field_names | ||
| ) | ||
| updates += ", phone_sanitized=hr_candidate.partner_phone_sanitized" | ||
|
|
||
| env.cr.execute( | ||
| f""" | ||
| UPDATE hr_applicant | ||
| SET | ||
| {updates} | ||
| FROM {openupgrade.get_legacy_name("hr_candidate")} hr_candidate | ||
| WHERE | ||
| hr_applicant.candidate_id=hr_candidate.id | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def hr_candidate_properties2hr_applicant_properties(env): | ||
| """ | ||
| Merge applicant and candidate properties | ||
| Merge property definitions from companies into jobs' applicant property definitions | ||
| if there are v18 candidates setting them. | ||
| Ignore applicants not linked to a job | ||
| """ | ||
| env.cr.execute( | ||
| f""" | ||
| UPDATE hr_applicant | ||
| SET applicant_properties= | ||
| COALESCE(applicant_properties, '{{}}') || | ||
| hr_candidate.candidate_properties | ||
| FROM {openupgrade.get_legacy_name("hr_candidate")} hr_candidate | ||
| WHERE | ||
| hr_applicant.candidate_id=hr_candidate.id | ||
| AND | ||
| hr_candidate.candidate_properties IS NOT NULL | ||
| """ | ||
| ) | ||
| if env.cr.rowcount: | ||
| env.cr.execute( | ||
| f""" | ||
| UPDATE hr_job | ||
| SET applicant_properties_definition= | ||
| COALESCE(applicant_properties_definition, '[]') || | ||
| res_company.candidate_properties_definition | ||
| FROM res_company | ||
| WHERE | ||
| ( | ||
| hr_job.company_id=res_company.id | ||
| OR | ||
| hr_job.company_id IS NULL | ||
| ) | ||
| AND | ||
| res_company.candidate_properties_definition IS NOT NULL | ||
| AND | ||
| exists ( | ||
| SELECT | ||
| hr_applicant.id | ||
| FROM hr_applicant | ||
| JOIN | ||
| {openupgrade.get_legacy_name("hr_candidate")} hr_candidate | ||
| ON hr_applicant.candidate_id=hr_candidate.id | ||
| WHERE | ||
| hr_candidate.candidate_properties IS NOT NULL | ||
| AND | ||
| hr_applicant.job_id=hr_job.id | ||
| AND | ||
| hr_candidate.company_id=res_company.id | ||
| ) | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "hr_recruitment", "19.0.1.1/noupdate_changes.xml") | ||
| openupgrade.delete_record_translations( | ||
| env.cr, | ||
| "hr_recruitment", | ||
| [ | ||
| "email_template_data_applicant_congratulations", | ||
| "email_template_data_applicant_interest", | ||
| "email_template_data_applicant_not_interested", | ||
| "email_template_data_applicant_refuse", | ||
| ], | ||
| ["body_html"], | ||
| ) | ||
| openupgrade.delete_records_safely_by_xml_id(env, _deleted_xmlids) | ||
| hr_candidate2hr_applicant(env) | ||
| hr_candidate_properties2hr_applicant_properties(env) |
23 changes: 23 additions & 0 deletions
23
openupgrade_scripts/scripts/hr_recruitment/19.0.1.1/pre-migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Copyright 2026 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def hr_candidate2hr_applicant(env): | ||
| """ | ||
| Prepare merging hr.candidate into hr.applicant: | ||
| Merge models | ||
| Rename hr_candidate to legacy table | ||
| Lift constraints on hr_candidate.id | ||
| """ | ||
| openupgrade.merge_models(env.cr, "hr.candidate", "hr.applicant", "candidate_id") | ||
| openupgrade.rename_tables(env.cr, [("hr_candidate", None)]) | ||
| openupgrade.lift_constraints( | ||
| env.cr, openupgrade.get_legacy_name("hr_candidate"), "id", cascade=True | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| hr_candidate2hr_applicant(env) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaner and safer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they do different things, I think we need both actually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought all the things that
lift_constraintsdoes are included inremove_tables_fks. If not, then put both 🤷♂️