[fix] [minor] patch for fixing report columns in defaults
diff --git a/accounts/doctype/fiscal_year/fiscal_year.js b/accounts/doctype/fiscal_year/fiscal_year.js
index 5cd672b..6bf7129 100644
--- a/accounts/doctype/fiscal_year/fiscal_year.js
+++ b/accounts/doctype/fiscal_year/fiscal_year.js
@@ -21,16 +21,8 @@
year_start_date: function(doc, dt, dn) {
var me = this;
- wn.call({
- method: 'controllers.trends.get_period_date_ranges',
- args: {
- 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])
- }
- });
+ year_end_date =
+ wn.datetime.add_days(wn.datetime.add_months(this.frm.doc.year_start_date, 12), -1);
+ this.frm.set_value("year_end_date", year_end_date);
},
});
\ No newline at end of file
diff --git a/accounts/doctype/fiscal_year/fiscal_year.py b/accounts/doctype/fiscal_year/fiscal_year.py
index 891c0a5..6eb5afb 100644
--- a/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/accounts/doctype/fiscal_year/fiscal_year.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes import msgprint, _
+from webnotes.utils import getdate
class DocType:
def __init__(self, d, dl):
@@ -19,9 +20,15 @@
msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
Please refresh your browser for the change to take effect."""))
- def on_update(self):
- from webnotes.utils import getdate
+ def validate(self):
+ 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
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"))
diff --git a/patches/1311/p06_fix_report_columns.py b/patches/1311/p06_fix_report_columns.py
new file mode 100644
index 0000000..3516b38
--- /dev/null
+++ b/patches/1311/p06_fix_report_columns.py
@@ -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))
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index d09cec1..7175b63 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -253,4 +253,5 @@
"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",
]
\ No newline at end of file