Juniorzkie
Juniorzkie

Reputation: 27

How to make custom field in product form searchable in order lines

I created a custom field in product form. This field named as x_studio_part_number.

Now, i want this custom field searchable when searching for product in order line of purchase and sales model or other models.

Typing the part number in product order line in purchase module

Typing the part number in product order line in sales module

I already tried modifying the views in product.template.search and product.product.search using odoo studio.

Code i added in xml

But, i have to use the "search more.." to prompt the advance search. I want to search directly in order line.

Search more prompt

It successfully show the product when typing the part number in custom field

PS. We are using odoo online and studio. So, please give a suggestion/help the fits only we currently have. Or using Settings/Technical.

Upvotes: -1

Views: 220

Answers (1)

Tan Justinn
Tan Justinn

Reputation: 33

Unfortunately, there is no way to modify the functionality of the Many2one field input from Studio. What you have done is the only possible solution directly from Studio with regards to searching a related record's fields for a Many2one field.

FYI: When you click into the text input and start typing, a JavaScript Many2XAutocomplete widget/component performs a query on the database, searching the related model (product.product in your case, I believe) for names that contain the input string.

// In addons/web/static/src/views/fields/relational_utils.js:Many2xAutocomplete
search(name) {
    return this.orm.call(this.props.resModel, "name_search", [], {
        name: name,
        operator: "ilike",
        args: this.props.getDomain(),
        limit: this.props.searchLimit + 1,
        context: this.props.context,
    });
}

If you were implement a custom addon/module to enable the kind of search you want, you would probably have to modify this function by creating another class to extend from Odoo's Many2XAutocomplete component. Then you would have to create a custom Many2OneField field widget to utilize this component and have the Many2one field utilize this widget. Again, this would all involve JavaScript and backend code.

Upvotes: 0

Related Questions