odoo/odoo#199304
Created by fw-bot
Statuses:
- legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/template: Contact runbot team on discord for help.
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
- label
- odoo-dev:18.0-saas-17.4-opw-4302856-correctly_apply_limit_when_searching_newest_products-sile-413018-fw
- head
- 849bc4942f0aedbf704321c476c6786b686f1584
- merged
- 8 months ago by Bugfix, Levi Siuzdak
| odoo/odoo | |
|---|---|
| saas-17.4 | #195857 |
| 18.0 | #199304 |
| saas-18.1 | #199314 |
| saas-18.2 | #199331 |
| saas-18.3 | |
| saas-18.4 | |
| 19.0 | |
| master | #199972 |
[FW][FIX] website_sale: use correct limit when filtering newest products
Versions
- saas-17.4+
Steps
- Create a new product with a lot of variants;
- publish it to the website;
- edit the website home page to add a product carousel;
- set it to display newest products & hide variants.
Issue
Fewer than 16 products are displayed in the carousel.
Cause
Unlike the other product filters handled in #189040, the "Newest Products" filter is defined in data/data.xml, and stored as a record.
This means it doesn't use the _get_products method to perform the search, instead using the _prepare_values method from the website module.
For obvious reasons, the method defined in website doesn't take the hide_variants parameter into account to get the correct amount of search results: https://github.com/odoo/odoo/blob/0f64298c871ffea088a4fe6255d19852c8348159/addons/website/models/website_snippet_filter.py#L102-L108
Instead it passes 16 product.product records to the _filter_records_to_values override in website_sale, where duplicate templates are filtered out, resulting in fewer than 16 product templates: https://github.com/odoo/odoo/blob/0f64298c871ffea088a4fe6255d19852c8348159/addons/website_sale/models/website_snippet_filter.py#L73-L76
Solution
When calling super()._prepare_values for stored product.product filters, temporarily square the usual limit for the search, and filter reduce to size later.
This may still be inadequate when working with products with dozens of variants, but should cover most normal use cases without requiring drastic changes to filter templates or search domain in stable.
On master, we could add a new filter specifically for product.template.
Forward-Port-Of: #195857