Skip to content

[OU-FIX] hr: rename contract types and map the employee type selection - #9

Merged
cursor[bot] merged 1 commit into
20.0from
cursor/ou-20-03-hr-employee-type-3e8f
Nov 12, 2026
Merged

cursor[bot] merged 1 commit into
20.0from
cursor/ou-20-03-hr-employee-type-3e8f

Conversation

@adekock11

Copy link
Copy Markdown
Owner

Symptom

Loading hr 20.0 raises:

KeyError: 'hr.contract.type'

while parsing hr/data/hr_employee_type_data.xml:4. The xmlids hr.contract_type_* still point at hr.contract.type.

Root cause

Odoo 20 replaces hr.contract.type with hr.employee.type and reuses the same xmlids. hr.job.contract_type_id and hr.version.contract_type_id become employee_type_id. The required selection hr.version.employee_type (employee, worker, student, trainee, contractor, freelance) is removed. Without a pre-migration rename, the data file tries to load an hr.employee.type record through an xmlid that still names hr.contract.type.

Change

Written from hr/20.0.1.1/upgrade_analysis.txt, not only the rename. upgrade_analysis_work.txt marks each line DONE or NOTHING TO DO.

Pre-migration:

  • rename_models / rename_tables: hr.contract.type → hr.employee.type, hr_contract_type → hr_employee_type.
  • ir_model_data.model for those rows is updated before the data file loads, so the xmlids update the renamed records instead of raising a different-model error. ir.actions.act_window.res_model, ir.ui.view.model and view arches are rewritten the same way.
  • rename_fields: contract_type_id → employee_type_id on hr.job and hr.version.
  • employee_type, departure_reason_id, departure_description and departure_date are copied with openupgrade.copy_columns.
  • hr.version.tz is added and filled from hr.employee.tz (NULL becomes UTC) because the version field is now stored and required. NULL resource_calendar_id is filled from the company calendar, then any calendar. hr.job.company_id NULL is filled from the department, then the first company. Both are now required.
  • additional_note and contract_template_id are copied from the employee's current version onto hr.employee (they stop being related).
  • hr.job.user_id (res.users) is copied to the new recruiter_id (hr.employee), preferring an employee of the job's company.
  • sex = 'other' is cleared. The key is gone and the field is not required.

Post-migration:

  • Maps the legacy selection onto employee_type_id only when that column is NULL or still points at a standard type that 20.0 dropped (contract_type_full_time, part_time, permanent, statutory, temporary). A version that already points at a type 20.0 still ships (Apprenticeship, Interim, Intern, Student, …) or at a custom type keeps that type. The selection defaults to employee and must not wipe a more specific contract type.
  • Mapping, from hr/data/hr_employee_type_data.xml (there is no worker, contractor or freelance type):
    • employee → hr.contract_type_employee
    • worker → hr.contract_type_employee (20.0 dropped hr.structure_type_worker; worker was the payroll split, not a separate employee type)
    • student → hr.contract_type_student
    • trainee → hr.contract_type_intern
    • contractor and freelance → hr.contract_type_interim (Interim is the non-permanent engagement that is not student, intern, seasonal, apprenticeship or thesis)
  • The legacy column keeps the original selection.
  • Creates one hr.employee.departure per version that had a reason, date or description and an employee, and sets hr.version.departure_id. A missing reason uses the first hr.departure.reason because the new field is required. dismissal_date is the departure date (or today). action_date is the next day. Contract templates (employee_id NULL) are skipped.
  • Loads 20.0.1.1/noupdate_changes.xml (sequences on the renamed types, Belgium Pay structure name, disabled bank rules).

Merged modules (hr_homeworking, hr_org_chart, hr_hourly_cost) are already in apriori.merged_modules and are handled by the base migration. Removed columns are not dropped by OpenUpgrade, so ssnid, study_school and private_car_plate stay in the database with no successor field.

Verification

Field list checked against Odoo 19 hr.version / hr.employee / hr.job and Odoo 20 hr.employee.type, hr.version, hr.employee.departure and hr_employee_type_data.xml. The six selection keys are all mapped (asserted by reading the dict). ruff and py_compile are clean. No database upgrade was run.

No OCA pull request migrates hr 20.0. The analysis in OCA OCA#6068 lists the model change and does not ship scripts.

Upstream

Generic. Submit to OCA 20.0 on top of OCA#6068. Not applicable to 18.0 or 19.0.

Limitations

  • contractor and freelance both become Interim. The legacy column is the only remaining distinction.
  • worker becomes Employee. Belgian payroll structure types that 20.0 deletes from the data file are left in place (they are noupdate).
  • Dropped standard contract types (full_time, part_time, permanent, statutory, temporary) are kept as hr.employee.type rows when something still points at them, and replaced by the selection mapping when a version points at them and the selection says something more specific. Custom contract types are never overwritten.
  • Departure rows are inserted in SQL so hr.employee.departure's date constraints (contract start versus departure date) do not abort the upgrade. A departure that would have been invalid in the UI is still created.
  • birthday_month, first_contract_date and phone_sanitized are left for the ORM to compute. They read only hr.employee, which is loaded with this module.
Open in Web Open in Cursor 

@cursor
cursor Bot merged commit 6c50062 into 20.0 Nov 12, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants