SuperAPI AI 工具集

custom_util

部署与运维

查看项目

更新于 10-16 07:24

技能介绍

custom_util 是用于 PS 特定 Odoo 数据迁移的辅助模块,扩展标准 upgrade-util 库,处理常见 PS 模式,并让 Studio 字段等技术债得到清晰的版本管理。

主要能力:custom_util.custom_rename_model(cr, old_name, new_name) 重命名模型并将其状态设为 'base';custom_util.custom_rename_field(cr, model, old_name, new_name) 重命名字段并设为 'base',适用于所有 x_ 或 x_studio_ 字段;custom_util.transfer_custom_fields(cr, src_module, dest_module, fields_to_transfer) 在模块间移动字段,fields_to_transfer 为 (model, field) 或 (model, old_field, new_field) 元组列表;custom_util.custom_rename_module(cr, old_name, new_name) 安全重命名自定义模块,处理新模块记录已存在的情况;custom_util.update_custom_views(cr, list_fields) 批量更新所有视图中的多个字段;custom_util.views.edit.edit_views(cr, { xmlid: (Operations) }) 进行细粒度视图修改,支持 ReplaceValue(search, replace)、UpdateAttributes(xpath, **attrs)、RemoveFields(names)、RenameElements(old, new) 等操作;custom_util.update_related_field(cr, list_fields) 更新指向已重命名自定义字段的 related 定义;custom_util.merge_groups(cr, src_xmlid, dest_xmlid) 合并安全组并重映射用户与引用;custom_util.merge_model_and_data(cr, source_model, target_model, copy_fields, set_values=None) 合并模型并复制记录、重映射 ID 和引用;custom_util.rename_xmlids(cr, pairs, detect_module=True) 批量重命名 XML ID。

用法:在迁移脚本中从 odoo.upgrade 导入 util,从 custom_util 导入 custom_util,在 migrate(cr, version) 函数中依次调用相应辅助函数,例如先 custom_rename_model 再 custom_rename_field,随后 transfer_custom_fields 与 update_custom_views。

最佳实践与限制:对自定义或 Studio 字段始终使用 custom_util,以保持 Odoo 注册表处于标准 'base' 状态;字段重命名后应通过 update_related_field 检查其他字段的 related 或 depends 属性是否需要更新。该模块面向 PS 特定迁移场景,具体适用版本、依赖与兼容范围暂未提供。