[fix] [minor] patch for fixing report columns in defaults
This commit is contained in:
parent
d333f20ca0
commit
259208187c
@ -21,16 +21,8 @@ $.extend(cur_frm.cscript, {
|
|||||||
year_start_date: function(doc, dt, dn) {
|
year_start_date: function(doc, dt, dn) {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
wn.call({
|
year_end_date =
|
||||||
method: 'controllers.trends.get_period_date_ranges',
|
wn.datetime.add_days(wn.datetime.add_months(this.frm.doc.year_start_date, 12), -1);
|
||||||
args: {
|
this.frm.set_value("year_end_date", year_end_date);
|
||||||
period: "Yearly",
|
|
||||||
year_start_date: this.frm.doc.year_start_date
|
|
||||||
},
|
|
||||||
callback: function(r) {
|
|
||||||
if (!r.exc)
|
|
||||||
me.frm.set_value("year_end_date", r.message[0][1])
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
@ -4,6 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes import msgprint, _
|
from webnotes import msgprint, _
|
||||||
|
from webnotes.utils import getdate
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
@ -19,9 +20,15 @@ class DocType:
|
|||||||
msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
|
msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
|
||||||
Please refresh your browser for the change to take effect."""))
|
Please refresh your browser for the change to take effect."""))
|
||||||
|
|
||||||
def on_update(self):
|
def validate(self):
|
||||||
from webnotes.utils import getdate
|
year_start_end_dates = webnotes.conn.sql("""select year_start_date, year_end_date
|
||||||
|
from `tabFiscal Year` where name=%s""", (self.doc.name))
|
||||||
|
|
||||||
|
if getdate(self.doc.year_start_date) != year_start_end_dates[0][0] or getdate(self.doc.year_end_date) != year_start_end_dates[0][1]:
|
||||||
|
webnotes.throw(_("Cannot change Year Start Date and Year End Date \
|
||||||
|
once the Fiscal Year is saved."))
|
||||||
|
|
||||||
|
def on_update(self):
|
||||||
# validate year start date and year end date
|
# validate year start date and year end date
|
||||||
if getdate(self.doc.year_start_date) > getdate(self.doc.year_end_date):
|
if getdate(self.doc.year_start_date) > getdate(self.doc.year_end_date):
|
||||||
webnotes.throw(_("Year Start Date should not be greater than Year End Date"))
|
webnotes.throw(_("Year Start Date should not be greater than Year End Date"))
|
||||||
|
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_year_end_date_of_fiscal_year",
|
||||||
"patches.1311.p04_update_comments",
|
"patches.1311.p04_update_comments",
|
||||||
"patches.1311.p05_website_brand_html",
|
"patches.1311.p05_website_brand_html",
|
||||||
|
"patches.1311.p06_fix_report_columns",
|
||||||
]
|
]
|
Loading…
x
Reference in New Issue
Block a user