1

I have a customized tree view that can be accessed from my customized action window.

I would like to set default search for a text "/Stock" in the Many2One field Location (location_id) of model stock.quant.

This is the desired result after clicking a menu that calls the customized action window.

search-by-name

Right now, I can only type the word in the search bar to get the result in the image. However, I want to make it happen automatically upon loading this page.

I tried <field name="context">{'search_default_location_id': '/Stock'}</field> in my customized action window, but it gives me this error.

invalid input syntax for type integer: "/Stock" LINE 1: ...ROM "stock_location" WHERE "stock_location".id IN ('/Stock')

Since I created all of these menu, action window, and view, I can customize anywhere among these components.

How to achieve this goal?

holydragon
  • 6,158
  • 6
  • 39
  • 62

1 Answers1

0

I got the right solution for my case.

First, create a new customized search view that will be specifically called by the action window. Create a filter with the desired domain. For example, my case is "/Stock".

<filter name="stock" string="/Stock" domain="[('location_id.complete_name', '=ilike', '%/Stock%')]"/>

After that, use the search view in the action window and also set the filter to be default in that search view in the context.

<field name="context">{'search_view_ref':'the_search_view_id','search_default_stock': 1}</field>

As a result, the filter will be set as a default in the searchbar of the view upon visiting the view.

holydragon
  • 6,158
  • 6
  • 39
  • 62