Skip to content

Conversation

@fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Feb 25, 2025

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:

try:
records = self.env[filter_sudo.model_id].sudo(False).with_context(**literal_eval(filter_sudo.context)).search(
domain,
order=','.join(literal_eval(filter_sudo.sort)) or None,
limit=limit
)
return self._filter_records_to_values(records)

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:
def _filter_records_to_values(self, records, is_sample=False):
hide_variants = self.env.context.get('hide_variants') and not isinstance(records, list)
if hide_variants:
records = records.product_tmpl_id

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

@robodoo
Copy link
Contributor

robodoo commented Feb 25, 2025

Pull request status dashboard

@fw-bot
Copy link
Contributor Author

fw-bot commented Feb 25, 2025

This PR targets saas-18.2 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Feb 25, 2025
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Feb 25, 2025
@fw-bot
Copy link
Contributor Author

fw-bot commented Feb 25, 2025

@lvsz @Feyensv ci/runbot failed on this forward-port PR

@lvsz lvsz force-pushed the saas-18.2-saas-17.4-opw-4302856-correctly_apply_limit_when_searching_newest_products-sile-418735-fw branch from 9367539 to e0ebdd5 Compare February 26, 2025 13:52
@fw-bot
Copy link
Contributor Author

fw-bot commented Feb 26, 2025

@lvsz @Feyensv this PR was modified / updated and has become a normal PR. It must be merged directly.

@lvsz
Copy link
Contributor

lvsz commented Feb 26, 2025

robodoo r+

@robodoo
Copy link
Contributor

robodoo commented Feb 26, 2025

@lvsz @Feyensv 'ci/runbot' failed on this reviewed PR.

@lvsz lvsz force-pushed the saas-18.2-saas-17.4-opw-4302856-correctly_apply_limit_when_searching_newest_products-sile-418735-fw branch from e0ebdd5 to f261883 Compare February 26, 2025 15:05
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 2249939, 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. 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.

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

X-original-commit: 116e615
@lvsz lvsz force-pushed the saas-18.2-saas-17.4-opw-4302856-correctly_apply_limit_when_searching_newest_products-sile-418735-fw branch from f261883 to ef575ce Compare February 26, 2025 15:55
@lvsz
Copy link
Contributor

lvsz commented Feb 28, 2025

robodoo r+

@robodoo
Copy link
Contributor

robodoo commented Mar 1, 2025

@lvsz @Feyensv staging failed: ci/runbot on 229139cf9f6b4c787b799b49f0961107470d8592 (view more at https://runbot.odoo.com/runbot/build/75870818)

@lvsz
Copy link
Contributor

lvsz commented Mar 3, 2025

robodoo retry

robodoo pushed a commit that referenced this pull request Mar 3, 2025
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 2249939, 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. 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.

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

closes #199331

X-original-commit: 116e615
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Signed-off-by: Levi Siuzdak <sile@odoo.com>
@robodoo robodoo closed this Mar 3, 2025
@xmo-odoo xmo-odoo deleted the saas-18.2-saas-17.4-opw-4302856-correctly_apply_limit_when_searching_newest_products-sile-418735-fw branch March 7, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants