Skip to content
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

[15.0][MIG] hr: Migration script #3481

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules140-150.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Module coverage 14.0 -> 15.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| google_spreadsheet | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr | | |
| hr | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| hr_attendance | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
4 changes: 2 additions & 2 deletions openupgrade_scripts/scripts/hr/15.0.1.1/noupdate_changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<field name="address_id" ref="base.main_company"/>
<field name="department_id" ref="dep_administration"/>
</record>
<record id="res_partner_admin_private_address" model="res.partner">
<!--<record id="res_partner_admin_private_address" model="res.partner">
<field name="image_1920" type="base64" file="base/static/img/avatar_grey.png"/>
</record>
</record>-->
</odoo>
62 changes: 62 additions & 0 deletions openupgrade_scripts/scripts/hr/15.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from openupgradelib import openupgrade


def _map_hr_employee_work_location_to_work_location_id(env):
openupgrade.logged_query(
env.cr,
"""
WITH work_location_tmp AS (
INSERT INTO hr_work_location AS hwl (name, company_id, address_id,
active, create_uid, write_uid, create_date, write_date)
SELECT emp.work_location, emp.company_id, emp.address_id, TRUE,
min(emp.create_uid), min(emp.write_uid), min(emp.create_date),
min(emp.write_date)
FROM hr_employee emp
WHERE emp.address_id IS NOT NULL AND emp.work_location IS NOT NULL
GROUP BY emp.work_location, emp.company_id, emp.address_id
RETURNING hwl.id, hwl.name, hwl.address_id, hwl.company_id
)
UPDATE hr_employee emp
SET work_location_id = wlt.id
FROM work_location_tmp as wlt
WHERE wlt.name = emp.work_location
AND wlt.address_id = emp.address_id
AND wlt.company_id = emp.company_id""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE hr_work_location hwl
SET active = FALSE
WHERE hwl.id NOT IN (
SELECT DISTINCT emp.work_location_id
FROM hr_employee emp
WHERE emp.work_location_id IS NOT NULL
AND emp.active)""",
)


def _map_hr_employee_departure_reason_to_departure_reason_id(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE hr_employee
SET departure_reason_id = CASE
WHEN departure_reason = 'fired' THEN %s
WHEN departure_reason = 'resigned' THEN %s
WHEN departure_reason = 'retired' THEN %s
END
WHERE departure_reason IN ('fired', 'resigned', 'retired')
""",
(
env.ref("hr.departure_fired").id,
env.ref("hr.departure_resigned").id,
env.ref("hr.departure_retired").id,
),
)


@openupgrade.migrate()
def migrate(env, version):
_map_hr_employee_work_location_to_work_location_id(env)
_map_hr_employee_departure_reason_to_departure_reason_id(env)
9 changes: 9 additions & 0 deletions openupgrade_scripts/scripts/hr/15.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.convert_field_to_html(
env.cr, "hr_employee", "departure_description", "departure_description"
)
openupgrade.convert_field_to_html(env.cr, "hr_job", "description", "description")
73 changes: 73 additions & 0 deletions openupgrade_scripts/scripts/hr/15.0.1.1/upgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---Models in module 'hr'---
new model hr.departure.reason
new model hr.work.location
---Fields in module 'hr'---
hr / hr.department / total_employee (integer) : previously in module hr_holidays
# NOTHING TO DO: has compute and not store

hr / hr.departure.reason / name (char) : NEW required
hr / hr.departure.reason / sequence (integer) : NEW hasdefault
# NOTHING TO DO: new records will be created by hr_data.xml

hr / hr.employee / departure_description (text) : type is now 'html' ('text')
# DONE post-migration: convert to html

hr / hr.employee / departure_reason (selection) : DEL selection_keys: ['fired', 'resigned', 'retired']
hr / hr.employee / departure_reason_id (many2one): NEW relation: hr.departure.reason
# DONE post-migration: map departure_reason with hr.deprture.reason on hr.employee model

hr / hr.employee / driving_license (binary) : NEW attachment: True
hr / hr.employee / employee_type (selection) : NEW required, selection_keys: ['contractor', 'employee', 'freelance', 'student', 'trainee'], req_default: function, hasdefault
hr / hr.employee / has_work_permit (binary) : NEW attachment: True
hr / hr.employee / id_card (binary) : NEW attachment: True
# NOTHING TO DO: new fields

hr / hr.employee / work_location (char) : DEL
hr / hr.employee / work_location_id (many2one) : NEW relation: hr.work.location, isfunction: function, stored
# DONE post-migration: create hr.work.location

hr / hr.employee / work_permit_expiration_date (date): NEW
hr / hr.employee / work_permit_scheduled_activity (boolean): NEW hasdefault
hr / hr.job / _order : _order is now 'sequence' ('id')
# NOTHING TO DO

hr / hr.job / description (text) : type is now 'html' ('text')
# DONE post-migration: convert to html

hr / hr.job / sequence (integer) : NEW hasdefault
# NOTHING TO DO

hr / hr.work.location / active (boolean) : NEW hasdefault
hr / hr.work.location / address_id (many2one) : NEW relation: res.partner, required
hr / hr.work.location / company_id (many2one) : NEW relation: res.company, required, req_default: function, hasdefault
hr / hr.work.location / location_number (char) : NEW
hr / hr.work.location / name (char) : NEW required
# DONE post-migration: create new records

hr / res.partner / employee_ids (one2many) : NEW relation: hr.employee
# NOTHING TO DO

---XML records in module 'hr'---
NEW hr.departure.reason: hr.departure_fired (noupdate)
NEW hr.departure.reason: hr.departure_resigned (noupdate)
NEW hr.departure.reason: hr.departure_retired (noupdate)
NEW ir.actions.act_window: hr.hr_departure_reason_action
NEW ir.actions.act_window: hr.hr_work_location_action
NEW ir.cron: hr.ir_cron_data_check_work_permit_validity (noupdate)
NEW ir.model.access: hr.access_hr_departure_reason
NEW ir.model.access: hr.access_hr_work_location_manager
NEW ir.model.access: hr.access_hr_work_location_user
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
NEW ir.ui.menu: hr.menu_hr_departure_reason_tree
NEW ir.ui.menu: hr.menu_hr_work_location_tree
NEW ir.ui.view: hr.hr_departure_reason_view_form
NEW ir.ui.view: hr.hr_departure_reason_view_list
NEW ir.ui.view: hr.hr_work_location_form_view
NEW ir.ui.view: hr.hr_work_location_tree_view
NEW ir.ui.view: hr.res_partner_view_form
DEL ir.ui.view: hr.assets_backend
DEL ir.ui.view: hr.qunit_suite
# NOTHING TO DO