如何模仿stock.picking.type看板视图的行为?

问题描述 投票:1回答:1

目的

我正在尝试开发一个类似于你可能使用的菜单项(如果你安装了stock模块)。如果您转到仓库>操作>所有操作,您将看到具有可用拣配类型的stock.picking.type模型的漂亮看板视图。如果单击任何拾取类型框的“所有操作”链接,您将被重定向到stock.picking树视图。嗯,这是我唯一需要的东西,但是,我想要链接将你重定向到我的自定义stock.move树。

所以,我创建了我的menuitem,以及我自己的stock.picking.type看板视图,它将重定向到我自定义的stock.move树视图。

我的代码

我的看板视图

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

我的行动打开我的看板(以及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>

我的menuitem

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

行为

当我点击我的menuitem时,我得到了不同的错误,他们中的大多数都告诉我那个不存在的字段。问题是所有这些领域都属于我为stock.move模型制作的搜索视图。我不知道为什么这个搜索视图被加载到我的stock.picking.type动作中,所以Odoo试图用stock.move的搜索视图显示我的看板视图。这就是错误的原因。如果我评论搜索视图的每个字段,我会收到此错误:

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: )>"

这是我的stock.move搜索视图的第一个过滤器的域。

为什么Odoo试图加载该搜索视图? (如果你看到我的动作代码,我甚至包括参数search_view_id,试图加载stock.picking.type的默认搜索视图而不是stock.move)。

还有一个更令人惊讶的事情是,如果我修改我的stock.picking.type看板视图的优先级并编写16例如,它将比原来的更优先(在stock模型中声明),所以现在如果再次点击Warehouse>操作>所有操作,我的看板视图已加载。但是,嘿,这里正确加载,它完美,完全按照我的意愿,看板视图也可以,它的搜索视图,链接重定向到我想要的stock.move视图...

谁能解释一下这里发生了什么?

xml openerp odoo-8
1个回答
0
投票

从代码的外观来看,你没有任何域名('state', '=', 'draft')我假设当你在代码中午餐时第一次在你的动作代码中有一个。当你有错误时,你删除它。并且在XML中删除代码不会更新数据库中的数据。

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

当您在xml中出现错误时,请先尝试记住在从数据库中清除之前删除的代码。

© www.soinside.com 2019 - 2024. All rights reserved.