Custom Script Report throwing error

Hi,

I created a Custom Script report within my app. It created a folder called report and report_name within report. I created the report_name.py, report_name.js and report_name.json files inside that. Now, when I am trying to run it on the website, it is giving me this following error:

   Traceback (innermost last):
  File "/home/umag/frappe-bench/apps/frappe/frappe/app.py", line 57, in application
    response = frappe.handler.handle()
  File "/home/umag/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
    execute_cmd(cmd)
  File "/home/umag/frappe-bench/apps/frappe/frappe/handler.py", line 36, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/umag/frappe-bench/apps/frappe/frappe/__init__.py", line 806, in call
    return fn(*args, **newargs)
  File "/home/umag/frappe-bench/apps/frappe/frappe/desk/query_report.py", line 88, in run
    columns, result = frappe.get_attr(method_name)(frappe._dict(filters))
  File "/home/umag/frappe-bench/apps/pppl/pppl/pppl/report/stock_ledger_modified/stock_ledger_modified.py", line 12, in execute
    sl_entries = get_stock_ledger_entries(filters)
  File "/home/umag/frappe-bench/apps/pppl/pppl/pppl/report/stock_ledger_modified/stock_ledger_modified.py", line 54, in get_stock_ledger_entries
    .format(sle_conditions=get_sle_conditions(filters)), filters, as_dict=1)
  File "/home/umag/frappe-bench/apps/frappe/frappe/database.py", line 136, in sql
    self._cursor.execute(query, values)
  File "/home/umag/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 185, in execute
    for key, item in args.iteritems())
 KeyError: 'company'

What could the reason be?

You did not set company in filters.

Hi @nabinhait,

I have set the filters… See, this is what is there in my .js file

frappe.query_reports[“Stock Ledger Modified”] = {
“filters”: [
{
“fieldname”:“company”,
“label”: __(“Company”),
“fieldtype”: “Link”,
“options”: “Company”,
“default”: frappe.defaults.get_user_default(“Company”),
“reqd”: 1
},

and in my .py file, it is

def get_stock_ledger_entries(filters):
return frappe.db.sql(“”“select concat_ws(” “, posting_date, posting_time) as date,
item_code, warehouse, actual_qty, qty_after_transaction, incoming_rate, valuation_rate,
stock_value, voucher_type, voucher_no, batch_no, serial_no, company
from tabStock Ledger Entry
where company = %(company)s and
posting_date between %(from_date)s and %(to_date)s
{sle_conditions}
order by posting_date asc, posting_time asc, name asc”“”
.format(sle_conditions=get_sle_conditions(filters)), filters, as_dict=1)

Is there anything wrong with this? When I made the same changes in the erpnext code, it works. But, when I am trying to implement these changes through the custom app, it is giving this error.

Try to print “filters” in execute method and check if it gives proper values.

I am facing the same issue anyone can help??

It’s pretty much old thread but if anyone face same issue here is how to solve this.
I was creating a custom report using script report type and using the py and js code from default reports of erpnext. Here I made a mistake.
defult report name = stock ledger
custom report name = inventory ledger

what i did wrong is used the js code from default file and used the name

Stock Ledger

while I should use the Inventory Ledger.
I fixed this and my issue resolved eventually.

I have also issue in custom script report.

Keyerror: options