-
-
Notifications
You must be signed in to change notification settings - Fork 785
[17.0][OU-ADD] hr: migration to 17.0 #4462
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,28 @@ | ||
| # Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def _merge_employee_contact(env): | ||
| """ | ||
| Performing merge 'address_home_id' into 'work_contact_id' | ||
| """ | ||
| partner_merge_wizard = env["base.partner.merge.automatic.wizard"] | ||
| partner = env["res.partner"] | ||
| env.cr.execute( | ||
| """ | ||
| SELECT address_home_id, work_contact_id | ||
| FROM hr_employee | ||
| WHERE work_contact_id IS NOT NULL AND address_home_id IS NOT NULL | ||
| AND work_contact_id<>address_home_id | ||
| """ | ||
| ) | ||
| for address_home_id, work_contact_id in env.cr.fetchall(): | ||
| partner_merge_wizard._merge( | ||
| [address_home_id, work_contact_id], partner.browse(work_contact_id) | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| _merge_employee_contact(env) | ||
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,26 @@ | ||
| # Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| _deleted_xml_records = [ | ||
| "hr.dep_sales", | ||
pedrobaeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "hr.openupgrade_legacy_17_0_offboarding_plan", | ||
| "hr.openupgrade_legacy_17_0_onboarding_plan", | ||
| "hr.openupgrade_legacy_17_0_offboarding_setup_compute_out_delais", | ||
| "hr.openupgrade_legacy_17_0_offboarding_take_back_hr_materials", | ||
| "hr.openupgrade_legacy_17_0_onboarding_plan_training", | ||
| "hr.openupgrade_legacy_17_0_onboarding_setup_it_materials", | ||
| "hr.openupgrade_legacy_17_0_onboarding_training", | ||
| "hr.hr_plan_activity_type_company_rule", | ||
| "hr.hr_plan_company_rule", | ||
| ] | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "hr", "17.0.1.1/noupdate_changes.xml") | ||
| openupgrade.delete_records_safely_by_xml_id( | ||
| env, | ||
| _deleted_xml_records, | ||
| ) | ||
151 changes: 151 additions & 0 deletions
151
openupgrade_scripts/scripts/hr/17.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,151 @@ | ||
| # Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from openupgradelib import openupgrade | ||
|
|
||
| _xmlids_renames = [ | ||
| ( | ||
| "hr.offboarding_plan", | ||
| "hr.openupgrade_legacy_17_0_offboarding_plan", | ||
| ), | ||
| ( | ||
| "hr.onboarding_plan", | ||
| "hr.openupgrade_legacy_17_0_onboarding_plan", | ||
| ), | ||
| ( | ||
| "hr.offboarding_setup_compute_out_delais", | ||
| "hr.openupgrade_legacy_17_0_offboarding_setup_compute_out_delais", | ||
| ), | ||
| ( | ||
| "hr.offboarding_take_back_hr_materials", | ||
| "hr.openupgrade_legacy_17_0_offboarding_take_back_hr_materials", | ||
| ), | ||
| ( | ||
| "hr.onboarding_plan_training", | ||
| "hr.openupgrade_legacy_17_0_onboarding_plan_training", | ||
| ), | ||
| ( | ||
| "hr.onboarding_setup_it_materials", | ||
| "hr.openupgrade_legacy_17_0_onboarding_setup_it_materials", | ||
| ), | ||
| ( | ||
| "hr.onboarding_training", | ||
| "hr.openupgrade_legacy_17_0_onboarding_training", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def _hr_plan_sync_to_mail_activity_plan(env): | ||
| employee_model = env["ir.model"].search([("model", "=", "hr.employee")]) | ||
| # Because when loading noupdate, we might create some duplicate plan data | ||
| # Therefore check if those plan data still exist then skip insert | ||
| env.cr.execute( | ||
| """ | ||
| SELECT res_id FROM ir_model_data | ||
| WHERE model='hr.plan' AND | ||
| name in ('offboarding_plan', 'onboarding_plan') | ||
| """ | ||
| ) | ||
| hr_plan_ids = tuple([d[0] for d in env.cr.fetchall()]) | ||
|
|
||
| # sync hr.plan to mail.activity.plan | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| ALTER TABLE mail_activity_plan ADD COLUMN IF NOT EXISTS department_id INTEGER, | ||
| ADD COLUMN IF NOT EXISTS hr_plan_legacy_id INTEGER; | ||
| """, | ||
| ) | ||
| hr_plan_query = f""" | ||
| INSERT INTO mail_activity_plan (company_id, res_model_id, create_uid, | ||
| write_uid, name, res_model, active, create_date, write_date, department_id, | ||
| hr_plan_legacy_id | ||
| ) | ||
| SELECT company_id, {employee_model.id}, create_uid, write_uid, name, | ||
| '{employee_model.model}', active, create_date, write_date, department_id, id | ||
| FROM hr_plan t | ||
| """ | ||
| if hr_plan_ids: | ||
| hr_plan_query += f" WHERE t.id NOT IN {hr_plan_ids}" | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| hr_plan_query, | ||
| ) | ||
|
|
||
| # sync hr.plan.activitype.type to mail.activity.plan.template | ||
| hr_plan_activity_type_query = """ | ||
| INSERT INTO mail_activity_plan_template (activity_type_id, responsible_id, | ||
| plan_id, responsible_type, summary, note, create_uid, write_uid, create_date, | ||
| write_date | ||
| ) | ||
| SELECT activity_type_id, responsible_id, t2.id plan_id, responsible, summary, | ||
| note, t1.create_uid, t1.write_uid, t1.create_date, t1.write_date | ||
| FROM hr_plan_activity_type t1, mail_activity_plan t2 | ||
| WHERE t1.plan_id = t2.hr_plan_legacy_id | ||
| """ | ||
| if hr_plan_ids: | ||
| hr_plan_activity_type_query += f" AND t1.plan_id NOT IN {hr_plan_ids}" | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| hr_plan_activity_type_query, | ||
| ) | ||
| # Drop hr_plan_legacy_id column | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| ALTER TABLE mail_activity_plan DROP COLUMN hr_plan_legacy_id; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _employee_sync_address_home_id(env): | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| ALTER TABLE hr_employee | ||
| ADD COLUMN IF NOT EXISTS lang VARCHAR, | ||
| ADD COLUMN IF NOT EXISTS private_city VARCHAR, | ||
| ADD COLUMN IF NOT EXISTS private_country_id INTEGER, | ||
| ADD COLUMN IF NOT EXISTS private_email VARCHAR, | ||
| ADD COLUMN IF NOT EXISTS private_phone VARCHAR, | ||
| ADD COLUMN IF NOT EXISTS private_state_id INTEGER, | ||
| ADD COLUMN IF NOT EXISTS private_street VARCHAR, | ||
| ADD COLUMN IF NOT EXISTS private_street2 VARCHAR, | ||
| ADD COLUMN IF NOT EXISTS private_zip VARCHAR; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE hr_employee t1 | ||
| SET lang = t2.lang, | ||
| private_city = t2.city, | ||
| private_country_id = t2.country_id, | ||
| private_email = t2.email, | ||
| private_phone = t2.phone, | ||
| private_state_id = t2.state_id, | ||
| private_street = t2.street, | ||
| private_street2 = t2.street2, | ||
| private_zip = t2.zip | ||
| FROM res_partner t2 | ||
| WHERE t1.address_home_id = t2.id | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _hr_work_location_fill_location_type(env): | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| ALTER TABLE hr_work_location ADD COLUMN IF NOT EXISTS location_type VARCHAR; | ||
| UPDATE hr_work_location | ||
| SET location_type = 'office' | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| _hr_plan_sync_to_mail_activity_plan(env) | ||
| openupgrade.rename_xmlids(env.cr, _xmlids_renames) | ||
| _employee_sync_address_home_id(env) | ||
| _hr_work_location_fill_location_type(env) |
158 changes: 158 additions & 0 deletions
158
openupgrade_scripts/scripts/hr/17.0.1.1/upgrade_analysis_work.txt
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,158 @@ | ||
| ---Models in module 'hr'--- | ||
| obsolete model hr.plan | ||
| obsolete model hr.plan.activity.type | ||
| # DONE pre-migration: move data into mail.activity.plan | ||
|
|
||
| obsolete model hr.plan.wizard [transient] | ||
| # NOTHING TO DO | ||
|
|
||
| ---Fields in module 'hr'--- | ||
| hr / discuss.channel / subscription_department_ids (many2many): NEW relation: hr.department | ||
| hr / mail.channel / subscription_department_ids (many2many): DEL relation: hr.department | ||
| # NOTHING TO DO | ||
pedrobaeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| hr / hr.contract.type / code (char) : NEW hasdefault: compute | ||
| # TODO pre-migration: create column and fill value using 'name' | ||
|
|
||
| hr / hr.contract.type / country_id (many2one) : NEW relation: res.country | ||
| # NOTHING TO DO: new feature | ||
|
|
||
| hr / hr.department / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| # NOTHING TO DO | ||
|
|
||
| hr / hr.department / plan_ids (one2many) : relation is now 'mail.activity.plan' ('hr.plan') [nothing to do] | ||
| hr / hr.plan / active (boolean) : DEL | ||
| hr / hr.plan / company_id (many2one) : DEL relation: res.company | ||
| hr / hr.plan / department_id (many2one) : DEL relation: hr.department | ||
| hr / hr.plan / name (char) : DEL required | ||
| hr / hr.plan / plan_activity_type_ids (one2many): DEL relation: hr.plan.activity.type | ||
| hr / hr.plan.activity.type / activity_type_id (many2one) : DEL relation: mail.activity.type | ||
| hr / hr.plan.activity.type / company_id (many2one) : DEL relation: res.company | ||
| hr / hr.plan.activity.type / note (html) : DEL | ||
| hr / hr.plan.activity.type / plan_id (many2one) : DEL relation: hr.plan | ||
| hr / hr.plan.activity.type / responsible (selection) : DEL required, selection_keys: ['coach', 'employee', 'manager', 'other'] | ||
| hr / hr.plan.activity.type / responsible_id (many2one) : DEL relation: res.users | ||
| hr / hr.plan.activity.type / summary (char) : DEL | ||
| hr / mail.activity.plan / department_id (many2one) : NEW relation: hr.department, hasdefault: compute | ||
| hr / mail.activity.plan.template / responsible_type (False) : NEW selection_keys: ['coach', 'employee', 'manager', 'on_demand', 'other'], mode: modify | ||
| # DONE pre-migration: move data into mail.activity.plan | ||
|
|
||
| hr / hr.department / rating_ids (one2many) : NEW relation: rating.rating | ||
| # NOTHING TO DO | ||
|
|
||
| hr / hr.departure.reason / reason_code (integer) : NEW | ||
| # DONE post-migration: load noupdate | ||
|
|
||
| hr / hr.employee / activity_user_id (many2one) : not related anymore | ||
| hr / hr.employee / activity_user_id (many2one) : now a function | ||
| # NOTHING TO DO: no store field | ||
|
|
||
| hr / hr.employee / employee_properties (properties): NEW hasdefault: compute | ||
| hr / res.company / employee_properties_definition (properties_definition): NEW | ||
| hr / hr.employee / private_car_plate (char) : NEW | ||
| # NOTHING TO DO: new feature | ||
|
|
||
| hr / hr.employee / address_home_id (many2one) : DEL relation: res.partner | ||
| hr / hr.employee / lang (selection) : is now stored | ||
| hr / hr.employee / lang (selection) : not related anymore | ||
| hr / hr.employee / private_city (char) : NEW | ||
| hr / hr.employee / private_country_id (many2one) : NEW relation: res.country | ||
| hr / hr.employee / private_email (char) : is now stored | ||
| hr / hr.employee / private_email (char) : not related anymore | ||
| hr / hr.employee / private_phone (char) : NEW | ||
| hr / hr.employee / private_state_id (many2one) : NEW relation: res.country.state | ||
| hr / hr.employee / private_street (char) : NEW | ||
| hr / hr.employee / private_street2 (char) : NEW | ||
| hr / hr.employee / private_zip (char) : NEW | ||
| # DONE pre_migration: create column and fill value from address_home_id and merge merge 'address_home_id' into 'work_contact_id' at end-migration | ||
|
|
||
| hr / hr.employee / rating_ids (one2many) : NEW relation: rating.rating | ||
| hr / hr.job / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| hr / hr.job / rating_ids (one2many) : NEW relation: rating.rating | ||
| # NOTHING TO DO: | ||
|
|
||
| hr / hr.work.location / location_type (selection) : NEW required, selection_keys: ['home', 'office', 'other'], hasdefault: default | ||
| # TODO pre-migration: create column and update it with default value | ||
|
|
||
| ---XML records in module 'hr'--- | ||
| NEW hr.contract.type: hr.contract_type_full_time (noupdate) | ||
| NEW hr.contract.type: hr.contract_type_part_time (noupdate) | ||
| NEW hr.contract.type: hr.contract_type_permanent (noupdate) | ||
| NEW hr.contract.type: hr.contract_type_seasonal (noupdate) | ||
| NEW hr.contract.type: hr.contract_type_temporary (noupdate) | ||
| # NOTHING TO DO | ||
|
|
||
| DEL hr.department: hr.dep_sales (noupdate) | ||
| # DONE: removed in pre-migration | ||
pedrobaeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| DEL hr.plan: hr.offboarding_plan (noupdate) | ||
| DEL hr.plan: hr.onboarding_plan (noupdate) | ||
| DEL hr.plan.activity.type: hr.offboarding_setup_compute_out_delais (noupdate) | ||
| DEL hr.plan.activity.type: hr.offboarding_take_back_hr_materials (noupdate) | ||
| DEL hr.plan.activity.type: hr.onboarding_plan_training (noupdate) | ||
| DEL hr.plan.activity.type: hr.onboarding_setup_it_materials (noupdate) | ||
| DEL hr.plan.activity.type: hr.onboarding_training (noupdate) | ||
| # DONE: renamed in pre-migration and removed in post-migration | ||
pedrobaeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| NEW hr.work.location: hr.home_work_location (noupdate) | ||
| NEW hr.work.location: hr.home_work_office (noupdate) | ||
| NEW hr.work.location: hr.home_work_other (noupdate) | ||
| NEW ir.actions.act_window: hr.mail_activity_plan_action | ||
| DEL ir.actions.act_window: hr.hr_employee_action_from_user | ||
| DEL ir.actions.act_window: hr.hr_plan_action | ||
| DEL ir.actions.act_window: hr.hr_plan_activity_type_action | ||
| NEW ir.actions.act_window.view: hr.mail_activity_plan_action_employee_view_form | ||
| NEW ir.actions.act_window.view: hr.mail_activity_plan_action_employee_view_tree | ||
| NEW ir.model.access: hr.access_mail_activity_plan_hr_manager | ||
| NEW ir.model.access: hr.access_mail_activity_plan_template_hr_manager | ||
| DEL ir.model.access: hr.access_hr_plan_activity_type_employee | ||
| DEL ir.model.access: hr.access_hr_plan_activity_type_hr_user | ||
| DEL ir.model.access: hr.access_hr_plan_employee | ||
| DEL ir.model.access: hr.access_hr_plan_hr_user | ||
| DEL ir.model.access: hr.access_hr_plan_wizard | ||
| DEL ir.model.constraint: hr.constraint_hr_employee_barcode_uniq | ||
| DEL ir.model.constraint: hr.constraint_hr_employee_category_name_uniq | ||
| DEL ir.model.constraint: hr.constraint_hr_employee_user_uniq | ||
| DEL ir.model.constraint: hr.constraint_hr_job_name_company_uniq | ||
| DEL ir.model.constraint: hr.constraint_hr_job_no_of_recruitment_positive | ||
| NEW ir.rule: hr.ir_rule_hr_contract_type_multi_company (noupdate) | ||
| NEW ir.rule: hr.ir_rule_res_partner_bank_employees (noupdate) | ||
| NEW ir.rule: hr.ir_rule_res_partner_bank_internal_users (noupdate) | ||
| NEW ir.rule: hr.mail_plan_rule_group_hr_manager (noupdate) | ||
| NEW ir.rule: hr.mail_plan_templates_rule_group_hr_manager (noupdate) | ||
| # NOTHING TO DO | ||
|
|
||
| DEL ir.rule: hr.hr_plan_activity_type_company_rule (noupdate) | ||
| DEL ir.rule: hr.hr_plan_company_rule (noupdate) | ||
| # DONE: removed in pre-migration | ||
pedrobaeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| NEW ir.ui.menu: hr.menu_resource_calendar_view | ||
| NEW ir.ui.view: hr.discuss_channel_view_form | ||
| NEW ir.ui.view: hr.hr_employee_plan_activity_summary | ||
| NEW ir.ui.view: hr.hr_employee_view_graph | ||
| NEW ir.ui.view: hr.hr_employee_view_pivot | ||
| NEW ir.ui.view: hr.mail_activity_plan_template_view_form | ||
| NEW ir.ui.view: hr.mail_activity_plan_view_form | ||
| NEW ir.ui.view: hr.mail_activity_plan_view_form_hr_employee | ||
| NEW ir.ui.view: hr.mail_activity_plan_view_tree | ||
| NEW ir.ui.view: hr.mail_activity_schedule_view_form | ||
| DEL ir.ui.view: hr.hr_plan_activity_type_view_form | ||
| DEL ir.ui.view: hr.hr_plan_activity_type_view_tree | ||
| DEL ir.ui.view: hr.hr_plan_view_form | ||
| DEL ir.ui.view: hr.hr_plan_view_search | ||
| DEL ir.ui.view: hr.hr_plan_view_tree | ||
| DEL ir.ui.view: hr.mail_channel_view_form_ | ||
| DEL ir.ui.view: hr.plan_wizard | ||
| DEL ir.ui.view: hr.view_employee_form_smartbutton | ||
| DEL ir.ui.view: hr.view_partner_tree2 | ||
| NEW mail.activity.plan: hr.offboarding_plan (noupdate) | ||
| NEW mail.activity.plan: hr.onboarding_plan (noupdate) | ||
| NEW mail.activity.plan.template: hr.offboarding_setup_compute_out_delais (noupdate) | ||
| NEW mail.activity.plan.template: hr.offboarding_take_back_hr_materials (noupdate) | ||
| NEW mail.activity.plan.template: hr.onboarding_plan_training (noupdate) | ||
| NEW mail.activity.plan.template: hr.onboarding_setup_it_materials (noupdate) | ||
| NEW mail.activity.plan.template: hr.onboarding_training (noupdate) | ||
| # NOTHING TO DO | ||
|
|
||
| DEL res.partner: hr.res_partner_admin_private_address (noupdate) | ||
| # DONE: removed in pre-migration | ||
pedrobaeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.