summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNasreddin (bon) <bon@odoo.com>2021-01-21 10:40:54 +0000
committerNasreddin (bon) <bon@odoo.com>2021-01-22 11:22:12 +0000
commite452d30f739db39a088248a3109c8c49cff9d49f (patch)
treee6c2b9c75d0d5ad077d7646681667ae8f56d7011
parenta27907e27fb99a523c7b2d58544c36073640511c (diff)
[FIX] website: Warning message on website if dynamic snippet category deleted
Issue - Install "Ecommerce" app - Go to 'Shop' page and edit it - Add a "Dynamic Products" block - Click on it to edit it : - Select any template - Select `Desks` as product category - Save - Go to "Website -> Configuration -> eCommerce Categories" - Delete the "Desks" category - Go back to Shop page Error : "Record does not exist or has been deleted". Cause The search domain is looking for child categories of dataset.productCategoryId (who does not exist anymore in the above case). `child_of` do a browse() to fetch the records, and therefore generate an error if category not found. Solution Log warning message if unexptected domain and return empty records set instead. This commit also reverts commit 0de069b8ca9fb005ba5b076984f5677de25889ee that generated the issue. opw-2440917 closes odoo/odoo#64847 Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com>
-rw-r--r--addons/website/models/website_snippet_filter.py38
-rw-r--r--addons/website/static/src/snippets/s_dynamic_snippet/000.js6
-rw-r--r--addons/website_sale/static/src/snippets/s_dynamic_snippet_products/000.js24
3 files changed, 30 insertions, 38 deletions
diff --git a/addons/website/models/website_snippet_filter.py b/addons/website/models/website_snippet_filter.py
index 5af610791b7..842cdfec372 100644
--- a/addons/website/models/website_snippet_filter.py
+++ b/addons/website/models/website_snippet_filter.py
@@ -3,10 +3,13 @@
from ast import literal_eval
from collections import OrderedDict
from odoo import models, fields, api, _
-from odoo.exceptions import ValidationError
+from odoo.exceptions import ValidationError, MissingError
from odoo.osv import expression
from odoo.tools import html_escape as escape
from lxml import etree as ET
+import logging
+
+_logger = logging.getLogger(__name__)
class WebsiteSnippetFilter(models.Model):
@@ -70,20 +73,27 @@ class WebsiteSnippetFilter(models.Model):
domain = expression.AND([domain, [('is_published', '=', True)]])
if search_domain:
domain = expression.AND([domain, search_domain])
-
- records = self.env[filter_sudo.model_id].search(
- domain,
- order=','.join(literal_eval(filter_sudo.sort)) or None,
- limit=limit
- )
- return self._filter_records_to_dict_values(records)
+ try:
+ records = self.env[filter_sudo.model_id].search(
+ domain,
+ order=','.join(literal_eval(filter_sudo.sort)) or None,
+ limit=limit
+ )
+ return self._filter_records_to_dict_values(records)
+ except MissingError:
+ _logger.warning("The provided domain %s in 'ir.filters' generated a MissingError in '%s'", domain, self._name)
+ return []
elif self.action_server_id:
- return self.action_server_id.with_context(
- dynamic_filter=self,
- limit=limit,
- search_domain=search_domain,
- get_rendering_data_structure=self._get_rendering_data_structure,
- ).sudo().run()
+ try:
+ return self.action_server_id.with_context(
+ dynamic_filter=self,
+ limit=limit,
+ search_domain=search_domain,
+ get_rendering_data_structure=self._get_rendering_data_structure,
+ ).sudo().run()
+ except MissingError:
+ _logger.warning("The provided domain %s in 'ir.actions.server' generated a MissingError in '%s'", search_domain, self._name)
+ return []
@api.model
def _get_rendering_data_structure(self):
diff --git a/addons/website/static/src/snippets/s_dynamic_snippet/000.js b/addons/website/static/src/snippets/s_dynamic_snippet/000.js
index 46b10ea0dc9..71b551738b5 100644
--- a/addons/website/static/src/snippets/s_dynamic_snippet/000.js
+++ b/addons/website/static/src/snippets/s_dynamic_snippet/000.js
@@ -94,14 +94,14 @@ const DynamicSnippet = publicWidget.Widget.extend({
* domain if needed.
* @private
*/
- _getSearchDomain: async function () {
+ _getSearchDomain: function () {
return [];
},
/**
* Fetches the data.
* @private
*/
- _fetchData: async function () {
+ _fetchData: function () {
if (this._isConfigComplete()) {
return this._rpc(
{
@@ -110,7 +110,7 @@ const DynamicSnippet = publicWidget.Widget.extend({
'filter_id': parseInt(this.$el.get(0).dataset.filterId),
'template_key': this.$el.get(0).dataset.templateKey,
'limit': parseInt(this.$el.get(0).dataset.numberOfRecords),
- 'search_domain': await this._getSearchDomain()
+ 'search_domain': this._getSearchDomain()
},
})
.then(
diff --git a/addons/website_sale/static/src/snippets/s_dynamic_snippet_products/000.js b/addons/website_sale/static/src/snippets/s_dynamic_snippet_products/000.js
index 44225f83928..3763593f98f 100644
--- a/addons/website_sale/static/src/snippets/s_dynamic_snippet_products/000.js
+++ b/addons/website_sale/static/src/snippets/s_dynamic_snippet_products/000.js
@@ -14,18 +14,6 @@ const DynamicSnippetProducts = DynamicSnippetCarousel.extend({
//--------------------------------------------------------------------------
/**
- * Check product category exist.
- * @private
- * @returns {Promise}
- */
- _checkCategoryExist: async function (productCategoryId) {
- return this._rpc({
- model: 'product.public.category',
- method: 'search_count',
- args: [[['id', '=', productCategoryId]]],
- }).then(nb => nb > 0);
- },
- /**
* Method to be overridden in child components if additional configuration elements
* are required in order to fetch data.
* @override
@@ -40,15 +28,9 @@ const DynamicSnippetProducts = DynamicSnippetCarousel.extend({
* @override
* @private
*/
- _getSearchDomain: async function () {
- const searchDomain = await this._super.apply(this, arguments);
- const productCategoryId = parseInt(this.$el.get(0).dataset.productCategoryId);
- const categoryExist = await this._checkCategoryExist(productCategoryId);
- if (categoryExist) {
- searchDomain.push(['public_categ_ids', 'child_of', productCategoryId]);
- } else {
- searchDomain.push([0, '=', 1]);
- }
+ _getSearchDomain: function () {
+ const searchDomain = this._super.apply(this, arguments);
+ searchDomain.push(['public_categ_ids', 'child_of', parseInt(this.$el.get(0).dataset.productCategoryId)]);
return searchDomain;
},