Odoo-视图中的多级继承

问题描述

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

请在下面查看详细信息:

尝试为将来的向导提供一些基本模型。这是定义模型的方式(始终使用 inherit = 进行模型之间的继承)

Model definition

由于我只想定义一次视图,因此我按照相同的方法为每个模型创建了一个表单视图:始终从“上面”继承。以下是(第一个)基本视图的定义,模型为 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 并添加自己的字段从“上”继承。

这是第二个视图,模型为 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',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>

我在视图定义中缺少什么吗?

谢谢。

解决方法

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

从视图Common Structure

模式

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

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...