Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecommerce): throw invalid doctype error in shop by category (backport #33901) #34017

Merged
Merged
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
49 changes: 22 additions & 27 deletions erpnext/www/shop-by-category/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,31 @@ def get_tabs(categories):
return tab_values


def get_category_records(categories):
def get_category_records(categories: list):
categorical_data = {}
for category in categories:
if category == "item_group":
categorical_data["item_group"] = frappe.db.sql(
"""
Select
name, parent_item_group, is_group, image, route
from
`tabItem Group`
where
parent_item_group = 'All Item Groups'
and show_in_website = 1
""",
as_dict=1,

for c in categories:
if c == "item_group":
categorical_data["item_group"] = frappe.db.get_all(
"Item Group",
filters={"parent_item_group": "All Item Groups", "show_in_website": 1},
fields=["name", "parent_item_group", "is_group", "image", "route"],
)
else:
doctype = frappe.unscrub(category)
fields = ["name"]
if frappe.get_meta(doctype, cached=True).get_field("image"):

continue

doctype = frappe.unscrub(c)
fields = ["name"]

try:
meta = frappe.get_meta(doctype, cached=True)
if meta.get_field("image"):
fields += ["image"]

categorical_data[category] = frappe.db.sql(
f"""
Select
{",".join(fields)}
from
`tab{doctype}`
""",
as_dict=1,
)
data = frappe.db.get_all(doctype, fields=fields)
categorical_data[c] = data
except BaseException:
frappe.throw(_("DocType {} not found").format(doctype))
continue

return categorical_data