Odoo Upgrade Utils Skill
Use the odoo.upgrade.util module for safe data migrations. These helpers handle complex database operations and ensure
consistent updates across the Odoo registry.
Summary of Helpers
util.rename_field(cr, model, old_name, new_name):- Renames the column in the database and updates
ir.model.fields,ir.model.data, andir.ui.viewreferences.
- Renames the column in the database and updates
util.remove_field(cr, model, field_name):- Safely deletes a field and its data.
util.move_field_to_module(cr, model, fieldname, old_module, new_module):- Moves a field's metadata from one module to another.
util.rename_model(cr, old_name, new_name):- Renames the model and updates all its associated XMLIDs and metadata.
util.rename_xmlid(cr, old_xmlid, new_xmlid):- Renames an external ID.
old_xmlidandnew_xmlidshould be fully qualified (e.g.,base.group_user).
- Renames an external ID.
util.edit_view(cr, xmlid):- Context manager for editing a view's architecture using
lxml.etree. - Usage:
with util.edit_view(cr, 'module.view_id') as arch: ...
- Context manager for editing a view's architecture using
util.merge_module(cr, old_name, into_name):- Merges one module's metadata into another.
util.module_installed(cr, module):- Returns
Trueif the specified module is installed or being upgraded.
- Returns
util.env(cr):- Returns an
odoo.api.Environmentinstance for the current cursor.
- Returns an
util.table_of_model(cr, model):- Returns the database table name associated with an Odoo model.
Best Practices
- Pre-migration: Use for field and model renames so the new Odoo version can find the data during its own installation.
- Post-migration: Use for complex data transformations that require the new Odoo registry to be partially loaded.
- Module discovery: Migration scripts should be placed in
<module>/migrations/<target_ver>/.
For more details, consult the Odoo Upgrade Utils Documentation.