You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

report_cookbook.txt 3.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Report Cookbook
  2. ===============
  3. Standard patterns used to customize reports
  4. Modify Report Filters (Client)
  5. ------------------------------
  6. Filters can be modified declaring the customize_filters method::
  7. report.customize_filters = function() {
  8. this.hide_all_filters();
  9. // show these filters only
  10. this.filter_fields_dict['GL Entry'+FILTER_SEP +'From Posting Date'].df.filter_hide = 0;
  11. this.filter_fields_dict['GL Entry'+FILTER_SEP +'To Posting Date'].df.filter_hide = 0;
  12. this.filter_fields_dict['GL Entry'+FILTER_SEP +'Account'].df.filter_hide = 0;
  13. // add new filters
  14. this.add_filter({fieldname:'aging_based_on', label:'Aging Based On', fieldtype:'Select', options:NEWLINE+'Transaction Date'+NEWLINE+'Aging Date'+NEWLINE+'Due Date',ignore : 1, parent:'Receivable Voucher', report_default:'Aging Date'});
  15. this.add_filter({fieldname:'range_1', label:'Range 1', fieldtype:'Data', ignore : 1, parent:'GL Entry'});
  16. // set default filters
  17. this.filter_fields_dict['GL Entry'+FILTER_SEP +'From Posting Date'].df['report_default']=sys_defaults.year_start_date;
  18. this.filter_fields_dict['GL Entry'+FILTER_SEP +'To Posting Date'].df['report_default']=dateutil.obj_to_str(new Date());
  19. this.filter_fields_dict['GL Entry'+FILTER_SEP +'Company'].df['report_default']=sys_defaults.company;
  20. }
  21. Remove Paging for a Report (Client)
  22. -----------------------------------
  23. If you want the report to skip paging and show all records then you can define as follows::
  24. report.dt.set_no_limit(1);
  25. Hide Column Picker (Client)
  26. ---------------------------
  27. If you want the user to only view the set columns and hide the column picker set as follows::
  28. $dh(this.mytabs.tabs['Select Columns'])
  29. Validate fitler values (Server)
  30. -------------------------------
  31. Check if user has set valid data for the filters. This code is in the Server Side::
  32. # Check mandatory filters
  33. #------------------------------
  34. if not filter_values.get('posting_date') or not filter_values.get('posting_date1'):
  35. msgprint("Please select From Posting Date and To Posting Date in 'Set Filters' section")
  36. raise Exception
  37. else:
  38. from_date = filter_values.get('posting_date')
  39. to_date = filter_values.get('posting_date1')
  40. Append a column to the report (Server)
  41. --------------------------------------
  42. Column structure is defined in the colnames, coltypes, colwidths and coloptions lists.
  43. You can modify or append to its values::
  44. colnames.append('Total')
  45. coltypes.append('Currency')
  46. colwidths.append('200px')
  47. coloptions.append('')
  48. col_idx[d[0]] = len(colnames)-1
  49. Add data to a column (Server)
  50. -----------------------------
  51. The result is set to the list "res". You can maniupate res on the server site, before it is sent
  52. to the client
  53. Values of columns can be found by label using the dictionary col_idx::
  54. for r in res:
  55. # customer cost center
  56. terr = sql("""select t1.territory from `tabCustomer` t1, `tabAccount` t2
  57. where t1.name = t2.master_name and t2.name = '%s'""" % r[col_idx['Account']])
  58. r.append(terr and terr[0][0] or '')
  59. # get due date
  60. due_date = sql("""select due_date from `tabReceivable Voucher`
  61. where name = '%s'""" % r[col_idx['Against Voucher']])
  62. r.append(due_date and cstr(due_date[0][0]) or '')
  63. Append rows to the report (Server)
  64. ----------------------------------
  65. This example adds an extra row to the data on the server side::
  66. # Append Extra rows to RES
  67. t_row = ['' for i in range(len(colnames))]
  68. t_row[col_idx['Voucher No']] = 'Total'
  69. t_row[col_idx['Opening Amt']] = total_opening_amt
  70. t_row[col_idx['Outstanding Amt']] = total_outstanding_amt
  71. out.append(t_row)