Child Table Data in Columns
Introduction
An example of a report that shows the child table values in a single row with the parent data. Also, columns can be dynamic.
Use Case
Suppose we have a demo DocType named Credit Card EMI which has the following fields:
- Customer Name
- Total Amount
- Scheme: 3/6/12 Months
- EMIs: Child table with EMIs based on the scheme
Here is a screenshot showing the form view:
The Report
We want to create a report that has this EMIs in different columns, like shown below:
The Script
Optimizing The Data Fetching
If you observe the get_data()
method, you will see we are calling the frappe.get_all
method to get child items for each Credit Card EMI doc, which means 1 DB call per document (O(n)
in computer sciency terms).
We can use the Query Builder to reduce this to just one database call (query is highlighted):
We had to add more data processing on the Python side though.