同一继承模块的 Odoo12 多树视图

Odoo12 multiple tree view for same inherited module

我想要的是在 my_model 中为 stock.picking 创建第二个树视图以调用另一个菜单而不更改 [=] 中的第一个树视图 ("vpicktree") 24=] 模型。 为了在我的新模型中存档它,我继承了模型并创建了一些我需要显示的字段,之后我创建了第二个树视图,如下所示:

<record id="stock_picking_spedizioni_tree" model="ir.ui.view">
    <field name="name">stock.picking.spedizioni.tree</field>
    <field name="model">stock.picking</field>
    <field name="arch" type="xml">
        <tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" decoration-danger="state not in ('cancel', 'done') and scheduled_date &lt; current_date" string="Picking list">
            <field name="name"/>
            <field name="carrier_id" string="Corriere"/>
            <field name="carrier_tracking_ref" string="Tracking"/>
            <field name="ddt_ids" string="TD"/>
            <field name="partner_id"/>
            <field name="IndirizzoDestinatario" string = "Indirizzo"/> #new compute field
            <field name="ComuneDestinatario" string = "Comune"/> #new compute field
            <field name="ZipDestinatario" string = "Cap"/>#new compute field
            <field name="ProvinciaDestinatario" string = "Prov"/>#new compute field
            <field name="date" invisible="1"/>
            <field name="scheduled_date"/>
            <field name="origin"/>
            <field name="group_id" invisible="1"/>
            <field name="backorder_id"/>
            <field name="state"/>
            <field name="priority" invisible="1"/>
            <field name="picking_type_id" invisible="1"/>
        </tree>   
    </field>
</record>

之后,我创建了操作拆分和新菜单项,如下所示:

<record model="ir.actions.act_window" id="action_parent_picking_spedizioni1">
    <field name="name">Spedizioni</field>
    <field name="res_model">stock.picking</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field eval="False" name="view_id"/>
</record>   

<record id="child_action_window_tree" model="ir.actions.act_window.view">
        <field eval="1" name="sequence"/>
        <field name="view_mode">tree</field>
        <field name="view_id" ref="stock_picking_spedizioni_tree" />
        <field name="act_window_id" ref="action_parent_picking_spedizioni1" />
</record>

<record id="child_action_window_form" model="ir.actions.act_window.view">
       <field eval="2" name="sequence"/>
       <field name="mode">primary</field>
       <field name="view_mode">form</field>
       <field name="view_id" ref="stock.view_picking_form" /> # same form view is ok 
       <field name="act_window_id" ref="action_parent_picking_spedizioni1" />
</record>       

<menuitem id="menu_spedizioni" 
          name="Spedizioni" 
          parent="stock.menu_stock_warehouse_mgmt" 
          sequence="6" 
          action="action_parent_picking_spedizioni1" 
          />

在库存模块中,我没有做任何更改,代码是:

<record id="vpicktree" model="ir.ui.view">
        <field name="name">stock.picking.tree</field>
        <field name="model">stock.picking</field>
        <field name="arch" type="xml">
            <tree decoration-info="state == 'draft'" decoration-muted="state == 'cancel'" decoration-danger="state not in ('cancel', 'done') and scheduled_date &lt; current_date" string="Picking list">
                <field name="name"/>
                <field name="location_dest_id" groups="stock.group_stock_multi_locations"/>
                <field name="partner_id"/>
                <field name="date" invisible="1"/>
                <field name="scheduled_date"/>
                <field name="origin"/>
                <field name="group_id" invisible="1"/>
                <field name="backorder_id"/>
                <field name="state"/>
                <field name="priority" invisible="1"/>
                <field name="picking_type_id" invisible="1"/>
            </tree>
        </field>
    </record>

    <record id="action_picking_tree_all" model="ir.actions.act_window">
        <field name="name">Transfers</field>
        <field name="res_model">stock.picking</field>
        <field name="type">ir.actions.act_window</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,kanban,form,calendar</field>
        <field name="domain"></field>
        <field name="context">{
                'contact_display': 'partner_address',
        }
        </field>
        <field name="search_view_id" ref="view_picking_internal_search"/>
        <field name="help" type="html">
          <p class="o_view_nocontent_smiling_face">
            Define a new transfer
          </p>
        </field>
    </record>

    <menuitem id="all_picking" name="Transfers" parent="menu_stock_warehouse_mgmt" sequence="5" action="action_picking_tree_all" groups="stock.group_stock_manager,stock.group_stock_user"/>

当我更新我的应用程序时,我发现第二个菜单语音和树视图对于新的计算字段是正确的,但如果我调用旧菜单,树视图也会显示新字段。

我哪里错了?

尝试向表单视图定义添加优先级(某种顺序):

<record id="stock_picking_spedizioni_tree" model="ir.ui.view">
    <field name="name">stock.picking.spedizioni.tree</field>
    <field name="model">stock.picking</field>
    <field name="priority" eval="20" />
    <field name="arch" type="xml">
        <!-- tree -->  
    </field>
</record>

默认值为 16 并且 IIRC 视图的顺序仅由其 priority 定义,这使得它随机(在每次服务器重启后)Odoo 将加载哪个视图,如果一些视图具有相同的优先级值。

因此,通过使用更高的优先级值(是的,名称优先级有点令人困惑),您的视图将不会加载到原始菜单项中。

另一个提示:正如您在原始 XML 代码中所见,Odoo 没有使用动作-视图-关系 (ir.actions.act_window.view)。这就是为什么 Odoo 试图为 stock.picking 获取第一个可能的视图,这就是 Odoo 使用视图的优先级排序的原因。