選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

248 行
7.1 KiB

  1. Report Builder
  2. ==============
  3. The Report Builder structure is as follows::
  4. +- Report Builder Container
  5. |
  6. +- Report Builder (DocType 1)
  7. | |
  8. | +- DataTable (Output grid)
  9. |
  10. +- Report Bulder (DocType 2)
  11. |
  12. ..
  13. ..
  14. Search Criteria
  15. ---------------
  16. Reports with selected columns and filters can be saved by clicking on the "Save" link on the top bar of
  17. the Report Builder. The report is saved in a record called `Search Criteria`. Client-side and server-side
  18. scripts can be plugged in by using the `Search Criteria`.
  19. Customizing Filters
  20. -------------------
  21. Customizing of filters is done by declaring the `report.customize_filters` method in the client side of the
  22. `Search Critiera`.
  23. * Individual filters in the Report Builder can be accessed by the `filter_fields_dict`. The filter_fields_dict
  24. returns a :class:`_f.Field` object.
  25. * Filters can be added by using the `add_filter` method
  26. * The filters can be customized by setting properties on the `df` dictionary of the field object.
  27. Custom properties of filter fields are
  28. * `filter_hide` - Hide this standard filter
  29. * `in_first_page` - Show this filter in the first page
  30. * `report_default` - Set the value as the default for the filter
  31. * `insert_before` - Insert this filter before the fieldname identified by this property
  32. * `ignore` - Ignore this field while building the query
  33. * `custom` - A property that indicates whether the filter is a custom filter (not a standard field)
  34. Example::
  35. report.customize_filters = function() {
  36. // hide exiting filters
  37. this.hide_all_filters();
  38. // add a new filter
  39. this.add_filter({fieldname:'show_group_balance', label:'Show Group Balance', fieldtype:'Select', options:NEWLINE+'Yes'+NEWLINE+'No',ignore : 1, parent:'Account'});
  40. // add a "Company" filter
  41. this.filter_fields_dict['Account'+FILTER_SEP +'Company'].df.filter_hide = 0;
  42. // remove limts - show all records
  43. this.dt.set_no_limit(1);
  44. // hide tabs
  45. $dh(this.mytabs.tabs['Select Columns'])
  46. }
  47. Scrubbing / modifying data from the query
  48. -----------------------------------------
  49. The query can be scrubbed on the server side in Python before it. The result data is available as a list-in-a-list
  50. `res`. The output can be modified by updating `res` or declaring a new list-in-a-list `out`
  51. Standard lists, dictionary that can be updated
  52. * `col_idx` - Index of columns by label
  53. * `colwidths` - list of column widths
  54. * `colnames` - list of column names
  55. * `coltypes` - list of column types
  56. * `colwidths` - list of column `options`
  57. * `filter_values` - dictionary containing values of all filters
  58. Example - adding a column::
  59. colnames.append('Total')
  60. coltypes.append('Currency')
  61. colwidths.append('120px')
  62. coloptions.append('')
  63. # set the index
  64. col_idx[c[0]] = len(colnames)-1
  65. Example - adding the column data::
  66. sum = 0
  67. for r in res:
  68. # get the total as sum of 2 columns
  69. t = r[col_idx['Val 1']] + r[col_idx['Val 2']]
  70. sum += t
  71. # add it to the record
  72. r.push(t)
  73. Example - getting value from a filter::
  74. if filter_values.get('Show sum')=='Yes':
  75. res.append(['','','', sum])
  76. Adding style to the result
  77. --------------------------
  78. Style can be set on a row by declaring the `beforerowprint` method in the Client Script of the `Search Criteria`
  79. Example::
  80. // Example 1: set foreground
  81. report.beforerowprint = function(row){
  82. if(row.data[‘Amount’] > 20000) {
  83. row.style.color = ‘GREEN’;
  84. }
  85. }
  86. // Example 2: set background
  87. report.beforerowprint = function(row){
  88. if(row.data[‘Amount’] < 1000) {
  89. row.style.backgroundColor = ‘#FDD’;
  90. }
  91. }
  92. Generating a query by script from client side
  93. ---------------------------------------------
  94. A query can be generated from a script from the client side like in Listing by declaring the `get_query` method.
  95. Note: Do not put ORDER BY and LIMIT as they would be appended by the Report Builder. There are 2 useful lists
  96. * report.selected_fields - list of selected fields in `Table_Name`.`field_name` format
  97. * report.filter_vals - dictionary of filter keys and values
  98. Example::
  99. report.get_query = function() {
  100. var query = 'SELECT ' + report.selected_fields.join(', ') + 'FROM `tab..` WHERE ...';
  101. return query;
  102. }
  103. Report Builder API
  104. ------------------
  105. .. data:: _r
  106. Namespace for all objects related to Report Builder
  107. Report Builder Container
  108. ------------------------
  109. The Report Builder Container is the object that contains ReportBuilder objects for each DocType. This object
  110. is managed automatically by the Framework
  111. .. class:: _r.ReportBuilderContainer()
  112. .. data:: rb_dict
  113. Dictionary of all ReportBuilders. Key is the `DocType`
  114. Report Builder Class
  115. --------------------
  116. .. class:: _r.ReportBuilder
  117. .. data:: large_report
  118. Flag indicating a report with many records as output. This will force the user to use "Export" only
  119. .. data:: filter_fields
  120. List of all filter fields
  121. .. data:: filter_fields_dict
  122. Dictionary of all filter fields. The key of this dictionary is the doctype + `FILTER_SEP` + label
  123. .. data:: dt
  124. Reference to the :class:`_r.Datatable` object of the Report Builder
  125. .. data:: mytabs
  126. `TabbedPage` object representing the tabs of the Report Builder. This can be used to hide / show
  127. tabs from the Client Script in the report like::
  128. $dh(this.mytabs.tabs['Select Columns'])
  129. .. function:: customize_filters(report)
  130. The method is called when a new report or Search Criteria is loaded. The method (if exists)
  131. is usually used to customize filters as per the user requirments.
  132. .. function:: hide_all_filters()
  133. Will set the `df`.`filter_hide` property and hide all filters
  134. .. function:: set_column(doctype, label, value)
  135. Select / unselect a column. `value` must be 0 or 1
  136. .. function:: set_filter(doctype, label, value)
  137. Set the value of a filter
  138. .. function:: add_filter(f)
  139. Add a filter in the by specifying the field properties in a dictionary.
  140. .. function:: run()
  141. Execute the report
  142. Datatable Class
  143. ---------------
  144. .. class:: _r.Datatable(html_fieldname, dt, repname, hide_toolbar)
  145. The datatable class represents a grid object to show the results with paging etc
  146. .. function:: add_sort_option(label, value)
  147. Add a new field for sorting selection - value is the tablename.fieldname for the "ORDER BY" clause::
  148. report.dt.add_sort_option('ID','`tabMyDT`.`name`');
  149. .. function:: set_sort_option_disabled(label, disabled)
  150. Will enable / disable sort option by label. To disable, pass disabled = 1 or to enable pass disabled = 0
  151. .. attribute:: query
  152. Query to be executed (the paging using `LIMIT` & sorting is managed by the datatable)
  153. .. attribute:: page_len
  154. Length of a page (default 50)
  155. .. method:: set_no_limit(value)
  156. Run the query without adding limits if value = 1, (if value=0) run as standard, with limits
  157. .. method:: run
  158. Execute the query