Skip to content

[19.0][FIX] hr: cleanup obsolete hr.employee fields from merged hr_contract#5630

Closed
dnplkndll wants to merge 1 commit into
OCA:19.0from
ledoent:19.0-fix-hr-obsolete-fields-cleanup
Closed

[19.0][FIX] hr: cleanup obsolete hr.employee fields from merged hr_contract#5630
dnplkndll wants to merge 1 commit into
OCA:19.0from
ledoent:19.0-fix-hr-obsolete-fields-cleanup

Conversation

@dnplkndll
Copy link
Copy Markdown

What

Add cleanup_obsolete_hr_employee_fields(env) to
openupgrade_scripts/scripts/hr/19.0.1.1/pre-migration.py and update the
companion annotation in upgrade_analysis_work.txt.

The helper deletes the stale ir_model_fields rows + ir_model_data
backrefs + orphan ir_ui_view records on hr.employee /
hr.employee.public for fields the 18.0 hr_contract module added
that no longer exist anywhere in 19.0:

  • listed by the analyzer as DEL: contract_id, contract_ids,
    contract_warning, first_contract_date, vehicle
  • not listed by the analyzer but verified stale via grep against all 19.0
    hr* modules: contract_template_id, contract_type_id,
    contract_wage, contracts_count, is_in_contract

Why

The relevant block in upgrade_analysis_work.txt (lines 255-259 of the
file before this PR) was annotated # NOTHING TO DO on the assumption
that Odoo's standard registry rebuild would prune fields that disappear
from the source. That holds for normal module upgrades, but not when the
donor module is merged into another via apriori — the field rows are
re-parented to the receiving module (hr) by update_module_names
and survive.

The stale rows themselves are inert, but the matching ir_ui_view
records on hr.employee retain <field name=\"contract_id\"/> etc.
in their arch_db. When any later module's data XML load triggers
cross-cutting view validation, those view-field lookups raise
Field 'first_contract_date' does not exist in model 'hr.employee' and
abort the migration. Reproduced on a fresh 18.0 → 19.0 install
(odoo -i all on the CE addons path, then -u all) — the migration
crashes at module 217/608 (l10n_ae) on parsing
addons/l10n_ae/data/account_tax_report_data.xml:3.

How

Pre-migration runs two SQL passes:

  1. Delete orphan ir_ui_view records on hr.employee /
    hr.employee.public whose arch_db matches a regex over the
    standard <field name=\"X\"/> pattern for any of the ten obsolete
    names. The 19.0 hr XML re-creates proper views during the same data
    load via mode=update.
  2. Delete the field metadata via openupgrade.delete_records_safely_by_xml_id
    for both hr.field_hr_employee__* and hr.field_hr_employee_public__*.

The annotation in upgrade_analysis_work.txt is updated from
# NOTHING TO DO to a # DONE comment that explains why the
"nothing to do" assumption was wrong and that five extra fields are
also covered.

Test plan

  • Repro confirmed against a fresh 18.0 CE-all install (odoo -i all
    with --addons-path scoped to the CE image's built-in addons,
    then -u all). Without this patch, migration crashes at module
    217/608 on the error above.
  • With this patch: the hr module's pre-migration + post-migration
    complete cleanly (Module hr loaded in 5.00s, 5822 queries), the
    migration progresses past the previous crash point. A different
    stale-field finding then surfaces on res.partner (filed
    separately).
  • OCA CI green.

Companion PRs

The loyalty fix is a prerequisite to reach the crash this PR addresses
during a clean migration. The hr null-write-date fix is independent.

@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts series:19.0 labels May 15, 2026
@dnplkndll dnplkndll force-pushed the 19.0-fix-hr-obsolete-fields-cleanup branch from 52943ad to 870d07a Compare May 15, 2026 00:49
@dnplkndll dnplkndll changed the title [FIX] hr: cleanup obsolete hr.employee fields from merged hr_contract [19.0][FIX] hr: cleanup obsolete hr.employee fields from merged hr_contract May 15, 2026
dnplkndll added a commit to ledoent/OpenUpgrade that referenced this pull request May 15, 2026
Add the merges introduced by today's PR series so the auto-built image
includes them and the lab can `OPENUPGRADE_PULL_POLICY=always` again:

 - 19.0-fix-hr-null-write-date                 (OCA#5628)
 - 19.0-fix-loyalty-stale-mail-template-fields (OCA#5629)
 - 19.0-fix-hr-obsolete-fields-cleanup         (OCA#5630)
 - 19.0-fix-partner-autocomplete-cleanup       (OCA#5631)
 - 19.0-fix-l10n-fr-cleanup                    (OCA#5632)

The companion lab repos.yaml is updated separately so local
`make sync-repos` matches.
… views

After the hr_contract → hr apriori merge, two classes of stale records
linger and trip cross-cutting view validation later in the migration:

1. ir_model_fields rows + orphan ir_ui_view records for fields the 18.0
   hr_contract module added to hr.employee that no longer exist in 19.0:
   contract_id, contract_ids, contract_warning, first_contract_date,
   vehicle (listed DEL in upgrade_analysis_work.txt as "# NOTHING TO DO"),
   plus contract_template_id, contract_type_id, contract_wage,
   contracts_count, is_in_contract (not flagged by the analyzer but
   verified stale via grep against all 19.0 hr* modules).

2. ir_ui_view records whose xml_ids were auto-renamed by openupgradelib
   (`<orig_name>_openupgrade_<id>`) during the merge to avoid xml_id
   collision. Two such views exist after the merge:
   res_config_settings_view_form_openupgrade_65293 and
   hr_departure_wizard_view_form_openupgrade_65294. Their arch_db still
   references 18.0-only xpath targets (e.g. //block[@name='employee_rights_setting_container'])
   and parents that 19.0 doesn't ship.

Both classes manifest as a migration crash when l10n_ae's
account_tax_report_data.xml triggers global view validation around
module 217/608 — without this patch the migration fails with either
"Field 'first_contract_date' does not exist in model 'hr.employee'"
or "Element '<xpath expr=...>' cannot be located in parent view".

Add two helpers in pre-migration:
 - cleanup_obsolete_hr_employee_fields(env)
 - cleanup_openupgrade_renamed_hr_views(env)

Update upgrade_analysis_work.txt: the "# NOTHING TO DO" block for the
DEL fields becomes "# DONE: stale ir_model_fields rows + orphan
ir_ui_view records cleaned up in pre-migration".
@dnplkndll dnplkndll force-pushed the 19.0-fix-hr-obsolete-fields-cleanup branch from 870d07a to 50fae9e Compare May 15, 2026 01:13
dnplkndll added a commit to ledoent/OpenUpgrade that referenced this pull request May 15, 2026
Copy link
Copy Markdown
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

@pedrobaeza pedrobaeza closed this May 15, 2026
dnplkndll added a commit to ledoent/OpenUpgrade that referenced this pull request May 16, 2026
Add the merges introduced by today's PR series so the auto-built image
includes them and the lab can `OPENUPGRADE_PULL_POLICY=always` again:

 - 19.0-fix-hr-null-write-date                 (OCA#5628)
 - 19.0-fix-loyalty-stale-mail-template-fields (OCA#5629)
 - 19.0-fix-hr-obsolete-fields-cleanup         (OCA#5630)
 - 19.0-fix-partner-autocomplete-cleanup       (OCA#5631)
 - 19.0-fix-l10n-fr-cleanup                    (OCA#5632)

The companion lab repos.yaml is updated separately so local
`make sync-repos` matches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:openupgrade_scripts Module openupgrade_scripts series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants