From 9bffdc95da7a8c30130c7a65edfe03911ad58534 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Wed, 22 Jun 2011 12:48:51 +0530 Subject: [PATCH] trial bal: added filter to select what to show(group/ledger/both) and optionto show/hide zero balance --- .../trial_balance/trial_balance.js | 54 ++++++++++++------- .../trial_balance/trial_balance.py | 23 ++++---- .../trial_balance/trial_balance.sql | 1 - .../trial_balance/trial_balance.txt | 12 ++--- 4 files changed, 50 insertions(+), 40 deletions(-) delete mode 100644 accounts/search_criteria/trial_balance/trial_balance.sql diff --git a/accounts/search_criteria/trial_balance/trial_balance.js b/accounts/search_criteria/trial_balance/trial_balance.js index 5fd60493d8..7cfe4598f6 100644 --- a/accounts/search_criteria/trial_balance/trial_balance.js +++ b/accounts/search_criteria/trial_balance/trial_balance.js @@ -1,31 +1,45 @@ report.customize_filters = function() { - this.hide_all_filters(); + this.hide_all_filters(); - this.add_filter({fieldname:'show_group_balance', label:'Show Group Balance', fieldtype:'Select', options:'Yes'+NEWLINE+'No',ignore : 1, parent:'Account', 'report_default':'No','in_first_page':1}); - this.add_filter({fieldname:'transaction_date', label:'Date', fieldtype:'Date', options:'',ignore : 1, parent:'Account', 'in_first_page':1}); + this.add_filter({fieldname:'show_group_ledger', label:'Show Group/Ledger', fieldtype:'Select', options:'Only Groups'+NEWLINE+'Only Ledgers'+NEWLINE+'Both But Without Group Balance'+NEWLINE+'Both With Balance',ignore : 1, parent:'Account', 'report_default':'Both With Balance','in_first_page':1,single_select:1}); + + this.add_filter({fieldname:'show_zero_balance', label:'Show Zero Balance', fieldtype:'Select', options:'Yes'+NEWLINE+'No',ignore : 1, parent:'Account', 'report_default':'Yes','in_first_page':1,single_select:1}); + + this.add_filter({fieldname:'transaction_date', label:'Date', fieldtype:'Date', options:'',ignore : 1, parent:'Account', 'in_first_page':1}); - this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df.filter_hide = 0; - this.filter_fields_dict['Account'+FILTER_SEP +'From Date'].df.filter_hide = 0; - this.filter_fields_dict['Account'+FILTER_SEP +'To Date'].df.filter_hide = 0; + this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df.filter_hide = 0; + this.filter_fields_dict['Account'+FILTER_SEP +'From Date'].df.filter_hide = 0; + this.filter_fields_dict['Account'+FILTER_SEP +'To Date'].df.filter_hide = 0; - this.filter_fields_dict['Account'+FILTER_SEP +'From Date'].df['report_default'] = sys_defaults.year_start_date; - this.filter_fields_dict['Account'+FILTER_SEP +'To Date'].df['report_default'] = dateutil.obj_to_str(new Date()); - this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company; + this.filter_fields_dict['Account'+FILTER_SEP +'From Date'].df['report_default'] = sys_defaults.year_start_date; + this.filter_fields_dict['Account'+FILTER_SEP +'To Date'].df['report_default'] = dateutil.obj_to_str(new Date()); + this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df['report_default'] = sys_defaults.company; - this.filter_fields_dict['Account'+FILTER_SEP +'From Date'].df.in_first_page = 1; - this.filter_fields_dict['Account'+FILTER_SEP +'To Date'].df.in_first_page = 1; - this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df.in_first_page = 1; + this.filter_fields_dict['Account'+FILTER_SEP +'From Date'].df.in_first_page = 1; + this.filter_fields_dict['Account'+FILTER_SEP +'To Date'].df.in_first_page = 1; + this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df.in_first_page = 1; - this.dt.set_no_limit(1); + this.dt.set_no_limit(1); } report.aftertableprint = function(t) { - $yt(t,'*',1,{whiteSpace:'pre'}); + $yt(t,'*',1,{whiteSpace:'pre'}); } -if(window.location.href.search('/v170/') != -1) { - this.mytabs.items['More Filters'].hide(); - this.mytabs.items['Select Columns'].hide(); -} else { - $dh(this.mytabs.tabs['More Filters']); - $dh(this.mytabs.tabs['Select Columns']); + +$dh(this.mytabs.tabs['More Filters']); +$dh(this.mytabs.tabs['Select Columns']); + +report.get_query = function() { + var g_or_l = this.get_filter('Account', 'Show Group/Ledger').get_value(); + var comp = this.get_filter('Account', 'Company').get_value(); + + if (g_or_l == 'Only Ledgers') { + var q = "SELECT name FROM tabAccount WHERE group_or_ledger = 'Ledger' and company = '" + comp + "' and docstatus != 2 ORDER BY lft"; + } else if (g_or_l == 'Only Groups') { + var q = "SELECT CONCAT( REPEAT(' ', COUNT(parent.name) - 1), node.name) AS name FROM tabAccount AS node,tabAccount AS parent WHERE (node.lft BETWEEN parent.lft AND parent.rgt) and node.group_or_ledger = 'Group' and node.company = '" + comp + "' and node.docstatus != 2 GROUP BY node.name ORDER BY node.lft"; + } else { + var q = "SELECT CONCAT( REPEAT(' ', COUNT(parent.name) - 1), node.name) AS name FROM tabAccount AS node,tabAccount AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt and node.company = '" + comp + "' and node.docstatus != 2 GROUP BY node.name ORDER BY node.lft"; + } + + return q; } diff --git a/accounts/search_criteria/trial_balance/trial_balance.py b/accounts/search_criteria/trial_balance/trial_balance.py index a4c3f827ff..fb168e57af 100644 --- a/accounts/search_criteria/trial_balance/trial_balance.py +++ b/accounts/search_criteria/trial_balance/trial_balance.py @@ -1,4 +1,3 @@ - # Columns #---------- cl = [['Account','Data', '200px'],['Debit/Credit', 'Data', '100px'], ['Group/Ledger', 'Data', '100px'], ['Is PL Account', 'Data', '100px'], ['Opening','Data', '100px'],['Debit', 'Data', '100px'],['Credit', 'Data', '100px'],['Closing', 'Data', '100px']] @@ -42,7 +41,7 @@ total_debit, total_credit = 0,0 glc = get_obj('GL Control') # Main logic -# ---------------- +# ---------- for r in res: # Fetch account details acc = r[col_idx['Account']].strip() @@ -51,11 +50,11 @@ for r in res: r.append(acc_det[0][4]) r.append(acc_det[0][1]) - # if group, check user input - if acc_det[0][4] == 'Group' and filter_values.get('show_group_balance') == 'No': + #if shows group and ledger both but without group balance + if filter_values.get('show_group_ledger') == 'Both But Without Group Balance' and acc_det[0][4] == 'Group': for i in range(4): r.append('') - continue + continue # opening balance if from_date_year: @@ -70,7 +69,7 @@ for r in res: if from_date_year == to_date_year: debit = flt(debit_on_todate) - flt(debit_on_fromdate) credit = flt(credit_on_todate) - flt(credit_on_fromdate) - else: # may be wrong + else: # if from date is start date of the year debit = flt(debit_on_todate) credit = flt(credit_on_todate) @@ -89,20 +88,18 @@ for r in res: r.append(flt(closing)) -# Remove accounts if closing bal = debit = credit = 0 -# ----------------------------------------------------- - out =[] for r in res: - if r[col_idx['Opening']] or r[col_idx['Debit']] or r[col_idx['Credit']] or r[col_idx['Closing']]: + # Remove accounts if opening bal = debit = credit = closing bal = 0 + # ------------------------------------------------------------------ + if filter_values.get('show_zero_balance') != 'No': out.append(r) - - if r[col_idx['Group/Ledger']] == 'Group' and filter_values.get('show_group_balance') == 'No': + elif r[col_idx['Opening']] or r[col_idx['Debit']] or r[col_idx['Credit']] or r[col_idx['Closing']] or (r[col_idx['Group/Ledger']] == 'Group' and filter_values.get('show_group_ledger') == 'Both But Without Group Balance'): out.append(r) # Total Debit / Credit # -------------------------- -if filter_values.get('show_group_balance') == 'No': +if filter_values.get('show_group_ledger') in ['Only Ledgers', 'Both But Without Group Balance']: t_row = ['' for i in range(len(colnames))] t_row[col_idx['Account']] = 'Total' t_row[col_idx['Debit']] = total_debit diff --git a/accounts/search_criteria/trial_balance/trial_balance.sql b/accounts/search_criteria/trial_balance/trial_balance.sql deleted file mode 100644 index 1f256ebf55..0000000000 --- a/accounts/search_criteria/trial_balance/trial_balance.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT CONCAT( REPEAT(' ', COUNT(parent.name) - 1), node.name) AS name FROM tabAccount AS node,tabAccount AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt and node.company = '%(company)s' and node.docstatus != 2 GROUP BY node.name ORDER BY node.lft diff --git a/accounts/search_criteria/trial_balance/trial_balance.txt b/accounts/search_criteria/trial_balance/trial_balance.txt index 308d24fa96..a29c5a2c1d 100644 --- a/accounts/search_criteria/trial_balance/trial_balance.txt +++ b/accounts/search_criteria/trial_balance/trial_balance.txt @@ -1,24 +1,24 @@ [ { 'add_col': None, - 'add_cond': '', + 'add_cond': None, 'add_tab': None, 'columns': 'Account\x01ID', - 'creation': '2010-12-14 10:33:08', + 'creation': '2010-12-14 10:23:28', 'criteria_name': 'Trial Balance', - 'custom_query': None, + 'custom_query': '', 'description': 'Trial Balance', 'dis_filters': 'transaction_date', 'disabled': None, 'doc_type': 'Account', 'docstatus': 0, 'doctype': 'Search Criteria', - 'filters': "{'Account\x01Group or Ledger':'Ledger','Account\x01Is PL Account':'','Account\x01Account Type':'','Account\x01Show Group Balance':''}", + 'filters': "{'Account\x01Is PL Account':'','Account\x01Account Type':''}", 'graph_series': None, 'graph_values': None, 'group_by': None, 'idx': None, - 'modified': '2010-11-25 12:25:28', + 'modified': '2011-06-22 12:29:43', 'modified_by': 'Administrator', 'module': 'Accounts', 'name': 'trial_balance', @@ -34,4 +34,4 @@ 'sort_order': 'DESC', 'standard': 'Yes' } -] \ No newline at end of file +]