mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +00:00
Index patch released and doctype updated based on index
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
This patch removes wrong indexs and add proper indexes in tables
|
||||
"""
|
||||
|
||||
import webnotes
|
||||
sql = webnotes.conn.sql
|
||||
from webnotes.utils import cint, cstr
|
||||
|
||||
def create_proper_index():
|
||||
from webnotes.modules.export_module import export_to_files
|
||||
@@ -102,7 +105,7 @@ def create_proper_index():
|
||||
'File Group': ['parent_group'],
|
||||
'Maintenance Visit Detail': ['item_code', 'service_person'],
|
||||
'Support Ticket Response': [],
|
||||
'PV Detail': ['item_code', 'purchase_order', 'purchase_receipt', 'expense_head', 'cost_center'],
|
||||
'PV Detail': ['item_code', 'purchase_order', 'po_detail', 'purchase_receipt', 'pr_detail', 'expense_head', 'cost_center'],
|
||||
'Timesheet Detail': ['project_name', 'task_id', 'customer_name'],
|
||||
'Holiday List Detail': [],
|
||||
'Workflow Rule Detail': [],
|
||||
@@ -125,7 +128,7 @@ def create_proper_index():
|
||||
'Declaration Detail': [],
|
||||
'Holiday List': ['fiscal_year'],
|
||||
'Sales Person': ['lft', 'rgt', 'parent_sales_person'],
|
||||
'RV Detail': ['item_code', 'sales_order', 'delivery_note', 'cost_center', 'income_account'],
|
||||
'RV Detail': ['item_code', 'sales_order', 'so_detail', 'delivery_note', 'dn_detail', 'cost_center', 'income_account'],
|
||||
'Module Def Item': [],
|
||||
'TDS Category': [],
|
||||
'DocTrigger': [],
|
||||
@@ -264,29 +267,34 @@ def create_proper_index():
|
||||
'Print Heading': [],
|
||||
'TDS Rate Detail': ['category']
|
||||
}
|
||||
|
||||
for dt in dt_index_fields.keys():
|
||||
current_index = sql("show indexes from `tab%s`" % dt)
|
||||
sql("commit")
|
||||
exist_dt = [cstr(d[0]) for d in sql("select name from `tabDocType`")]
|
||||
|
||||
proper_index = dt_index_fields[dt]
|
||||
for dt in [d for d in dt_index_fields.keys() if d in exist_dt]:
|
||||
try:
|
||||
current_index = sql("show indexes from `tab%s`" % dt)
|
||||
|
||||
for d in current_index:
|
||||
if d[4] not in ['name', 'parent', 'parenttype']:
|
||||
if d[4] not in proper_index:
|
||||
sql("ALTER TABLE `tab%s` DROP INDEX %s" % (dt, d[4]))
|
||||
sql("start transaction")
|
||||
sql("UPDATE `tabDocField` SET search_index = 0 WHERE fieldname = '%s' AND parent = '%s'" % (d[4], dt))
|
||||
sql("commit")
|
||||
else:
|
||||
proper_index.remove(d[4])
|
||||
proper_index = dt_index_fields[dt]
|
||||
|
||||
for d in proper_index:
|
||||
sql("ALTER TABLE `tab%s` ADD INDEX ( `%s` ) " % (dt, d))
|
||||
sql("start transaction")
|
||||
sql("UPDATE `tabDocField` SET search_index = 1 WHERE fieldname = '%s' AND parent = '%s'" % (d, dt))
|
||||
sql("commit")
|
||||
for d in current_index:
|
||||
if d[4] not in ['name', 'parent', 'parenttype']:
|
||||
if d[4] not in proper_index:
|
||||
sql("ALTER TABLE `tab%s` DROP INDEX %s" % (dt, d[4]))
|
||||
sql("start transaction")
|
||||
sql("UPDATE `tabDocField` SET search_index = 0 WHERE fieldname = '%s' AND parent = '%s'" % (d[4], dt))
|
||||
sql("commit")
|
||||
else:
|
||||
proper_index.remove(d[4])
|
||||
|
||||
for d in proper_index:
|
||||
sql("ALTER TABLE `tab%s` ADD INDEX ( `%s` ) " % (dt, d))
|
||||
sql("start transaction")
|
||||
sql("UPDATE `tabDocField` SET search_index = 1 WHERE fieldname = '%s' AND parent = '%s'" % (d, dt))
|
||||
sql("commit")
|
||||
|
||||
sql("start transaction")
|
||||
dt_module = sql("select module from `tabDocType` where name = '%s'" % dt)[0][0]
|
||||
export_to_files(record_list = [['DocType', dt]], record_module = dt_module)
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
dt_module = sql("select module from `tabDocType` where name = '%s'" % dt)[0][0]
|
||||
export_to_files(record_list = [['DocType', dt]], record_module = dt_module)
|
||||
sql("commit")
|
||||
except:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user