首页 文章

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

提问于
浏览
1

目的

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

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

我的代码

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

行为

当我点击我的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 视图...

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

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中出现错误时,请先尝试记住在从数据库中清除之前删除的代码 .

相关问题