mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
Merge pull request #1100 from akhileshdarjee/master
[fix] [minor] patch for fixing report columns in defaults
This commit is contained in:
35
patches/1311/p06_fix_report_columns.py
Normal file
35
patches/1311/p06_fix_report_columns.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import cstr
|
||||
import json
|
||||
|
||||
def execute():
|
||||
doctypes_child_tables_map = {}
|
||||
|
||||
# Get all saved report columns
|
||||
columns = webnotes.conn.sql("""select defvalue, defkey from `tabDefaultValue` where
|
||||
defkey like '_list_settings:%'""")
|
||||
|
||||
# Make map of doctype and child tables
|
||||
for value, key in columns:
|
||||
doctype = key.split(':')[-1]
|
||||
child_tables = webnotes.conn.sql_list("""select options from `tabDocField`
|
||||
where parent=%s and fieldtype='Table'""", doctype)
|
||||
doctypes_child_tables_map.setdefault(doctype, child_tables + [doctype])
|
||||
|
||||
# If defvalue contains child doctypes then only append the column
|
||||
for value, key in columns:
|
||||
new_columns = []
|
||||
column_doctype = key.split(':')[-1]
|
||||
for child_doctype in doctypes_child_tables_map.get(column_doctype):
|
||||
for field, field_doctype in json.loads(value):
|
||||
if field_doctype == child_doctype:
|
||||
new_columns.append([field, field_doctype])
|
||||
|
||||
if new_columns:
|
||||
defkey = "_list_settings:" + column_doctype
|
||||
webnotes.conn.sql("""update `tabDefaultValue` set defvalue=%s
|
||||
where defkey=%s""" % ('%s', '%s'), (json.dumps(new_columns), defkey))
|
||||
@@ -253,4 +253,5 @@ patch_list = [
|
||||
"patches.1311.p04_update_year_end_date_of_fiscal_year",
|
||||
"patches.1311.p04_update_comments",
|
||||
"patches.1311.p05_website_brand_html",
|
||||
"patches.1311.p06_fix_report_columns",
|
||||
]
|
||||
Reference in New Issue
Block a user