Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions docsource/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| google_recaptcha | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| hr | | |
| hr |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| hr_attendance | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down Expand Up @@ -818,7 +818,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| payment_xendit | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| phone_validation | | |
| phone_validation |Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| point_of_sale | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down Expand Up @@ -980,7 +980,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| resource |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| resource_mail | | |
| resource_mail |Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |new| rpc | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
107 changes: 107 additions & 0 deletions openupgrade_scripts/scripts/hr/19.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright 2026 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

_deleted_xmlids = []


def fill_hr_version(env):
"""
Create a hr.version per hr.employee if not already created by a contract.
If hr_contract was installed, amend data resulting from renaming hr.contract to
hr.version
"""
fields = (
"active",
"additional_note",
"address_id",
"children",
"country_id",
"company_id",
"department_id",
"departure_date",
"departure_description",
"departure_reason_id",
"distance_home_work",
"distance_home_work_unit",
"employee_type",
"sex",
"identification_id",
"is_flexible",
"is_fully_flexible",
"job_id",
"job_title",
"km_home_work",
"marital",
"name",
"passport_id",
"private_city",
"private_country_id",
"private_state_id",
"private_street",
"private_street2",
"private_zip",
"spouse_birthdate",
"spouse_complete_name",
"ssnid",
"work_location_id",
)
link_column = openupgrade.get_legacy_name("contract_id")
env.cr.execute(
f"ALTER TABLE hr_version ADD COLUMN IF NOT EXISTS {link_column} int",
)
env.cr.execute(f"UPDATE hr_version SET {link_column}=id")
env.cr.execute(
f"""
UPDATE hr_version
SET
{", ".join(f"{field}=hr_employee.{field}" for field in fields)}
FROM hr_employee
WHERE
hr_version.employee_id=hr_employee.id
"""
)
env.cr.execute(
f"""
INSERT INTO hr_version
(
{link_column}, employee_id, date_version,
last_modified_uid, last_modified_date, hr_responsible_id,
{", ".join(fields)}
)
SELECT
id, id, create_date,
write_uid, write_date, {env.ref("base.user_admin").id},
{", ".join(fields)}
FROM hr_employee
WHERE id NOT IN (
SELECT employee_id FROM hr_version
)
"""
)
env.cr.execute(
f"""
UPDATE hr_version
SET hr_responsible_id={env.ref("base.user_admin").id}
WHERE hr_responsible_id IS NULL
"""
)
env["hr.employee"]._cron_update_current_version_id()


def hr_employee_bank_account_ids(env):
"""
Fill hr.employee#bank_account_ids
"""
openupgrade.m2o_to_x2m(
env.cr, env["hr.employee"], "hr_employee", "bank_account_ids", "bank_account_id"
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "hr", "19.0.1.1/noupdate_changes.xml")
fill_hr_version(env)
hr_employee_bank_account_ids(env)
openupgrade.delete_records_safely_by_xml_id(env, _deleted_xmlids)
79 changes: 79 additions & 0 deletions openupgrade_scripts/scripts/hr/19.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2026 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

renamed_fields = [
("hr.employee", "hr_employee", "gender", "sex"),
]

renamed_fields_hr_contract = [
("hr.contract", "hr_contract", "date_start", "contract_date_start"),
("hr.contract", "hr_contract", "date_end", "contract_date_end"),
]

renamed_field_references = [
("hr.employee", "bank_account_id", "bank_account_ids"),
]

added_fields = [
(
"country_id",
"hr.departure.reason",
"hr_departure_reason",
"many2one",
None,
"hr",
),
("employee", "res.partner", "res_partner", "boolean", None, "hr", False),
]

renamed_tables_hr_contract = [
("hr_contract", "hr_version"),
]

renamed_models = [
("hr.contract", "hr.version"),
]

renamed_xmlids = [
("hr.contract_type_statutaire", "hr.contract_type_statutory"),
]

deleted_xmlids = [
"hr.ir_cron_data_check_work_permit_validity",
"hr.ir_cron_data_contract_update_state",
"hr.ir_rule_hr_contract_employee_manager",
"hr.ir_rule_hr_contract_history_multi_company",
]


def res_partner_employee(env):
"""
Compute res.partner#employee
"""
env.cr.execute(
"""
UPDATE res_partner
SET
employee=True
FROM
hr_employee
WHERE
hr_employee.work_contact_id=res_partner.id
"""
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, renamed_fields)
openupgrade.rename_field_references(env, renamed_field_references)
openupgrade.add_fields(env, added_fields)
openupgrade.rename_xmlids(env.cr, renamed_xmlids)
openupgrade.delete_records_safely_by_xml_id(env, deleted_xmlids)
if openupgrade.table_exists(env.cr, "hr_contract"):
openupgrade.rename_fields(env, renamed_fields_hr_contract)
openupgrade.rename_tables(env.cr, renamed_tables_hr_contract)
openupgrade.rename_models(env.cr, renamed_models)
res_partner_employee(env)
Loading
Loading