You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo ORM中非抽象原型继承行为差异的原因探究

Odoo ORM原型继承非抽象父类的行为差异解析

现象对比

1. ir.actions.*系列的自动父记录生成

当创建ir.actions.report子类记录时,父类ir.actions.actions会自动生成对应记录,代码示例:

class IrActionsReport(models.Model):
    _name = 'ir.actions.report'
    _description = 'Report Action'
    _inherit = ['ir.actions.actions']
    _table = 'ir_act_report_xml'
    _order = 'name, id'
    _allow_sudo_commands = False

2. event.booth的无自动父记录生成

创建event.booth子类记录时,父类event.type.booth不会自动生成对应记录,代码示例:

class EventBooth(models.Model):
    _name = 'event.booth'
    _description = 'Event Booth'
    _inherit = [
        'event.type.booth',
        'mail.thread',
        'mail.activity.mixin'
    ]

差异原因

  • ir.actions.actions的特殊框架设计
    ir.actions.actions是Odoo所有动作类的统一注册表模型,框架层面为其子类做了特殊CRUD钩子处理:当子类(如报表、窗口动作)创建记录时,会自动在父类ir.actions.actions中生成对应记录,目的是让所有动作类型能被全局索引和统一管理,方便系统在任意场景下查找和调用动作。

  • event.type.booth与event.booth的业务逻辑隔离
    event.type.booth是活动展位的模板模型,event.booth是实际活动中的展位实例模型,两者是模板与实例的关系。event.booth继承父类仅为复用字段定义,业务逻辑上不需要将实例记录同步到模板模型——模板用于生成实例的初始数据,实例是模板的具体落地,数据完全隔离,框架也没有为这类业务模型设计自动同步父记录的逻辑。


内容的提问来源于stack exchange,提问作者Sake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 15:42:38