Skip to content

Commit

Permalink
[IMP] website: support generic website for dynamic snippet filters
Browse files Browse the repository at this point in the history
Made the website_id non mandatory on website snippet filters and adapted
the fetching route so that it interprets an unspecified website_id as
the filter being available on any website.

Before this commit website snippet filters had to be limited to one
single website.

After this commit website snippet filters can be made available on all
websites by setting their website_id to no value (this is the new
default of the pre-defined filters).

odoo#59831
task-2355369

closes odoo#59831

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
  • Loading branch information
JKE-be authored and bso-odoo committed Oct 13, 2020
1 parent 6aa8e7b commit 550d293
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
7 changes: 7 additions & 0 deletions addons/website/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def get_dynamic_filter(self, filter_id, template_key, limit=None, search_domain=
)
return dynamic_filter and dynamic_filter.render(template_key, limit, search_domain) or ''

@http.route('/website/snippet/options_filters', type='json', auth='user', website=True)
def get_dynamic_snippet_filters(self):
dynamic_filter = request.env['website.snippet.filter'].sudo().search_read(
request.website.website_domain(), ['id', 'name', 'limit']
)
return dynamic_filter

@http.route('/website/snippet/filter_templates', type='json', auth='public', website=True)
def get_dynamic_snippet_templates(self, filter_id=False):
# todo: if filter_id.model -> filter template
Expand Down
1 change: 0 additions & 1 deletion addons/website/data/website_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@
<field name="filter_id" ref="website.dynamic_snippet_country_filter"/>
<field name="limit" eval="16"/>
<field name="name">Countries</field>
<field name="website_id" ref="website.default_website"/>
</record>
<record id="group_multi_website" model="res.groups">
<field name="name">Multi-website</field>
Expand Down
4 changes: 2 additions & 2 deletions addons/website/models/website_snippet_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WebsiteSnippetFilter(models.Model):
field_names = fields.Char(help="A list of comma-separated field names", required=True)
filter_id = fields.Many2one('ir.filters', 'Filter', ondelete='cascade')
limit = fields.Integer(help='The limit is the maximum number of records retrieved', required=True)
website_id = fields.Many2one('website', string='Website', ondelete='cascade', required=True)
website_id = fields.Many2one('website', string='Website', ondelete='cascade')

@api.model
def escape_falsy_as_empty(self, s):
Expand Down Expand Up @@ -51,7 +51,7 @@ def render(self, template_key, limit, search_domain=[]):
self.ensure_one()
assert '.dynamic_filter_template_' in template_key, _("You can only use template prefixed by dynamic_filter_template_ ")

if self.env['website'].get_current_website() != self.website_id:
if self.website_id and self.env['website'].get_current_website() != self.website_id:
return ''

records = self._prepare_values(limit, search_domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ const dynamicSnippetOptions = options.Class.extend({
* @returns {Promise}
*/
_fetchDynamicFilters: function () {
return this._rpc({
model: 'website.snippet.filter',
method: 'search_read',
kwargs: {
domain: [],
fields: ['id', 'name', 'limit'],
}
});
return this._rpc({route: '/website/snippet/options_filters'});
},
/**
* Fetch dynamic filters templates.
Expand Down
1 change: 0 additions & 1 deletion addons/website_sale/data/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ response = res_products
<field name="field_names">display_name,description_sale,image_512,list_price</field>
<field name="limit" eval="16"/>
<field name="name">Products</field>
<field name="website_id" ref="website.default_website"/>
</record>
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>sale.order</value>
Expand Down

0 comments on commit 550d293

Please sign in to comment.