2017-07-19 61 views
2

我在Odoo的產品中添加了一個字段,名稱爲x_low_inventory_level。我想爲產品樹的搜索視圖添加一個篩選器,該篩選器僅顯示擁有qty_available < x_low_inventory_level的產品。這可能嗎?我試着加入這個以搜索視圖:Odoo搜索視圖過濾器使用模型中的值

<filter string="Low Inventory" name="low_inventory" domain="[('qty_available', '&lt;', x_low_inventory_level)]"/> 

但我得到一個錯誤:

https://my-instance.odoo.com/web/content/525-9a23e87/web.assets_backend.js:1715 
Traceback: 
Error: Failed to evaluate search criterions: 
{"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nNameError: name 'x_low_inventory_level' is not defined\n\n{\"domains\":[[],\"[('qty_available', '<', x_low_inventory_level)]\"],\"contexts\":[{\"lang\":\"en_US\",\"tz\":false,\"uid\":1,\"params\":{\"action\":418,\"min\":1,\"limit\":80,\"view_type\":\"list\",\"model\":\"product.product\",\"menu_id\":84,\"_push_me\":false}},{}],\"group_by_seq\":[]}"}} 
    at Object.<anonymous> (https://my-instance.odoo.com/web/content/525-9a23e87/web.assets_backend.js:1715:1192) 
    at fire (https://my-instance.odoo.com/web/content/528-59c08d4/web.assets_common.js:541:299) 
    at Object.fireWith [as resolveWith] (https://my-instance.odoo.com/web/content/528-59c08d4/web.assets_common.js:546:198) 
    at Object.deferred.(anonymous function) [as resolve] (https://my-instance.odoo.com/web/content/528-59c08d4/web.assets_common.js:548:56) 
    at https://my-instance.odoo.com/web/content/525-9a23e87/web.assets_backend.js:1625:3 

回答

2

我認爲你不能做到這一點,而不是創建商店= true的計算領域。

該字段例如是一個布爾字段。並在搜索視圖中使用它,但一定要把存儲爲真。

希望你明白了。

+0

對不起,我沒讀過評論波紋管,我認爲你們都準備好了解出來 – Cherif

+0

技術上你不需要'store = True',但是會的用它更容易;-) – CZoellner

1

創建布爾字段

is_low_inventory_level = fields.Boolean('qty_available is_low_inventory_level', default=False) 

然後使用函數返回TRUE或FALSE

@api.onchange('qty_available','x_low_inventory_level') 
def _onchange_qty_available(self): 
    if self.qty_available < x_low_inventory_level: 
     self.is_low_inventory_level = True 
    else: 
     elf.is_low_inventory_level = False 

和XML做這樣的事情

<filter string="Low Inventory" name="low_inventory" domain="[('is_low_inventory_level', '!=', False)]"/>