diff --git a/webshop/patches/copy_custom_field_filters_to_website_item.py b/webshop/patches/copy_custom_field_filters_to_website_item.py index 1f986edbf5..12157cc292 100644 --- a/webshop/patches/copy_custom_field_filters_to_website_item.py +++ b/webshop/patches/copy_custom_field_filters_to_website_item.py @@ -1,6 +1,7 @@ import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_field +from webshop.webshop.utils.setup import has_ecommerce_fields def execute(): "Add Field Filters, that are not standard fields in Website Item, as Custom Fields." @@ -41,7 +42,9 @@ def get_table_multiselect_data(docfield): return table_multiselect_data - settings = frappe.get_doc("E Commerce Settings") + settings_doctype = "E Commerce Settings" if has_ecommerce_fields() else "Webshop Settings" + + settings = frappe.get_doc(settings_doctype) if not (settings.enable_field_filters or settings.filter_fields): return diff --git a/webshop/patches/populate_e_commerce_settings.py b/webshop/patches/populate_e_commerce_settings.py index 061a981f39..f5fa326964 100644 --- a/webshop/patches/populate_e_commerce_settings.py +++ b/webshop/patches/populate_e_commerce_settings.py @@ -1,6 +1,7 @@ import frappe from frappe.utils import cint +from webshop.webshop.utils.setup import has_ecommerce_fields def execute(): frappe.reload_doc("webshop", "doctype", "webshop_settings") @@ -34,7 +35,9 @@ def execute(): "save_quotations_as_draft", ] - settings = frappe.get_doc("E Commerce Settings") + settings_doctype = "E Commerce Settings" if has_ecommerce_fields() else "Webshop Settings" + + settings = frappe.get_doc(settings_doctype) def map_into_e_commerce_settings(doctype, fields): singles = frappe.qb.DocType("Singles") @@ -63,6 +66,6 @@ def map_into_e_commerce_settings(doctype, fields): frappe.db.set_value( doctype, {"parent": "Products Settings"}, - {"parenttype": "E Commerce Settings", "parent": "E Commerce Settings"}, + {"parenttype": settings_doctype, "parent": settings_doctype}, update_modified=False, ) \ No newline at end of file diff --git a/webshop/setup/install.py b/webshop/setup/install.py index 72ed7e8fb0..bde3f0f267 100644 --- a/webshop/setup/install.py +++ b/webshop/setup/install.py @@ -4,6 +4,7 @@ from frappe import _ from frappe.custom.doctype.custom_field.custom_field import create_custom_fields +from webshop.webshop.utils.setup import has_ecommerce_fields def after_install(): run_patches() @@ -47,19 +48,6 @@ def copy_from_ecommerce_settings(): query.run() -def has_ecommerce_fields() -> bool: - table = frappe.qb.Table("tabSingles") - query = ( - frappe.qb.from_(table) - .select(table.field) - .where(table.doctype == "E Commerce Settings") - .limit(1) - ) - - data = query.run(as_dict=True) - return bool(data) - - def drop_ecommerce_settings(): frappe.delete_doc_if_exists("DocType", "E Commerce Settings", force=True) @@ -229,12 +217,12 @@ def say_thanks(): patches = [ "create_website_items", "populate_e_commerce_settings", + "add_homepage_field", "make_homepage_products_website_items", "fetch_thumbnail_in_website_items", "convert_to_website_item_in_item_card_group_template", "shopping_cart_to_ecommerce", "copy_custom_field_filters_to_website_item", - "add_homepage_field" ] def run_patches(): diff --git a/webshop/webshop/utils/setup.py b/webshop/webshop/utils/setup.py new file mode 100644 index 0000000000..0fff23160e --- /dev/null +++ b/webshop/webshop/utils/setup.py @@ -0,0 +1,13 @@ +import frappe + +def has_ecommerce_fields() -> bool: + table = frappe.qb.Table("tabSingles") + query = ( + frappe.qb.from_(table) + .select(table.field) + .where(table.doctype == "E Commerce Settings") + .limit(1) + ) + + data = query.run(as_dict=True) + return bool(data) \ No newline at end of file