简体   繁体   中英

Odoo12 multiple tree view for same inherited module

What i want is to create a second tree view for stock.picking in my_model to call in another menu without to change the first tree view ("vpicktree") in the stock.picking model. To archive this in my new model i've inherited the model and create some fields that i need to show, after that i've create the second tree view like this:

<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>

After that i've create the action split and the new menu item like this :

<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" 
          />

In the stock module i haven't change nothing and the code are :

<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"/>

When i update my app, i find the second menu voice and the tree view is correct with the new compute fields but if i call the old menu the tree view is also show with the new fields.

Where i'm wrong?

Try to add a priority (some kind of order) to your form view definition:

<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>

The default value is 16 and IIRC the order of views is defined by its priority only, which makes it random (after each server restart) which view will be loaded by Odoo, if some views have the same priority value.

So by using a higher priority value (yes the name priority is a bit confusing), your view wouldn't be loaded in the original menu item.

And another hint: As you can see in the original XML code, Odoo is not using action-view-relations ( ir.actions.act_window.view ). That's why Odoo is trying to get the first possible view for stock.picking , and that's when Odoo is using the priority ordering of the views.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM