Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] website_sale_product_search_advanced #11

Open
wants to merge 4 commits into
base: 17.0
Choose a base branch
from

Conversation

ChristianSantamaria
Copy link
Contributor

@dalonsod Change search method in v17.... Its most simple but it was hard search it

@dalonsod
Copy link
Contributor

Great, at last Odoo made a proper hook for this!!!

I'll test it ASAP

Copy link
Contributor

@dalonsod dalonsod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@api.model
def _search_get_detail(self, website, order, options):
res = super()._search_get_detail(website, order, options)
res['search_fields'].append('barcode')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally tested, when any result is obtained seems to be 👍 , but when no results were found, in internal error is raised looking for similar results:

imagen

You can try this very interesting "similar results" functionality searching with a not exact word like "florr" instead of "floor", with this addon uninstalled.

Error is raised in those cases because Odoo looks via Postgres SQL raw query for a similar result... and barcode is actually a field of product.product model, not template (see https://github.com/odoo/odoo/blob/b6b90636938ae961c339807ea893cabdede9f549/addons/product/models/product_template.py#L130 and https://github.com/odoo/odoo/blob/b6b90636938ae961c339807ea893cabdede9f549/addons/product/models/product_product.py#L44-L46). This fixes it:

Suggested change
res['search_fields'].append('barcode')
res['search_fields'].append('product_variant_ids.barcode')

def _search_get_detail(self, website, order, options):
res = super()._search_get_detail(website, order, options)
res['search_fields'].append('barcode')
res['search_fields'].append('website_partner_ref')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In original _search_get_detail code you can see that not only desired fields are added to search_fields key, but also to mapping clause (not sure which is the need), and even in fetch_fields (in some cases, indeed). Could you investigate a little but about those keys and their usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        - search_fields: fields within which the search term must be found
        - fetch_fields: fields from which data must be fetched

@ChristianSantamaria ChristianSantamaria force-pushed the 17.0-mig-website_sale_product_search_advanced branch from e2c78a6 to a18e8b2 Compare August 23, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants