Skip to content

Commit d551763

Browse files
authored
Merge pull request #4794 from Tecnativa/17.0-ou_add-hr
[17.0][OU-ADD] hr: Migration scripts
2 parents 1479853 + 1235345 commit d551763

File tree

5 files changed

+333
-3
lines changed

5 files changed

+333
-3
lines changed

docsource/modules160-170.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Module coverage 16.0 -> 17.0
156156
+---------------------------------------------------+----------------------+-------------------------------------------------+
157157
| google_recaptcha | Nothing to do | |
158158
+---------------------------------------------------+----------------------+-------------------------------------------------+
159-
| hr | | |
159+
| hr | Done | |
160160
+---------------------------------------------------+----------------------+-------------------------------------------------+
161161
| hr_attendance | | |
162162
+---------------------------------------------------+----------------------+-------------------------------------------------+

openupgrade_scripts/scripts/hr/17.0.1.1/noupdate_changes.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<field name="responsible_type">manager</field>
2727
<field name="sequence">20</field>
2828
</record>
29-
<record id="onboarding_plan" model="mail.activity.plan">
29+
<!-- <record id="onboarding_plan" model="mail.activity.plan">
3030
<field name="res_model">hr.employee</field>
3131
</record>
3232
<record id="onboarding_plan_training" model="mail.activity.plan.template">
@@ -40,5 +40,5 @@
4040
<record id="onboarding_training" model="mail.activity.plan.template">
4141
<field name="responsible_type">employee</field>
4242
<field name="sequence">30</field>
43-
</record>
43+
</record> -->
4444
</odoo>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
2+
# Copyright 2025 Tecnativa - Pedro M. Baeza
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from openupgradelib import openupgrade
6+
7+
_deleted_xml_records = [
8+
"hr.dep_sales",
9+
"hr.hr_plan_activity_type_company_rule",
10+
"hr.hr_plan_company_rule",
11+
"hr.res_partner_admin_private_address",
12+
]
13+
14+
15+
def _transfer_employee_private_data(env):
16+
"""On v17, there's no more private res.partner records, so we should transfer the
17+
information to the dedicated employee fields, and then anonymize the remaining data
18+
in the res.partner record.
19+
"""
20+
openupgrade.logged_query(
21+
env.cr,
22+
"""
23+
UPDATE hr_employee he
24+
SET lang = rp.lang,
25+
private_city = rp.city,
26+
private_country_id = rp.country_id,
27+
private_email = rp.email,
28+
private_phone = rp.phone,
29+
private_state_id = rp.state_id,
30+
private_street = rp.street,
31+
private_street2 = rp.street2,
32+
private_zip = rp.zip
33+
FROM res_partner rp
34+
WHERE he.address_home_id = rp.id""",
35+
)
36+
openupgrade.logged_query(
37+
env.cr,
38+
"""
39+
UPDATE res_partner rp
40+
SET city = '***',
41+
country_id = NULL,
42+
email = '***',
43+
phone = '***',
44+
state_id = NULL,
45+
street = '***',
46+
street2 = '***',
47+
zip = '***'
48+
FROM hr_employee he
49+
WHERE he.address_home_id = rp.id""",
50+
)
51+
52+
53+
@openupgrade.migrate()
54+
def migrate(env, version):
55+
_transfer_employee_private_data(env)
56+
openupgrade.load_data(env, "hr", "17.0.1.1/noupdate_changes.xml")
57+
openupgrade.delete_records_safely_by_xml_id(env, _deleted_xml_records)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
2+
# Copyright 2025 Tecnativa - Pedro M. Baeza
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
from openupgradelib import openupgrade
5+
6+
7+
def _rename_subscription_department_ids_m2m(env):
8+
openupgrade.logged_query(
9+
env.cr,
10+
"""ALTER TABLE hr_department_mail_channel_rel
11+
RENAME TO discuss_channel_hr_department_rel""",
12+
)
13+
openupgrade.logged_query(
14+
env.cr,
15+
"""ALTER TABLE discuss_channel_hr_department_rel
16+
RENAME mail_channel_id TO discuss_channel_id""",
17+
)
18+
19+
20+
def _fill_hr_contract_type_code(env):
21+
openupgrade.logged_query(
22+
env.cr, "ALTER TABLE hr_contract_type ADD COLUMN IF NOT EXISTS code VARCHAR"
23+
)
24+
openupgrade.logged_query(
25+
env.cr, "UPDATE hr_contract_type SET code = name WHERE code IS NULL"
26+
)
27+
28+
29+
def _hr_plan_sync_to_mail_activity_plan(env):
30+
employee_model = env["ir.model"].search([("model", "=", "hr.employee")])
31+
# sync hr.plan to mail.activity.plan
32+
openupgrade.logged_query(
33+
env.cr,
34+
"""
35+
ALTER TABLE mail_activity_plan ADD COLUMN IF NOT EXISTS department_id INTEGER,
36+
ADD COLUMN IF NOT EXISTS hr_plan_legacy_id INTEGER""",
37+
)
38+
hr_plan_query = f"""
39+
INSERT INTO mail_activity_plan (
40+
company_id, res_model_id, create_uid, write_uid, name, res_model,
41+
active, create_date, write_date, department_id, hr_plan_legacy_id
42+
)
43+
SELECT
44+
company_id, {employee_model.id}, create_uid, write_uid, name, 'hr.employee',
45+
active, create_date, write_date, department_id, id
46+
FROM hr_plan
47+
"""
48+
openupgrade.logged_query(env.cr, hr_plan_query)
49+
# sync hr.plan.activitype.type to mail.activity.plan.template
50+
openupgrade.logged_query(
51+
env.cr,
52+
"""
53+
ALTER TABLE mail_activity_plan_template
54+
ADD COLUMN hr_plan_activity_type_legacy_id INTEGER""",
55+
)
56+
hr_plan_activity_type_query = """
57+
INSERT INTO mail_activity_plan_template (
58+
activity_type_id, responsible_id, plan_id, responsible_type,
59+
summary, note, create_uid, write_uid, create_date,
60+
write_date, hr_plan_activity_type_legacy_id
61+
)
62+
SELECT
63+
hpat.activity_type_id, hpat.responsible_id, map.id, hpat.responsible,
64+
hpat.summary, hpat.note, hpat.create_uid, hpat.write_uid, hpat.create_date,
65+
hpat.write_date, hpat.id
66+
FROM hr_plan_activity_type hpat
67+
JOIN mail_activity_plan map ON hpat.plan_id = map.hr_plan_legacy_id
68+
"""
69+
openupgrade.logged_query(env.cr, hr_plan_activity_type_query)
70+
# Reassign standard data XML-IDs for pointing to the new records
71+
openupgrade.logged_query(
72+
env.cr,
73+
"""
74+
UPDATE ir_model_data imd
75+
SET model = 'mail.activity.plan', res_id = map.id
76+
FROM ir_model_data imd2
77+
JOIN mail_activity_plan map ON
78+
map.hr_plan_legacy_id = imd2.res_id
79+
AND imd2.name IN ('onboarding_plan', 'offboarding_plan')
80+
AND imd2.module = 'hr'
81+
WHERE imd.id = imd2.id""",
82+
)
83+
openupgrade.logged_query(
84+
env.cr,
85+
"""
86+
UPDATE ir_model_data imd
87+
SET model = 'mail.activity.plan.template', res_id = mapt.id
88+
FROM ir_model_data imd2
89+
JOIN mail_activity_plan_template mapt ON
90+
mapt.hr_plan_activity_type_legacy_id = imd2.res_id
91+
AND imd2.name IN (
92+
'onboarding_setup_it_materials',
93+
'onboarding_plan_training',
94+
'onboarding_training',
95+
'offboarding_setup_compute_out_delais',
96+
'offboarding_take_back_hr_materials'
97+
)
98+
AND imd2.module = 'hr'
99+
WHERE imd.id = imd2.id""",
100+
)
101+
102+
103+
def _hr_work_location_fill_location_type(env):
104+
openupgrade.logged_query(
105+
env.cr,
106+
"""
107+
ALTER TABLE hr_work_location ADD COLUMN IF NOT EXISTS location_type VARCHAR;
108+
UPDATE hr_work_location
109+
SET location_type = 'office'
110+
""",
111+
)
112+
113+
114+
@openupgrade.migrate()
115+
def migrate(env, version):
116+
_rename_subscription_department_ids_m2m(env)
117+
_fill_hr_contract_type_code(env)
118+
_hr_plan_sync_to_mail_activity_plan(env)
119+
_hr_work_location_fill_location_type(env)
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---Models in module 'hr'---
2+
obsolete model hr.plan
3+
obsolete model hr.plan.activity.type
4+
# DONE pre-migration: move data into mail.activity.plan
5+
6+
obsolete model hr.plan.wizard [transient]
7+
# NOTHING TO DO
8+
9+
---Fields in module 'hr'---
10+
hr / mail.channel / subscription_department_ids (many2many): column1 is now 'discuss_channel_id' ('mail_channel_id') [hr_department_mail_channel_rel]
11+
hr / mail.channel / subscription_department_ids (many2many): table is now 'discuss_channel_hr_department_rel' ('hr_department_mail_channel_rel')
12+
# DONE: pre-migration: Rename table and column
13+
14+
hr / hr.contract.type / code (char) : NEW hasdefault: compute
15+
# DONE: pre-migration: Column created and filled with the name. It wouldn't be too much burden to let the ORM compute, being few records, but let's do it by SQL anyway.
16+
17+
hr / hr.contract.type / country_id (many2one) : NEW relation: res.country
18+
# NOTHING TO DO: new feature
19+
20+
hr / hr.department / message_main_attachment_id (many2one): DEL relation: ir.attachment
21+
# NOTHING TO DO
22+
23+
hr / hr.department / plan_ids (one2many) : relation is now 'mail.activity.plan' ('hr.plan') [nothing to do]
24+
hr / hr.plan / active (boolean) : DEL
25+
hr / hr.plan / company_id (many2one) : DEL relation: res.company
26+
hr / hr.plan / department_id (many2one) : DEL relation: hr.department
27+
hr / hr.plan / name (char) : DEL required
28+
hr / hr.plan / plan_activity_type_ids (one2many): DEL relation: hr.plan.activity.type
29+
hr / hr.plan.activity.type / activity_type_id (many2one) : DEL relation: mail.activity.type
30+
hr / hr.plan.activity.type / company_id (many2one) : DEL relation: res.company
31+
hr / hr.plan.activity.type / note (html) : DEL
32+
hr / hr.plan.activity.type / plan_id (many2one) : DEL relation: hr.plan
33+
hr / hr.plan.activity.type / responsible (selection) : DEL required, selection_keys: ['coach', 'employee', 'manager', 'other']
34+
hr / hr.plan.activity.type / responsible_id (many2one) : DEL relation: res.users
35+
hr / hr.plan.activity.type / summary (char) : DEL
36+
hr / mail.activity.plan / department_id (many2one) : NEW relation: hr.department, hasdefault: compute
37+
hr / mail.activity.plan.template / responsible_type (False) : NEW selection_keys: ['coach', 'employee', 'manager', 'on_demand', 'other'], mode: modify
38+
# DONE: pre-migration: move data into mail.activity.plan
39+
40+
hr / hr.department / rating_ids (one2many) : NEW relation: rating.rating
41+
# NOTHING TO DO
42+
43+
hr / hr.departure.reason / reason_code (integer) : NEW
44+
# DONE post-migration: load noupdate
45+
46+
hr / hr.employee / activity_user_id (many2one) : not related anymore
47+
hr / hr.employee / activity_user_id (many2one) : now a function
48+
# NOTHING TO DO: no store field
49+
50+
hr / hr.employee / employee_properties (properties): NEW hasdefault: compute
51+
hr / res.company / employee_properties_definition (properties_definition): NEW
52+
# NOTHING TO DO: new feature for assigning properties
53+
54+
hr / hr.employee / private_car_plate (char) : NEW
55+
# NOTHING TO DO: new feature
56+
57+
hr / hr.employee / address_home_id (many2one) : DEL relation: res.partner
58+
hr / hr.employee / lang (selection) : is now stored
59+
hr / hr.employee / lang (selection) : not related anymore
60+
hr / hr.employee / private_city (char) : NEW
61+
hr / hr.employee / private_country_id (many2one) : NEW relation: res.country
62+
hr / hr.employee / private_email (char) : is now stored
63+
hr / hr.employee / private_email (char) : not related anymore
64+
hr / hr.employee / private_phone (char) : NEW
65+
hr / hr.employee / private_state_id (many2one) : NEW relation: res.country.state
66+
hr / hr.employee / private_street (char) : NEW
67+
hr / hr.employee / private_street2 (char) : NEW
68+
hr / hr.employee / private_zip (char) : NEW
69+
# DONE: post-migration: fill values from address_home_id to the employee fields, and anonymize the information on the res.partner record
70+
71+
hr / hr.employee / rating_ids (one2many) : NEW relation: rating.rating
72+
hr / hr.job / message_main_attachment_id (many2one): DEL relation: ir.attachment
73+
hr / hr.job / rating_ids (one2many) : NEW relation: rating.rating
74+
# NOTHING TO DO: New rating inheritance
75+
76+
hr / hr.work.location / location_type (selection) : NEW required, selection_keys: ['home', 'office', 'other'], hasdefault: default
77+
# DONE: pre-migration: Pre-created and filled with the value 'office', which is fine according previous version behavior.
78+
79+
---XML records in module 'hr'---
80+
NEW hr.contract.type: hr.contract_type_full_time (noupdate)
81+
NEW hr.contract.type: hr.contract_type_part_time (noupdate)
82+
NEW hr.contract.type: hr.contract_type_permanent (noupdate)
83+
NEW hr.contract.type: hr.contract_type_seasonal (noupdate)
84+
NEW hr.contract.type: hr.contract_type_temporary (noupdate)
85+
# NOTHING TO DO
86+
87+
DEL hr.department: hr.dep_sales (noupdate)
88+
DEL ir.rule: hr.hr_plan_activity_type_company_rule (noupdate)
89+
DEL ir.rule: hr.hr_plan_company_rule (noupdate)
90+
DEL res.partner: hr.res_partner_admin_private_address (noupdate)
91+
# DONE: post-migration: removed safely
92+
93+
DEL hr.plan: hr.offboarding_plan (noupdate)
94+
DEL hr.plan: hr.onboarding_plan (noupdate)
95+
DEL hr.plan.activity.type: hr.offboarding_setup_compute_out_delais (noupdate)
96+
DEL hr.plan.activity.type: hr.offboarding_take_back_hr_materials (noupdate)
97+
DEL hr.plan.activity.type: hr.onboarding_plan_training (noupdate)
98+
DEL hr.plan.activity.type: hr.onboarding_setup_it_materials (noupdate)
99+
DEL hr.plan.activity.type: hr.onboarding_training (noupdate)
100+
NEW mail.activity.plan: hr.offboarding_plan (noupdate)
101+
NEW mail.activity.plan: hr.onboarding_plan (noupdate)
102+
NEW mail.activity.plan.template: hr.offboarding_setup_compute_out_delais (noupdate)
103+
NEW mail.activity.plan.template: hr.offboarding_take_back_hr_materials (noupdate)
104+
NEW mail.activity.plan.template: hr.onboarding_plan_training (noupdate)
105+
NEW mail.activity.plan.template: hr.onboarding_setup_it_materials (noupdate)
106+
NEW mail.activity.plan.template: hr.onboarding_training (noupdate)
107+
# DONE: pre-migration: Reassign XML-IDs to the new mail.activity.plan* records
108+
109+
NEW hr.work.location: hr.home_work_location (noupdate)
110+
NEW hr.work.location: hr.home_work_office (noupdate)
111+
NEW hr.work.location: hr.home_work_other (noupdate)
112+
NEW ir.actions.act_window: hr.mail_activity_plan_action
113+
DEL ir.actions.act_window: hr.hr_employee_action_from_user
114+
DEL ir.actions.act_window: hr.hr_plan_action
115+
DEL ir.actions.act_window: hr.hr_plan_activity_type_action
116+
NEW ir.actions.act_window.view: hr.mail_activity_plan_action_employee_view_form
117+
NEW ir.actions.act_window.view: hr.mail_activity_plan_action_employee_view_tree
118+
NEW ir.model.access: hr.access_mail_activity_plan_hr_manager
119+
NEW ir.model.access: hr.access_mail_activity_plan_template_hr_manager
120+
DEL ir.model.access: hr.access_hr_plan_activity_type_employee
121+
DEL ir.model.access: hr.access_hr_plan_activity_type_hr_user
122+
DEL ir.model.access: hr.access_hr_plan_employee
123+
DEL ir.model.access: hr.access_hr_plan_hr_user
124+
DEL ir.model.access: hr.access_hr_plan_wizard
125+
DEL ir.model.constraint: hr.constraint_hr_employee_barcode_uniq
126+
DEL ir.model.constraint: hr.constraint_hr_employee_category_name_uniq
127+
DEL ir.model.constraint: hr.constraint_hr_employee_user_uniq
128+
DEL ir.model.constraint: hr.constraint_hr_job_name_company_uniq
129+
DEL ir.model.constraint: hr.constraint_hr_job_no_of_recruitment_positive
130+
NEW ir.rule: hr.ir_rule_hr_contract_type_multi_company (noupdate)
131+
NEW ir.rule: hr.mail_plan_rule_group_hr_manager (noupdate)
132+
NEW ir.rule: hr.mail_plan_templates_rule_group_hr_manager (noupdate)
133+
# NOTHING TO DO
134+
135+
NEW ir.ui.menu: hr.menu_resource_calendar_view
136+
NEW ir.ui.view: hr.discuss_channel_view_form
137+
NEW ir.ui.view: hr.hr_employee_plan_activity_summary
138+
NEW ir.ui.view: hr.hr_employee_view_graph
139+
NEW ir.ui.view: hr.hr_employee_view_pivot
140+
NEW ir.ui.view: hr.mail_activity_plan_template_view_form
141+
NEW ir.ui.view: hr.mail_activity_plan_view_form
142+
NEW ir.ui.view: hr.mail_activity_plan_view_form_hr_employee
143+
NEW ir.ui.view: hr.mail_activity_plan_view_tree
144+
NEW ir.ui.view: hr.mail_activity_schedule_view_form
145+
DEL ir.ui.view: hr.hr_plan_activity_type_view_form
146+
DEL ir.ui.view: hr.hr_plan_activity_type_view_tree
147+
DEL ir.ui.view: hr.hr_plan_view_form
148+
DEL ir.ui.view: hr.hr_plan_view_search
149+
DEL ir.ui.view: hr.hr_plan_view_tree
150+
DEL ir.ui.view: hr.mail_channel_view_form_
151+
DEL ir.ui.view: hr.plan_wizard
152+
DEL ir.ui.view: hr.view_employee_form_smartbutton
153+
DEL ir.ui.view: hr.view_partner_tree2
154+
# NOTHING TO DO

0 commit comments

Comments
 (0)