From 681ada9aaf4ac4b05624271bc110108c3b8d62b6 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 18 May 2021 15:13:33 +0530 Subject: [PATCH] fix: Patch fix for fresh installs - minor sider fix - patch fix for fresh installs --- erpnext/patches/v13_0/create_website_items.py | 50 +++++++++++++------ .../make_homepage_products_website_items.py | 1 + .../v13_0/populate_e_commerce_settings.py | 2 + .../item_variant_settings.js | 2 +- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/erpnext/patches/v13_0/create_website_items.py b/erpnext/patches/v13_0/create_website_items.py index a3b07517f54..2e1f3052c1f 100644 --- a/erpnext/patches/v13_0/create_website_items.py +++ b/erpnext/patches/v13_0/create_website_items.py @@ -7,20 +7,37 @@ def execute(): frappe.reload_doc("e_commerce", "doctype", "website_item") frappe.reload_doc("stock", "doctype", "item") - web_fields_to_map = ["route", "slideshow", "website_image", "website_image_alt", + item_fields = ["item_code", "item_name", "item_group", "stock_uom", "brand", "image", + "has_variants", "variant_of", "description", "weightage"] + web_fields_to_map = ["route", "slideshow", "website_image_alt", "website_warehouse", "web_long_description", "website_content"] - items = frappe.db.sql(""" - Select - item_code, item_name, item_group, stock_uom, brand, image, - has_variants, variant_of, description, weightage, - route, slideshow, website_image_alt, - website_warehouse, web_long_description, website_content - from - `tabItem` - where - show_in_website = 1 - or show_variant_in_website = 1""", as_dict=1) + item_table_fields = frappe.db.sql("desc `tabItem`", as_dict=1) + item_table_fields = [d.get('Field') for d in item_table_fields] + + # prepare fields to query from Item, check if the field exists in Item master + web_query_fields = [] + for field in web_fields_to_map: + if field in item_table_fields: + web_query_fields.append(field) + item_fields.append(field) + + # check if the filter fields exist in Item master + or_filters = {} + for field in ["show_in_website", "show_variant_in_website"]: + if field in item_table_fields: + or_filters[field] = 1 + + if not web_query_fields or not or_filters: + # web fields to map are not present in Item master schema + # most likely a fresh installation that doesnt need this patch + return + + items = frappe.db.get_all( + "Item", + fields=item_fields, + or_filters=or_filters + ) for item in items: if frappe.db.exists("Website Item", {"item_code": item.item_code}): @@ -34,12 +51,15 @@ def execute(): website_item.save() # move Website Item Group & Website Specification table to Website Item - for doc in ("Website Item Group", "Item Website Specification"): - frappe.db.sql("""Update `tab{doctype}` + for doctype in ("Website Item Group", "Item Website Specification"): + web_item, item = website_item.name, item.item_code + frappe.db.sql(f""" + Update `tab{doctype}` set parenttype = 'Website Item', parent = '{web_item}' where parenttype = 'Item' and parent = '{item}' - """.format(doctype=doc, web_item=website_item.name, item=item.item_code)) \ No newline at end of file + """ + ) \ No newline at end of file diff --git a/erpnext/patches/v13_0/make_homepage_products_website_items.py b/erpnext/patches/v13_0/make_homepage_products_website_items.py index 8b51cad6411..8be5875b78d 100644 --- a/erpnext/patches/v13_0/make_homepage_products_website_items.py +++ b/erpnext/patches/v13_0/make_homepage_products_website_items.py @@ -11,4 +11,5 @@ def execute(): row.item_code = web_item + homepage.flags.ignore_mandatory = True homepage.save() \ No newline at end of file diff --git a/erpnext/patches/v13_0/populate_e_commerce_settings.py b/erpnext/patches/v13_0/populate_e_commerce_settings.py index 19f91ef1e2a..5241caed9f7 100644 --- a/erpnext/patches/v13_0/populate_e_commerce_settings.py +++ b/erpnext/patches/v13_0/populate_e_commerce_settings.py @@ -4,6 +4,8 @@ from frappe.utils import cint def execute(): frappe.reload_doc("e_commerce", "doctype", "e_commerce_settings") + frappe.reload_doc("portal", "doctype", "website_filter_field") + frappe.reload_doc("portal", "doctype", "website_attribute") products_settings_fields = [ "hide_variants", "home_page_is_products", "products_per_page", diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js index 2afa9109a7f..cb9abc08e25 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js @@ -5,7 +5,7 @@ frappe.ui.form.on('Item Variant Settings', { setup: function(frm) { const allow_fields = []; const exclude_fields = ["naming_series", "item_code", "item_name", "published_in_website", - "opening_stock", "variant_of", "valuation_rate"]; + "opening_stock", "variant_of", "valuation_rate"]; frappe.model.with_doctype('Item', () => { frappe.get_meta('Item').fields.forEach(d => {