Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
149 changes: 149 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,149 @@
# Copyright 2026 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

from odoo.tools.mail import html2plaintext, is_html_empty

_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
(
employee_id, date_version,
last_modified_uid, last_modified_date, hr_responsible_id,
{", ".join(fields)}
)
SELECT
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"
)


def hr_employee_notes(env):
"""
Append hr.employee#note and hr.contract#note to hr.version#additional_note
"""
env.cr.execute(
"""
UPDATE
hr_version
SET
additional_note=
COALESCE(hr_version.additional_note || '\n', '') ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this coalesce doesn't make sense, because it will always add the '\n'?

hr_employee.notes
FROM
hr_employee
WHERE
hr_version.employee_id=hr_employee.id
AND
hr_employee.notes IS NOT NULL
"""
)
if openupgrade.column_exists(env.cr, "hr_version", "notes"):
# this is hr.contract#note, which is html
env.cr.execute(
"SELECT id, additional_note, notes FROM hr_version WHERE notes IS NOT NULL"
)
for _id, additional_note, notes in env.cr.fetchall():
if is_html_empty(notes):
continue
notes = html2plaintext(notes)
additional_note = (additional_note + "\n") if additional_note else ""
env.cr.execute(
"UPDATE hr_version SET additional_note=%s WHERE id=%s",
(
additional_note + notes,
_id,
),
)


@openupgrade.migrate()
def migrate(env, version):
fill_hr_version(env)
hr_employee_notes(env)
hr_employee_bank_account_ids(env)
openupgrade.load_data(env, "hr", "19.0.1.1/noupdate_changes.xml")
openupgrade.delete_records_safely_by_xml_id(env, _deleted_xmlids)
81 changes: 81 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,81 @@
# 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",
"hr_contract.group_hr_contract_employee_manager",
"hr_contract.group_hr_contract_manager",
]


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