diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 3f20bc287d7c..4ec2b512e33f 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -152,7 +152,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | google_recaptcha |Nothing to do |No analysis file | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| hr |Done (partial) | | +| hr |Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | hr_attendance | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr/17.0.1.1/end-migration.py b/openupgrade_scripts/scripts/hr/17.0.1.1/end-migration.py new file mode 100644 index 000000000000..558e5d7d3008 --- /dev/null +++ b/openupgrade_scripts/scripts/hr/17.0.1.1/end-migration.py @@ -0,0 +1,26 @@ +# 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 + """ + ) + 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) diff --git a/openupgrade_scripts/scripts/hr/17.0.1.1/post-migration.py b/openupgrade_scripts/scripts/hr/17.0.1.1/post-migration.py index d48c97700bf7..b71abe3322e3 100644 --- a/openupgrade_scripts/scripts/hr/17.0.1.1/post-migration.py +++ b/openupgrade_scripts/scripts/hr/17.0.1.1/post-migration.py @@ -14,7 +14,6 @@ "hr.openupgrade_legacy_17_0_onboarding_training", "hr.hr_plan_activity_type_company_rule", "hr.hr_plan_company_rule", - "hr.res_partner_admin_private_address", ] diff --git a/openupgrade_scripts/scripts/hr/17.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/hr/17.0.1.1/pre-migration.py index 124f4d1e58d1..57c85c291d84 100644 --- a/openupgrade_scripts/scripts/hr/17.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/hr/17.0.1.1/pre-migration.py @@ -34,6 +34,118 @@ ] +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) diff --git a/openupgrade_scripts/scripts/hr/17.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr/17.0.1.1/upgrade_analysis_work.txt index 052f58a83015..311f6b69c72c 100644 --- a/openupgrade_scripts/scripts/hr/17.0.1.1/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/hr/17.0.1.1/upgrade_analysis_work.txt @@ -1,22 +1,60 @@ ---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 + 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 -hr / hr.employee / address_home_id (many2one) : DEL relation: res.partner +# 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_car_plate (char) : NEW 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 @@ -26,26 +64,16 @@ hr / hr.employee / private_state_id (many2one) : NEW re 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 -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 +# NOTHING TO DO: + hr / hr.work.location / location_type (selection) : NEW required, selection_keys: ['home', 'office', 'other'], hasdefault: default -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 -hr / mail.channel / subscription_department_ids (many2many): DEL relation: hr.department -hr / res.company / employee_properties_definition (properties_definition): NEW +# 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)