Skip to content
Snippets Groups Projects
Commit 67abc6c8 authored by qsm-odoo's avatar qsm-odoo
Browse files

[FIX] website_blog, *: allow more than 6 blog posts in dynamic snippet

*: website

Commit [1] introduced the possibility to configure "website filters"
used in the website to display some records dynamically via the "dynamic
snippet" and its variants. One of their field is `limit` which is a max
number of records the filter allows to show (so that the client side
cannot ask for thousands of records). Users can configure the limit used
by a snippet via the editor: they are allowed to choose up to 16, still
safe-guarded by the internal limit configured on the website filter on
the python side.

The problem here was that [2] introduced website filters for the blog
posts but set up a max limit of 6. Thus breaking the editor option if
the user choose a limit between 7 and 16. This commit fixes the issue,
for newly configured snippets (as a stable fix) or for users who would
-u their blog application.

Steps to reproduce:
- Install blog application
- Add a "Blog Posts" snippet
- Set "Fetched Elements" to 10 (there are 7 records in demo data)
=> Only 6 are still shown
- Save

With the fix:
- Restart your server
=> Only 6 are still shown
- Enter edit mode, reset "Fetched Elements" to >6
=> 7 records are now shown

[1]: https://github.com/odoo/odoo/commit/0e7640b5f22d2bea04bbe22d3189cff7e03af545
[2]: https://github.com/odoo/odoo/commit/3c0d98bcd8adf9325ee3497eb8d25ec7f904d6a5



opw-2885948

closes odoo/odoo#106754

Signed-off-by: default avatarRomain Derie (rde) <rde@odoo.com>
parent b469295c
No related branches found
No related tags found
No related merge requests found
......@@ -82,7 +82,16 @@ class WebsiteSnippetFilter(models.Model):
"""Gets the data and returns it the right format for render."""
self.ensure_one()
limit = limit and min(limit, self.limit) or self.limit
# TODO adapt in master: the "limit" field is there to prevent loading
# an arbitrary number of records asked by the client side. It was
# however set to 6 for a blog post filter, probably thinking it was a
# default limit and not a max limit. That means that configuring a
# higher limit via the editor (which allows up to 16) was not working.
# As a stable fix, this was made to bypass the max limit if it is under
# 16, and only for newly configured snippets.
max_limit = max(self.limit, 16) if self.env.context.get('_bugfix_force_minimum_max_limit_to_16') else self.limit
limit = limit and min(limit, max_limit) or max_limit
if self.filter_id:
filter_sudo = self.filter_id.sudo()
domain = filter_sudo._get_eval_domain()
......
......@@ -122,6 +122,13 @@ const DynamicSnippet = publicWidget.Widget.extend({
'limit': parseInt(nodeData.numberOfRecords),
'search_domain': this._getSearchDomain(),
'with_sample': this.editableMode,
'context': {
// TODO adapt in master (see _bugfix_force_minimum_max_limit_to_16)
// in python. The `forceMinimumMaxLimitTo16` value in the
// dataset is there only in dynamic snippets whose options
// have been configured after this fix was merged.
'_bugfix_force_minimum_max_limit_to_16': !!nodeData.forceMinimumMaxLimitTo16,
},
}, this._getRpcParameters()),
});
this.data = filterFragments.map(Markup);
......
......@@ -64,6 +64,9 @@ const dynamicSnippetOptions = options.Class.extend({
if (numberOfElementsSmallDevices > numberOfRecords) {
dataSet.numberOfElementsSmallDevices = numberOfRecords;
}
// TODO adapt in master
dataSet.forceMinimumMaxLimitTo16 = '1';
}
},
......
......@@ -23,13 +23,13 @@
<field name="name">Latest Blog Posts</field>
<field name="filter_id" ref="website_blog.dynamic_snippet_latest_blog_post_filter"/>
<field name="field_names">name,teaser,subtitle</field>
<field name="limit" eval="6"/>
<field name="limit" eval="16"/>
</record>
<record id="dynamic_filter_most_viewed_blog_posts" model="website.snippet.filter">
<field name="name">Most Viewed Blog Posts</field>
<field name="filter_id" ref="website_blog.dynamic_snippet_most_viewed_blog_post_filter"/>
<field name="field_names">name,teaser,subtitle</field>
<field name="limit" eval="6"/>
<field name="limit" eval="16"/>
</record>
</data>
</odoo>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment