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

Odoo继承视图中双字段转标签页并新增标签页的实现方法

Fixing Odoo View Inheritance: Combine Fields into a Single Notebook & Add New Tab

Let's sort out your view inheritance problem. The issue with your current code is that you're trying to replace each field separately with a notebook, which creates duplicate notebook structures and breaks the layout. Instead, we need to remove the existing separators and fields first, then insert a single notebook container that holds all three tabs in the right place.

Here's the corrected inheritance code:

<record model="ir.ui.view" id="view_wpa_publication_form_inherit" inherit_id="module_name.view_wpa_publication_form">
    <!-- Remove the original "Editions" separator -->
    <xpath expr="//separator[@string='Editions']" position="replace"/>
    <!-- Remove the original "Ad Categories" separator -->
    <xpath expr="//separator[@string='Ad Categories']" position="replace"/>
    
    <!-- Remove the original edition_ids field -->
    <xpath expr="//field[@name='edition_ids']" position="replace"/>
    <!-- Remove the original category_ids field -->
    <xpath expr="//field[@name='category_ids']" position="replace"/>
    
    <!-- Insert the new notebook right after the top group -->
    <xpath expr="//group[@colspan='4']" position="after">
        <notebook colspan="4">
            <!-- Editions Tab -->
            <page string="Editions">
                <field name="edition_ids" mode="tree" colspan="2" nolabel="1">
                    <tree string="" editable="bottom">
                        <field name="date"/>
                    </tree>
                    <form>
                        <field name="publication_id"/>
                        <field name="date"/>
                    </form>
                </field>
            </page>
            
            <!-- Ad Categories Tab -->
            <page string="Ad Categories">
                <field name="category_ids" mode="tree" colspan="2" nolabel="1">
                    <tree string="" editable="bottom">
                        <field name="category_id"/>
                        <field name="price"/>
                        <field name="functioning"/>
                    </tree>
                    <form>
                        <field name="publication_id"/>
                        <field name="category_id"/>
                        <field name="price"/>
                        <field name="functioning"/>
                    </form>
                </field>
            </page>
            
            <!-- New Awards Tab -->
            <page string="Awards">
                <!-- Make sure your award field is properly defined on the wpa.publication model or related model -->
                <!-- Assuming you have a one2many field named award_ids for awards -->
                <field name="award_ids" mode="tree" colspan="2" nolabel="1">
                    <tree string="" editable="bottom">
                        <field name="award"/>
                    </tree>
                    <form>
                        <field name="publication_id"/>
                        <field name="award"/>
                    </form>
                </field>
            </page>
        </notebook>
    </xpath>
</record>

Key Notes:

  • Replace module_name with the actual name of the module where the parent view (view_wpa_publication_form) is defined.
  • For the Awards tab: I assumed you have a one2many field named award_ids on the wpa.publication model linking to your awards records. If your field name is different, adjust it accordingly.
  • We're using position="after" on the top group to place the notebook exactly where the original separators and fields were, keeping the form layout consistent.
  • By removing the original fields and separators first, we avoid duplicate elements and ensure the new notebook is the only container for these sections.

This approach will cleanly combine your existing fields into a single notebook and add the new Awards tab as required.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:42:11