1
votes

THE PURPOSE

I'm trying to develop a menuitem similar to the one you probably use to work with (if you have stock module installed). If you go to Warehouse > Operations > All Operations, you will see a beautiful kanban view of stock.picking.type model with the available picking types. If you click on the All operations link of any of the picking type boxes, you will be redirected to stock.picking tree view. Well, that's the only thing I need, but, I want the link to redirect you to my custom stock.move tree instead.

So, I've created my menuitem, and my own stock.picking.type kanban view which is going to redirect to my custom stock.move tree view.

MY CODE

My Kanban view

<record id="stock_picking_type_2_move_kanban" model="ir.ui.view">
    <field name="name">stock.picking.type.2.move.kanban</field>
    <field name="model">stock.picking.type</field>
    <field name="priority" eval="20"/>
    <field name="arch" type="xml">
        <kanban class="oe_background_grey" create="0">
            <field name="complete_name"/>
            <field name="color"/>
            <templates>
                <t t-name="kanban-box">
                    <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_stock_picking_type">
                        <div class="oe_kanban_content">
                            <h4 class="text-center"><strong><field name="complete_name"/></strong></h4>
                            <div class="oe_items_list oe_kanban_ellipsis">
                                <div>
                                    <a name="%(action_in_alt_move_views)d" type="action">Open moves</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </t>
            </templates>
        </kanban>
    </field>
</record>

My action which opens my kanban (and the default form of stock.picking.type)

<record id="action_in_alt_picking_type_views" model="ir.actions.act_window">
    <field name="name">Picking types</field>
    <field name="res_model">stock.picking.type</field>
    <field name="type">ir.actions.act_window</field>
    <field name="view_type">form</field>
    <field name="view_mode">kanban,form</field>
    <field name="search_view_id" ref="stock.view_pickingtype_filter"/>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">
        Click to create a new picking type. 
        </p><p>
        The picking type system allows you to assign each stock
        operation a specific type which will alter its views accordingly.  
        On the picking type you could e.g. specify if packing is needed by default, 
        if it should show the customer.  
        </p>
    </field>
</record>

<record id="action_in_alt_picking_type_kanban" model="ir.actions.act_window.view">
    <field name="view_mode">kanban</field>
    <field name="view_id" ref="poc_alternative_stock.stock_picking_type_2_move_kanban"/>
    <field name="act_window_id" ref="action_in_alt_picking_type_views"/>
</record>

<record id="action_in_alt_picking_type_form" model="ir.actions.act_window.view">
    <field name="view_mode">form</field>
    <field name="view_id" ref="stock.view_picking_type_form"/>
    <field name="act_window_id" ref="action_in_alt_picking_type_views"/>
</record>

My menuitem

<menuitem action="action_in_alt_picking_type_views"
    id="menu_action_in_alt_move_views"
    parent="stock.menu_stock_warehouse_mgmt" sequence="4"/>

THE BEHAVIOUR

When I clicked on my menuitem, I got different errors, most of them telling me that the field whatever didn't exist. The problem is that all these fields belonged to a search view I made for stock.move model. And I don't know why this search view is being loaded in my stock.picking.type action, so Odoo is trying to show my kanban view with a search view of stock.move. That's the reason of the errors. If I comment every field of the search view, I get this error:

raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'state' in leaf "<osv.ExtendedLeaf: ('state', '=', 'draft') on stock_picking_type (ctx: )>"

Which is the domain of the first filter of my stock.move search view.

Why is Odoo trying to load that search view? (If you see my action code, I've even included the parameter search_view_id, to try to load the default search view of stock.picking.type instead of the stock.move one).

And there's a more surprisingly thing and is that if I modify the priority of my stock.picking.type kanban view and write 16 for example, it's going to have more priority than the original one (declared in stock model), so now if click again on Warehouse > Operations > All Operations, my kanban view is loaded. But, hey, here's loaded rightly, and it works perfect, exactly as I want, the kanban view is OK, its search view too, and the link redirects to the stock.move view I want...

Can anyone explain me what's happening here?

1

1 Answers

0
votes

From the looks of your code you don't have any domain ('state', '=', 'draft') i'm assuming when you lunch your code the first time in your action code there was one. and when you had the error you removed it. and in XML removing code will not update the data in database.

  <!-- you must tell Odoo empty the field first and next time 
       remove the code(in production) when odoo load some thing to database
       like context, domain, any other value clear it first then remove
       the code -->
  <fied name="domain">[] </field> 

When you have an error in xml try to remember what code you removed before you clear it from database first.