From ea30ce4c511367c71ec068d48761e694745687db Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 2 Jun 2021 13:24:06 +0530 Subject: [PATCH] fix: Sider and Patch tests --- .../e_commerce_settings/e_commerce_settings.py | 12 +++++++----- erpnext/e_commerce/product_search.js | 14 +++++++------- erpnext/e_commerce/website_item_indexing.py | 4 ++-- erpnext/www/shop-by-category/index.py | 15 ++++++++------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py index 8d6cc74204..ec989a6bbb 100644 --- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py @@ -132,12 +132,14 @@ class ECommerceSettings(Document): def on_change(self): old_doc = self.get_doc_before_save() - old_fields = old_doc.search_index_fields - new_fields = self.search_index_fields - # if search index fields get changed - if not (new_fields == old_fields): - create_website_items_index() + if old_doc: + old_fields = old_doc.search_index_fields + new_fields = self.search_index_fields + + # if search index fields get changed + if not (new_fields == old_fields): + create_website_items_index() def validate_cart_settings(doc, method): frappe.get_doc("E Commerce Settings", "E Commerce Settings").run_method("validate") diff --git a/erpnext/e_commerce/product_search.js b/erpnext/e_commerce/product_search.js index 4f8b028fc1..605594b455 100644 --- a/erpnext/e_commerce/product_search.js +++ b/erpnext/e_commerce/product_search.js @@ -18,11 +18,11 @@ erpnext.ProductSearch = class { bindSearchAction() { let me = this; - this.searchBox.on("focus", (e) => { + this.searchBox.on("focus", () => { this.search_dropdown.removeClass("hidden"); }); - this.searchBox.on("focusout", (e) => { + this.searchBox.on("focusout", () => { this.search_dropdown.addClass("hidden"); }); @@ -53,7 +53,7 @@ erpnext.ProductSearch = class { query: query }, callback: (data) => { - me.populateCategoriesList(data) + me.populateCategoriesList(data); } }); } @@ -211,16 +211,16 @@ erpnext.ProductSearch = class { return; } - let html = "" - let search_results = data.message.results + let html = ""; + let search_results = data.message.results; search_results.forEach((category) => { html += `
${category.name}
`; - }) + }); this.category_container.html(html); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/erpnext/e_commerce/website_item_indexing.py b/erpnext/e_commerce/website_item_indexing.py index 32701013a5..73ab7408cc 100644 --- a/erpnext/e_commerce/website_item_indexing.py +++ b/erpnext/e_commerce/website_item_indexing.py @@ -120,7 +120,7 @@ def delete_item_from_index(website_item_doc): try: cache.delete(key) - except: + except Exception: return False delete_from_ac_dict(website_item_doc) @@ -152,7 +152,7 @@ def define_autocomplete_dictionary(): try: cache.delete(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE)) cache.delete(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE)) - except: + except Exception: return False items = frappe.get_all( diff --git a/erpnext/www/shop-by-category/index.py b/erpnext/www/shop-by-category/index.py index f94b33ea85..865a4c00ce 100644 --- a/erpnext/www/shop-by-category/index.py +++ b/erpnext/www/shop-by-category/index.py @@ -70,13 +70,14 @@ def get_category_records(categories): if frappe.get_meta(doctype, cached=True).get_field("image"): fields += ["image"] - categorical_data[category] = frappe.db.sql(f""" - Select - {",".join(fields)} - from - `tab{doctype}`""", - as_dict=1 - ) + categorical_data[category] = frappe.db.sql( + f""" + Select + {",".join(fields)} + from + `tab{doctype}` + """, + as_dict=1) return categorical_data