SKILL.md
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.renamefield(cr, model, oldname, new_name):
- Renames the column in the database and updates ir.model.fields, ir.model.data, and ir.ui.view references.
util.removefield(cr, model, fieldname):
- Safely deletes a field and its data.
util.movefieldtomodule(cr, model, fieldname, oldmodule, new_module):
- Moves a field's metadata from one module to another.
util.renamemodel(cr, oldname, new_name):
- Renames the model and updates all its associated XMLIDs and metadata.
util.renamexmlid(cr, oldxmlid, new_xmlid):
- Renames an external ID. oldxmlid and newxmlid should be fully qualified (e.g., base.group_user).
util.edit_view(cr, xmlid):
- Context manager for editing a view's architecture using lxml.etree. - Usage: with util.editview(cr, 'module.viewid') as arch: ...
util.mergemodule(cr, oldname, into_name):
- Merges one module's metadata into another.
util.module_installed(cr, module):
- Returns True if the specified module is installed or being upgraded.
util.env(cr):
- Returns an odoo.api.Environment instance for the current cursor.
util.tableofmodel(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.