Skip to Content
Menu
This question has been flagged
5 Replies
4866 Views

in our custom module we have a many2One relation to product.product.

in product.product we made a custom "name_get" Funciton to add some more Information of other custom fields to the dropdown.

so in the Dropdown the name and Value of custom_field_x and custom_field_y will be shown.

when i type the name it reduces the possible Values of the Dropdown.- but if i type the value of custom_field_x it does not work. 

so it correctly shows the Dropdown Values (productname + custom_field_x) but i can not type the values ov custom_field_x because then the Dropdown will be empty.



Avatar
Discard
Best Answer

Hi, 

you can use the name_search, this is a example:


@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
      args = args or []
 domain = ['|', ('attribute_id', operator, name), ('value_ids', operator, name)]
return self.search(expression.AND([domain, args]), limit=limit).name_get()
return super(ProductAttributeLine, self).name_search(name=name, args=args, operator=operator, limit=limit)
Avatar
Discard
Best Answer

You should try with name_search for product.product to have custom_field_x.

Avatar
Discard
Best Answer

Hi,

name_get field will update the value displayed in the many2one field. If you need to search the record based on the custom field what you can do is that define name_search for the corresponding model based on the custom fields.


You can refer this blog:  How to search many2one field by other than "name" field.

Thanks

Avatar
Discard
Author

so for product.product i have to copy the whole _name_search function and extend it? i tried with overriding the function and calling super method but without success. it always calls the product_template _name_search when i call the super Method...

Author

we have in total about 6 fields that sould be searchable here... i think it would be better to save a concatenated string in another customfield and search only this string by ilike