fix: Failing search util import and patch
- Use simple function import instead of global variable to check if field is valid to index - Commit after every 20 items in patch to create web items from items
This commit is contained in:
parent
bbcbcf7a20
commit
e2b9a38f28
@ -7,7 +7,7 @@ from frappe.utils import comma_and, flt
|
|||||||
from frappe import _, msgprint
|
from frappe import _, msgprint
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import unique
|
from frappe.utils import unique
|
||||||
from erpnext.e_commerce.redisearch import create_website_items_index, ALLOWED_INDEXABLE_FIELDS_SET, is_search_module_loaded
|
from erpnext.e_commerce.redisearch import create_website_items_index, get_indexable_web_fields, is_search_module_loaded
|
||||||
|
|
||||||
class ShoppingCartSetupError(frappe.ValidationError): pass
|
class ShoppingCartSetupError(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -57,8 +57,10 @@ class ECommerceSettings(Document):
|
|||||||
fields = unique(fields.strip(',').split(',')) # Remove extra ',' and remove duplicates
|
fields = unique(fields.strip(',').split(',')) # Remove extra ',' and remove duplicates
|
||||||
|
|
||||||
# All fields should be indexable
|
# All fields should be indexable
|
||||||
if not (set(fields).issubset(ALLOWED_INDEXABLE_FIELDS_SET)):
|
allowed_indexable_fields = get_indexable_web_fields()
|
||||||
invalid_fields = list(set(fields).difference(ALLOWED_INDEXABLE_FIELDS_SET))
|
|
||||||
|
if not (set(fields).issubset(allowed_indexable_fields)):
|
||||||
|
invalid_fields = list(set(fields).difference(allowed_indexable_fields))
|
||||||
num_invalid_fields = len(invalid_fields)
|
num_invalid_fields = len(invalid_fields)
|
||||||
invalid_fields = comma_and(invalid_fields)
|
invalid_fields = comma_and(invalid_fields)
|
||||||
|
|
||||||
|
@ -19,9 +19,6 @@ def get_indexable_web_fields():
|
|||||||
|
|
||||||
return [df.fieldname for df in valid_fields]
|
return [df.fieldname for df in valid_fields]
|
||||||
|
|
||||||
ALLOWED_INDEXABLE_FIELDS_SET = get_indexable_web_fields()
|
|
||||||
|
|
||||||
|
|
||||||
def is_search_module_loaded():
|
def is_search_module_loaded():
|
||||||
cache = frappe.cache()
|
cache = frappe.cache()
|
||||||
out = cache.execute_command('MODULE LIST')
|
out = cache.execute_command('MODULE LIST')
|
||||||
|
@ -13,12 +13,12 @@ def execute():
|
|||||||
item_table_fields = frappe.db.sql("desc `tabItem`", 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]
|
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
|
# prepare fields to query from Item, check if the web field exists in Item master
|
||||||
web_query_fields = []
|
web_query_fields = []
|
||||||
for field in web_fields_to_map:
|
for web_field in web_fields_to_map:
|
||||||
if field in item_table_fields:
|
if web_field in item_table_fields:
|
||||||
web_query_fields.append(field)
|
web_query_fields.append(web_field)
|
||||||
item_fields.append(field)
|
item_fields.append(web_field)
|
||||||
|
|
||||||
# check if the filter fields exist in Item master
|
# check if the filter fields exist in Item master
|
||||||
or_filters = {}
|
or_filters = {}
|
||||||
@ -37,6 +37,7 @@ def execute():
|
|||||||
or_filters=or_filters
|
or_filters=or_filters
|
||||||
)
|
)
|
||||||
|
|
||||||
|
count = 0
|
||||||
for item in items:
|
for item in items:
|
||||||
if frappe.db.exists("Website Item", {"item_code": item.item_code}):
|
if frappe.db.exists("Website Item", {"item_code": item.item_code}):
|
||||||
continue
|
continue
|
||||||
@ -59,5 +60,9 @@ def execute():
|
|||||||
parent = '{web_item}'
|
parent = '{web_item}'
|
||||||
where
|
where
|
||||||
parenttype = 'Item'
|
parenttype = 'Item'
|
||||||
and parent = '{item}'
|
and parent = '{item_code}'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
if count % 20 == 0: # commit after every 20 items
|
||||||
|
frappe.db.commit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user