From 550d2935bdf4e9b85f26f29aef4f45c91c3f0c4c Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 13 Oct 2020 09:10:58 +0000 Subject: [PATCH] [IMP] website: support generic website for dynamic snippet filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). https://github.com/odoo/odoo/pull/59831 task-2355369 closes odoo/odoo#59831 Signed-off-by: Jérémy Kersten (jke) --- addons/website/controllers/main.py | 7 +++++++ addons/website/data/website_data.xml | 1 - addons/website/models/website_snippet_filter.py | 4 ++-- .../static/src/snippets/s_dynamic_snippet/options.js | 9 +-------- addons/website_sale/data/data.xml | 1 - 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index e0cab93db9a..8601eb9e03b 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -276,6 +276,13 @@ class Website(Home): ) 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 diff --git a/addons/website/data/website_data.xml b/addons/website/data/website_data.xml index dc477e723f6..5bcbc10e10f 100644 --- a/addons/website/data/website_data.xml +++ b/addons/website/data/website_data.xml @@ -769,7 +769,6 @@ Countries - Multi-website diff --git a/addons/website/models/website_snippet_filter.py b/addons/website/models/website_snippet_filter.py index 6613a80ff45..f9dc876338f 100644 --- a/addons/website/models/website_snippet_filter.py +++ b/addons/website/models/website_snippet_filter.py @@ -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): @@ -51,7 +51,7 @@ class WebsiteSnippetFilter(models.Model): 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) diff --git a/addons/website/static/src/snippets/s_dynamic_snippet/options.js b/addons/website/static/src/snippets/s_dynamic_snippet/options.js index 4c713703eb9..eb80fba1b42 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet/options.js +++ b/addons/website/static/src/snippets/s_dynamic_snippet/options.js @@ -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. diff --git a/addons/website_sale/data/data.xml b/addons/website_sale/data/data.xml index c3e23f32161..dcc14f49ecd 100644 --- a/addons/website_sale/data/data.xml +++ b/addons/website_sale/data/data.xml @@ -102,7 +102,6 @@ response = res_products display_name,description_sale,image_512,list_price Products - sale.order