odoo/odoo#199304

Created by fw-bot
Merged at 8df68773fb797c752448ef231618ebbc2efdf666

Statuses:

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

  1. Create a new product with a lot of variants;
  2. publish it to the website;
  3. edit the website home page to add a product carousel;
  4. 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.

opw-4302856

Forward-Port-Of: #195857