From 1a079ca19ccac0b29dc89650b46e59feb3067669 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 22 Jun 2012 12:16:03 +0530 Subject: [PATCH] Error fixed in new report: sort by child table column --- js/wn/views/reportview.js | 10 +++++++--- py/webnotes/widgets/doclistview.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/js/wn/views/reportview.js b/js/wn/views/reportview.js index c2201fc3c3..7c20d57b46 100644 --- a/js/wn/views/reportview.js +++ b/js/wn/views/reportview.js @@ -192,17 +192,21 @@ wn.views.ReportView = wn.ui.Listing.extend({ get_order_by: function() { // first - var order_by = this.get_full_column_name([this.sort_by_select.val()]) + var order_by = this.get_selected_table_and_column(this.sort_by_select) + ' ' + this.sort_order_select.val() - + // second if(this.sort_by_next_select.val()) { - order_by += ', ' + this.get_full_column_name([this.sort_by_next_select.val()]) + order_by += ', ' + this.get_selected_table_and_column(this.sort_by_next_select) + ' ' + this.sort_order_next_select.val() } return order_by; }, + get_selected_table_and_column: function($select) { + return this.get_full_column_name([$select.val(), + $select.find('option:selected').attr('table')]) + }, // get table_name.column_name get_full_column_name: function(v) { diff --git a/py/webnotes/widgets/doclistview.py b/py/webnotes/widgets/doclistview.py index f1d9df43a5..d55801fa9a 100644 --- a/py/webnotes/widgets/doclistview.py +++ b/py/webnotes/widgets/doclistview.py @@ -55,8 +55,10 @@ def get(arg=None): data['tables'] = ', '.join(tables) data['conditions'] = ' and '.join(conditions) data['fields'] = ', '.join(fields) + if not data.get('order_by'): data['order_by'] = tables[0] + '.modified desc' + check_sort_by_table(data.get('order_by'), tables) add_limit(data) @@ -64,6 +66,15 @@ def get(arg=None): order by %(order_by)s %(limit)s""" % data return webnotes.conn.sql(query, as_dict=1) +def check_sort_by_table(sort_by, tables): + """check atleast 1 column selected from the sort by table """ + tbl = sort_by.split('.')[0] + if tbl not in tables: + if tbl.startswith('`'): + tbl = tbl[4:-1] + webnotes.msgprint("Please select atleast 1 column from '%s' to sort"\ + % tbl, raise_exception=1) + def run_custom_query(data): """run custom query""" query = data['query']