Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion webshop/patches/copy_custom_field_filters_to_website_item.py
Original file line number Diff line number Diff line change
@@ -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."
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions webshop/patches/populate_e_commerce_settings.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
)
16 changes: 2 additions & 14 deletions webshop/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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():
Expand Down
13 changes: 13 additions & 0 deletions webshop/webshop/utils/setup.py
Original file line number Diff line number Diff line change
@@ -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)