Odoo Commit 每日一读/1 - 084dbf9

每天象读报纸一样浏览最新的提交信息(commit log)是学习Odoo(包括其他开源项目)的一个 好方法,它可以让你了解Odoo的发展动向,专家对bug的处理方法,最新的特性实现等。

本次要介绍的Odoo提交是: 084dbf9。该提交于2017年11月3日新鲜出炉。是对OdooV11版的库 存盘点功能的一个小改进。

改进结果

这个改进的结果就是如下图所示,当我们在开启Debug模式后,当盘点单在确认状态,即“In Progress” 状态时,在该“盘点单”的右上角出现一个新的叫做“Detail”的按钮,点击这个按钮就会显示盘点明细的列表视图。

Commit 084dbf9 log for Odoo

改进原因

增加这个额外的列表视图的原因是:

  1. 原来的盘点明细是嵌入在盘点单内的,无法用到Odoo的搜索工具,当盘点项很多的时候 很难查找,过滤。

  2. 由于盘点单上的compute字段以及明细中的各种onchange混合作用,对明细行的每一行的 改动都会触发一堆的运算,如果明细很多的话,那页面就半天都不会有响应了。

似乎这个改进的确不错,但不明白为什么还是雪藏在debug模式中,打算在公司的Odoo页面 卡死的时候,给Odoo管理员一个📈工资的机会?

代码说明

代码非常简单,只是在盘点单的view中增加了一个按钮和按钮对应的window action。下 面是对按钮部分关于访问控制的解释:

                    <button name="action_inventory_line_tree"
                        class="oe_stat_button"
                        icon="fa-building-o"
                        type="object"
                        help="List view of lines"
                        groups="base.group_no_one" (1)
                        states="confirm">          (2)
                        <div class="o_form_field o_stat_info">
                            <span class="o_stat_text">Details</span>
                        </div>
                    </button>
1 这里groups用来指定该按钮的可访问的用户组,base.group_no_one 表示在 debug模式下访问的权限
2 这里的states也是用来做访问控制的,这里的设置表明只有在按钮所绑定的实体对 象,即stock.inventory的状态(state)为:confirm时,这个按钮才会显示。

原始提交信息

commit 084dbf9b8f258e453c4a5958bc146c8f4c4ddbbb
Author: Nicolas Martinelli <[email protected]>
Date:   Fri Aug 11 15:56:33 2017 +0200

    [FIX] stock: inventory adjustment

    The inventory adjustment form is not suitable for large inventories.

    First, a list view embedded in a form view is not convenient since it
    doesn't provide any search capabilities. The user has to rely on the
    search feature of the browser, which has restricted features in
    comparison to the Odoo search field.

    Then, the existing onchange mechanism coupled with computed fields
    triggers heavy computations impacting all lines each time a single
    line is modified. This leads to a hanging page for every inventory line
    modification, which causes a non-negligeable loss of time.

    This commit introduces a new tree view for inventory lines, accessible
    thanks to a stat button on the inventory page. This button is available
    in debug mode, if the inventory is in state 'Confirmed'. The tree view
    contains the same fields than the tree view embedded in the form view,
    without the flaws of the latter.

    opw-760614

diff --git a/addons/stock/views/stock_inventory_views.xml b/addons/stock/views/stock_inventory_views.xml
index db133d114d9..d3394da3c13 100644
--- a/addons/stock/views/stock_inventory_views.xml
+++ b/addons/stock/views/stock_inventory_views.xml
@@ -120,6 +120,19 @@
                 <field name="state" widget="statusbar" statusbar_visible="draft,confirm,done"/>
             </header>
             <sheet>
+                <div class="oe_button_box" name="button_box">
+                    <button name="action_inventory_line_tree"
+                        class="oe_stat_button"
+                        icon="fa-building-o"
+                        type="object"
+                        help="List view of lines"
+                        groups="base.group_no_one"
+                        states="confirm">
+                        <div class="o_form_field o_stat_info">
+                            <span class="o_stat_text">Details</span>
+                        </div>
+                    </button>
+                </div>
                 <div class="oe_title">
                     <label for="name" class="oe_edit_only"/>
                     <h1><field name="name" placeholder="e.g. Annual inventory"/></h1>
@@ -247,5 +260,15 @@
         </field>
     </record>

+    <record id="action_inventory_line_tree" model="ir.actions.act_window">
+        <field name="name">Inventory Lines</field>
+        <field name="type">ir.actions.act_window</field>
+        <field name="res_model">stock.inventory.line</field>
+        <field name="view_type">form</field>
+        <field name="view_mode">tree</field>
+        <field name="view_id" ref="stock_inventory_line_tree2"/>
+        <field name="domain">[('inventory_id', '=', active_id)]</field>
+    </record>
+
     <menuitem action="action_inventory_form" id="menu_action_inventory_form" parent="menu_stock_warehouse_mgmt" sequence="30"/>
 </odoo>