2
votes

I've added a field to my products in Odoo called x_low_inventory_level. I would like to add a filter to the search view for the product tree that will only show products who have qty_available < x_low_inventory_level. Is this possible? I've tried adding this to the search view:

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

But I get an error:

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

2 Answers

2
votes

I think you cannot do that instead create a compute field with store =true.

This field for example is a boolean field. And use it in Search view but make sure to put store to true.

Hope you get the idea.

1
votes

create Boolean field

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

Then Use Function for return True or 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

and in XML do something like this

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