【问题标题】:Odoo - Multi level inheritance in viewsOdoo - 视图中的多级继承
【发布时间】:2020-10-26 16:10:56
【问题描述】:

我正在尝试使用具有多级继承的视图,但视图中未显示来自子级的字段。我目前正在使用 Odoo 11 社区版。

请看下面的详细信息:

尝试为未来的巫师提供一些基本模型。这就是模型的定义方式(始终使用 inherit = 用于模型之间的继承):

由于我只想定义一次视图,我为每个模型创建了一个表单视图,遵循相同的方法:始终从“上方”继承。下面是(第一个)基本视图模型handleprocess.quick.action的定义:

<record model="ir.ui.view" id="handleprocess_qact_abstract_wz_form_view">
        <field name="name">handleprocess_qact_abstract_wz.form</field>
        <field name="model">handleprocess.quick.action</field>
        <field name="arch" type="xml">
            <form string="Quick Action">
                <group class="bg-info" col="4" id="security_check_group">
                    <h6 colspan="4" style="color: red">Are you sure you want to execute this Quick Action?</h6>
                    <h6 colspan="4">Check to confirm you know what you are doing: <field name="security_check" nolabel="1" /></h6>
                </group>
                <group id="basic_fields">
                    <field name="environment" />
                    <field name="data_center" attrs="{'invisible': [('environment', '!=', 'prod')], 'required': [('environment', '=', 'prod')]}" />
                </group>
                <footer class="pull-right">
                    <button name="execute_qact" type="object" string="Execute" class="oe_highlight" attrs="{'invisible': [('security_check', '=', False)]}" />
                    <button special="cancel" string="Cancel" />
                </footer>
            </form>
        </field>
    </record>

然后,接下来的 3 个视图中的每一个都使用 xpath 从“above”继承并添加自己的字段。

这是第二个视图,模型 handleprocess.quick.action.update.file

<record model="ir.ui.view" id="handleprocess_qact_abstract_wz_form_view">
        <field name="name">handleprocess_qact_abstract_wz.form</field>
        <field name="model">handleprocess.quick.action</field>
        <field name="arch" type="xml">
            <form string="Quick Action">
                <group class="bg-info" col="4" id="security_check_group">
                    <h6 colspan="4" style="color: red">Are you sure you want to execute this Quick Action?</h6>
                    <h6 colspan="4">Check to confirm you know what you are doing: <field name="security_check" nolabel="1" /></h6>
                </group>
                <group id="basic_fields">
                    <field name="environment" />
                    <field name="data_center" attrs="{'invisible': [('environment', '!=', 'prod')], 'required': [('environment', '=', 'prod')]}" />
                </group>
                <footer class="pull-right">
                    <button name="execute_qact" type="object" string="Execute" class="oe_highlight" attrs="{'invisible': [('security_check', '=', False)]}" />
                    <button special="cancel" string="Cancel" />
                </footer>
            </form>
        </field>
    </record>

如果此时我显示该模型的表单视图,所有字段都会正确显示。字段在第二级继承后消失,即在我定义此视图后(对于模型 handleprocess.quick.action.update.file.intergate):

<record model="ir.ui.view" id="handleprocess_qact_abstract_ig_wz_form_view">
        <field name="name">handleprocess_qact_abstract_ig_wz.form</field>
        <field name="model">handleprocess.quick.action.update.file.intergate</field>
        <field name="inherit_id" ref="handleprocess.handleprocess_qact_update_file_wz_form_view"/>
        <field name="arch" type="xml">
            <data>
                <xpath expr="//field[@name='create_backup']" position="before">
                    <field name="carrier_id" options="{'no_create': True}" />
                </xpath>
            </data>
        </field>
    </record>

在向导的表单视图下方,同样的问题:没有显示任何字段。

<record model="ir.ui.view" id="handleprocess_qact_ig_template_wz_form_view">
        <field name="name">handleprocess_qact_ig_template_wz.form</field>
        <field name="model">handleprocess.qact.ig.template.wz</field>
        <field name="inherit_id" ref="handleprocess_qact_abstract_ig_wz_form_view"/>
        <field name="priority">70</field>
        <field name="arch" type="xml">
            <xpath expr="//group[@id='security_check_group']/h6" position="before">
                <div>This Quick Action updates the template files in carrier boxes, in the environment specified below.</div>
            </xpath>
            <xpath expr="//field[@name='carrier_id']" position="after">
                <field name="template_file_id" options="{'no_create': True}" />
            </xpath>
        </field>
    </record>

请注意,我使用不同的模型,因为我需要根据字段将它们分开,因为将来计划创建其他一些向导,并且对于其他向导,并非所有字段都相同(以上向导定义只是第一个,应该还会有更多)。

打开向导(TransientModel)的动作是这样定义的,直接调用向导模型的表单视图:

<record model="ir.actions.act_window" id="handleprocess_qact_ig_template_wz_action">
        <field name="name">Update Template</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">handleprocess.qact.ig.template.wz</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="handleprocess.handleprocess_qact_ig_template_wz_form_view" />
        <field name="target">new</field>
    </record>

我在视图定义中遗漏了什么吗?

提前致谢。

【问题讨论】:

    标签: inheritance view odoo odoo-11


    【解决方案1】:

    派生视图的mode 需要设置为primary,因为它是派生模型的基础(也许是唯一)视图。否则,view matching 规则将不适用。

    来自Common Structure的意见:

    模式

    继承模式,见Inheritance。如果inherit_id 未设置,则mode 只能是primary。如果设置了inherit_id,则默认情况下为extension,但可以显式设置为primary

    委托继承是您想要执行此操作的一个示例。在这种情况下,您的派生模型将与其父模型分离,并且与其中一个匹配的视图不会与另一个匹配。假设您从与父模型关联的视图继承并希望自定义派生视图以显示来自派生模型的数据。派生视图的mode 需要设置为primary,因为它是该派生模型的基础(也许是唯一)视图。否则,view matching 规则将不适用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      相关资源
      最近更新 更多