I’m trying to edit the html file of the report to create a custom template, but, I’m unable to use get_value, db.get_value and get_doc in it. All 3 throws error on console.
How can I fetch data from another doctype in this case. It doesn’t use Jinja but some other templating engine.
Please guide.
Hello,
You may also include the data on the report itself.
Regards,
Ivan
Are you by any chance using a script report or making a custom print format for a query or built-in report?
I’m trying to fetch customer address and adding it each row will increase its width. Any other way?
I using a script report, Accounts Receivable, to be precise.
Hello,
Found something, this is not the good way to do it. You can attach after_datatable_render
script on report and modify the data of the query report like this.
frappe.query_reports["..."] = {
"after_datatable_render": function(_) {
frappe.query_report.data[0]['test'] = 'Testing';
},
"filters": [...]
}
Regards,
Ivan
1 Like
Create Custom Print Format for a Script Report
Assuming you already created a standard Script Report (Is Standard = Yes), follow these steps:
create html file in /apps/your_app/your_app/your_module/report/your_report/your_report.html
your_app/
└── your_module/
└── report/
└── your_report_name/
├── your_report_name.py
├── your_report_name.js
├── your_report_name.json
└── your_report_name.html ← create this!
The .html file must match the report name.
Inside your_report_name.html, write a Jinja2 template like this:
<h2>{{ report.report_name }}</h2>
<table class="table table-bordered">
<thead>
<tr>
{% for col in columns %}
<th>{{ col.label }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
{% for col in columns %}
<td>{{ row[col.fieldname] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
You can use any valid HTML + Jinja2 logic. Frappe passes columns and data from your execute() function to this template automatically.
How to Use It
Go to your Script Report in the UI.
From the top-right menu (⋮), choose Print.
Frappe will render your custom HTML as the print output.
You can also export as PDF from the same menu.
Hot Reload (Optional)
After editing the .html, if your changes don’t show up:
bench --site your-site build
bench --site your-site clear-cache
bench --site your-site migrate
bench restart
Note:
The .html file must match the report name.
The .html file must be in the same directory as the .py file.
The .html file is not a standard Frappe feature. It’s a custom solution for specific needs.
The .html file is only used for printing (not the onscreen report).
Make sure your columns list in execute() uses fieldname, label, etc., properly.
You can include custom styles or logic inside the HTML/Jinja template.
It only works for Script Reports (not Query Reports).
It’s mainly for PDF/HTML export, not for viewing in the browser.
For complex print formats, consider using standard Print Formats (Setup > Print > Print Format) which are more integrated with Frappe’s features.
Tips
Please don’t give people advice from GPT without verifying.
Report HTML won’t render Jinja.
Frappe Framework uses John Resig’s Microtemplate script to render HTML templates in the Desk application.
https://docs.frappe.io/framework/user/en/guides/app-development/using-html-templates-in-javascript
1 Like
i already tried it and it works with me
I got that solution from erpnext itself:
<!-- Modified on 25-11-2024
-->
<style type="text/css">
/* General styles for both screen display and print */
body, html {
margin-top: 10;
padding: 0;
width: 100%;
height: auto; /* Allow content to expand */
font-family: Arial, sans-serif; /* Example font */
}
/* Ensure consistent letter spacing across all media */
.title-letter-spacing {
letter-spacing: .2rem;
}
/* Styles specific to printing and PDF generation */
@media print {
This file has been truncated. show original
just knew the “John Resig’s Microtemplate script”
I thought it was normal jinja
thanks
2 Likes
No problem, we all learn from experiences
1 Like