Error While creating custom Report

Hi there @shreyasp
I am trying to create a custom script report in HR Module for Attendance doctype.
But after creating it, filters are not displayed in the report so could not query any data…
Under console i checked so getting an error as report_settings is undefined.
I dont know why i am getting this error.
Can u look into the matter?

Hi after creating script report, it should add .js, and .py files
you should code it there

i Have done the coding but still the filters are not displaying so cannot query any information from the scrip…
I ll paste my .js code as well.

My Js Code:

frappe.query_reports[“Monthly Detailed Work duration”] = {
“filters”: [
{
“fieldname”:“month”,
“label”: __(“Month”),
“fieldtype”: “Select”,
“options”: “Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec”,
“default”: [“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”,
“Dec”][frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth()],
},
{
“fieldname”:“year”,
“label”: __(“Year”),
“fieldtype”: “Select”,
“reqd”: 1
},
{
“fieldname”:“employee”,
“label”: __(“Employee”),
“fieldtype”: “Link”,
“options”: “Employee”
},
{
“fieldname”:“company”,
“label”: __(“Company”),
“fieldtype”: “Link”,
“options”: “Company”,
“default”: frappe.defaults.get_user_default(“Company”),
“reqd”: 1
}
],
“onload”: function() {
return frappe.call({
method: “erpnext.hr.report.monthly_detailed_work_duration.monthly_detailed_work_duration.get_attendance_years”,
callback: function(r) {
var year_filter = frappe.query_report_filters_by_name.year;
year_filter.df.options = r.message;
year_filter.df.default = r.message.split(“\n”)[0];
year_filter.refresh();
year_filter.set_input(year_filter.df.default);
}
});
}
}

Hi

Can you also post the .json file

Hi there,
the json file is:

{
“add_total_row”: 0,
“apply_user_permissions”: 1,
“creation”: “2016-11-12 14:51:05.401946”,
“disabled”: 0,
“docstatus”: 0,
“doctype”: “Report”,
“idx”: 0,
“is_standard”: “Yes”,
“modified”: “2016-11-12 16:10:57.185539”,
“modified_by”: “Administrator”,
“module”: “HR”,
“name”: “Monthly Detailed Work Duration”,
“owner”: “Administrator”,
“ref_doctype”: “Attendance”,
“report_name”: “Monthly Detailed Work Duration”,
“report_type”: “Script Report”
}

frappe.query_reports[“Monthly Detailed Work duration”] = {
“filters”: [
{

Maybe
The “duration” there should be “Duration”

1 Like

Yess that was the error…
Thank you for the support.
Appreciate it.

Hi good to know that it is already solved :slight_smile: you can also right click in your browser and then inspect so that you can see the errors.

Hi there, @johnskywalker
I am currently stuck on an error.
the error is string index out of range.
but i checked all the values and dont know y i am getting it.
I ll paste my code for the same.

def execute(filters=None):
if not filters: filters = {}

conditions, filters = get_conditions(filters)
columns = get_columns(filters)
att_map = get_attendance_list(conditions, filters)
emp_map = get_employee_details()

data = []
for emp in sorted(att_map):
    emp_det = emp_map.get(emp)
    if not emp_det:
        continue

    row = [emp, emp_det.employee_name, emp_det.branch, emp_det.department, emp_det.designation]

    total_p = total_a = 0.0
    msd = datetime.date(int(filters.get("year")),int ( filters.get("month")),int (filters["start_day"]))

    for d in range(filters["total_days_in_month"]):
        status = att_map.get(emp).get((msd.day), "None")[0]
        time_in = att_map.get(emp).get(msd.day, "None")[1]
        time_out = att_map.get(emp).get(msd.day, "None")[2]
        expected_working_time = att_map.get(emp).get(msd.day, "None")[3]
        **total_hours = (att_map.get(emp).get(msd.day, "None")[4])**
        **less_time = (att_map.get(emp).get(msd.day, "None")[5])**

I am getting error on values of total_hours and less_time
msd += relativedelta(days=1)

        status_map = {"Present": "P", "Absent": "A", "Half Day": "H", "N": "", "Weekly Off":"W"}
        row.append("Status: "+str(status_map[status]) + '\n' + "In Time :" + str(time_in) + "\n"+ "Out Time :" + str(time_out)
        + "\n"+ "Expected Time: :" + str(expected_working_time) + '\n' + "Total Time Worked :" + str(total_hours)
        + "\n"+ "Less Time :" + str(less_time))

        if status == "Present":
            total_p += 1
        elif status == "Absent":
            total_a += 1
        elif status == "Half Day":
            total_p += 0.5
            total_a += 0.5

    row += [total_p, total_a]
    data.append(row)

return columns, data

@Ujjawal Hello can you post the traceback, you can find it in your console where you did “bench start”

1 Like

hi @johnskywalker,
The traceback for the error.:
Traceback (most recent call last):
File “/home/user/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/user/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/user/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 890, in call
return fn(*args, **newargs)
File “/home/user/frappe-bench/apps/frappe/frappe/desk/query_report.py”, line 93, in run
res = frappe.get_attr(method_name)(frappe._dict(filters))
File “/home/user/frappe-bench/apps/erpnext/erpnext/hr/report/monthly_detailed_work_duration/monthly_detailed_work_duration.py”, line 36, in execute
t_h = (att_map.get(emp).get(msd.day, “None”)[4])
IndexError: string index out of range

Hi there @johnskywalker,
Any update on this?

Hello sorry, I’m a bit busy right now. Check on this later, thanks for the traceback

Sure :wink:
Thanks by the way.
Appreciate it.

Hi @Ujjawal

this

t_h = (att_map.get(emp).get(msd.day, “None”)[4])
IndexError: string index out of range

means that your list/array doesnt have index 4, have you checked the size and elements of your list?
try printing it first so that you may see it’s elements.

Sorry for replying late.
I have tried it and also printed all the value for the Dict.
But when printing individual values getting an error.

Hi there,
I have tried it and also solved it.
Can you just let me know how i can insert a new line in it?

row.append("Status: "+str(status_map[status]) + ‘\n’ + “In Time :” + str(time_in) + “\n”+ “Out Time :” + str(time_out)
+ “\n”+ “Expected Time: :” + str(expected_working_time) + ‘\n’ + “Total Time Worked :” + str(total_hours)
+ “\n”+ “Less Time :” + str(less_time))

i have used the above syntax to insert a new line but unable to do so what it does is it skips the ‘\n’ code and prints other

1 Like

Hi Haven’t tried doing that. But you may try <br> instead if it works. Or try doing custom jinja html, you can customize it more. Assuming that this is a custom script report, there should be a directory/files for this report, and if the name of the report is My Report you should add my_report.html in its folder. It will render what is in your my_report.html

I ll try doing that will revert back to you.

ok sure :slight_smile: