diff options
| author | Nasreddin (bon) <bon@odoo.com> | 2021-01-05 13:56:06 +0000 |
|---|---|---|
| committer | Nasreddin (bon) <bon@odoo.com> | 2021-01-06 08:25:27 +0000 |
| commit | 0de069b8ca9fb005ba5b076984f5677de25889ee (patch) | |
| tree | d2229d2db7cdabc5c09d05632d10bcb4d0e4a2f4 /addons | |
| parent | 0024b592b2d589138f34e27c724b8d471d213a4d (diff) | |
[FIX] website,website_sale: Dynamic products isn't visible if 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
Check if dataset.productCategoryId exist before updating domain.
opw-2416231
closes odoo/odoo#64090
Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/website/static/src/snippets/s_dynamic_snippet/000.js | 6 | ||||
| -rw-r--r-- | addons/website_sale/static/src/snippets/s_dynamic_snippet_products/000.js | 26 |
2 files changed, 25 insertions, 7 deletions
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 71b551738b5..46b10ea0dc9 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: function () { + _getSearchDomain: async function () { return []; }, /** * Fetches the data. * @private */ - _fetchData: function () { + _fetchData: async 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': this._getSearchDomain() + 'search_domain': await 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 73b7d3abb02..44225f83928 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,12 +14,24 @@ 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 * @private */ - _isConfigComplete: function() { + _isConfigComplete: function () { return this._super.apply(this, arguments) && this.$el.get(0).dataset.productCategoryId !== undefined; }, /** @@ -28,9 +40,15 @@ const DynamicSnippetProducts = DynamicSnippetCarousel.extend({ * @override * @private */ - _getSearchDomain: function () { - const searchDomain = this._super.apply(this, arguments); - searchDomain.push(['public_categ_ids', 'child_of', parseInt(this.$el.get(0).dataset.productCategoryId)]); + _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]); + } return searchDomain; }, |
