Good day to all, can anyone help me why the data doesn’t display when trying to print the report? Tried following the documentation but for some reason it does not work.
here is my Javascript, Python, and HTML codes.
Javascript Code:
frappe.query_reports["Athlete"] = {
"filters": [
{
"fieldname": "first_name",
"label": __("First Name"),
"fieldtype": "Data",
"width": 100,
"reqd": 0,
},
{
"fieldname": "middle_name",
"label": __("Middle Name"),
"fieldtype": "Data",
"width": 100,
"reqd": 0,
},
{
"fieldname": "last_name",
"label": __("Last Name"),
"fieldtype": "Data",
"width": 100,
"reqd": 0,
},
{
"fieldname": "sport_name",
"label": __("Sport"),
"fieldtype": "Link",
"options": "Sport",
"width": 100,
"reqd": 0,
}
],
}
Python Code:
from __future__ import unicode_literals
from frappe import _
import frappe
def execute(filters=None):
return get_columns(), get_data(filters)
def Merge(dict1, dict2):
return (dict1.update(dict2))
def get_data(filters):
conditions = " 1=1 "
if(filters.get('first_name')):conditions += f"AND first_name='{filters.get('first_name')}'"
if(filters.get('middle_name')):conditions += f"AND middle_name='{filters.get('middle_name')}'"
if(filters.get('last_name')):conditions += f"AND last_name='{filters.get('last_name')}'"
if(filters.get('sport_name')):conditions += f"AND sport_name='{filters.get('sport_name')}'"
x = 0
data1 = frappe.db.sql(f"""SELECT first_name, middle_name, last_name, full_name FROM `tabAthlete` WHERE {conditions};""", as_dict=True)
for i in data1:
data2 = frappe.db.sql(f"""SELECT sport_name, start_date, end_date, no_of_games FROM `tabGames` WHERE parent = '{i['full_name']}';""", as_dict=True)
data1[x] = Merge(i, data2[0])
x = x + 1
data3 = list()
dict_data = dict()
for data in data1:
dict_data[data['full_name']] = 'Full Name'
dict_data[data['first_name']] = 'First Name'
dict_data[data['middle_name']] = 'Middle Name'
dict_data[data['last_name']] = 'Last Name'
dict_data[data['sport_name']] = 'Sport'
dict_data[data['start_date']] = 'Start Date'
dict_data[data['end_date']] = 'End Date'
dict_data[data['no_of_games']] = 'No. of Games'
data3.append(tuple(dict_data))
dict_data = {}
data9 = list()
for i in data3:
data9.append(list(i))
return data9
def get_columns():
return [
"Full Name:Link/Athlete:200",
"First Name:Data:120",
"Middle Name:Data:100",
"Last Name:Data:100",
"Sport:Data:100",
"Start Date:Date:100",
"End Date:Date:100",
"No. of Games:Int:120"
]
HTML Code:
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<h2 class="text-center">{%= __("Athlete Report") %}</h2>
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center">{%= __("Full Name") %}</th>
<th class="text-center">{%= __("First Name") %}</th>
<th class="text-center">{%= __("Middle Name") %}</th>
<th class="text-center">{%= __("Last Name") %}</th>
<th class="text-center">{%= __("Sport") %}</th>
<th class="text-center">{%= __("Start Date") %}</th>
<th class="text-center">{%= __("End Date") %}</th>
<th class="text-center">{%= __("No. of Games") %}</th>
</tr>
</thead>
<tbody>
{% for(var i=0, l=data.length-1; i<l; i++) { %}
<tr>
<td class="text-center" id="fullname">{%= data[0].full_name %}</td>
<td class="text-center" id="firstname">{%= data[0].first_name %}</td>
<td class="text-center" id="middlename">{%= data[0].middle_name %}</td>
<td class="text-center" id="lastname">{%= data[0].last_name %}</td>
<td class="text-center" id="sportname">{%= data[0].sport_name %}</td>
<td class="text-center" id="startdate">{%= data[0].start_date%}</td>
<td class="text-center" id="enddate">{%= data[0].end_date %}</td>
<td class="text-center" id="numgames">{%= data[0].no_of_games %}</td>
</tr>
{% } %}
</tbody>
</table>
Here is a screenshot when I tried to print. It shows the table but not the data. In addition, I have 2 entries, which is why there are 2 rows in the table.
Screenshot:
Print Report
Entries
https://imgur.com/a/A5ugk32
DocTypes Used
- Athlete
- Games
Thank you for helping