Script Report in Custom App

I have created a custom app and now I am trying to make report in it. The report is working fine in my development environment. How ever when I deploy it in the production server it is giving me error. I have tried to change the code directly in the production server just to see. But it keeps showing the same error on the same line no mater how I change the code, I have even tried to change the file name just to see what happens. The code has been taken and customized from stock ledger report
The code is on this link: Code for report

below is the error:

Traceback (most recent call last):
File “/home/ahmad/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/ahmad/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/home/ahmad/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/init.py”, line 1042, in call
return fn(*args, **newargs)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/init.py”, line 515, in wrapper_fn
retval = fn(*args, **get_newargs(fn, kwargs))
File “/home/ahmad/frappe-bench/apps/frappe/frappe/desk/query_report.py”, line 183, in run
result = generate_report_result(report, filters, user)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/desk/query_report.py”, line 68, in generate_report_result
res = report.execute_script_report(filters)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/core/doctype/report/report.py”, line 104, in execute_script_report
res = self.execute_module(filters)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/core/doctype/report/report.py”, line 121, in execute_module
return frappe.get_attr(method_name)(frappe._dict(filters))
File “/home/ahmad/frappe-bench/apps/steelpipes/steelpipes/sp_item/report/pipe_stock_ledger/pipe_stock_ledger.py”, line 41, in execute
query_result = frappe.db.sql(sql_query,as_dict=1)
File “/home/ahmad/frappe-bench/apps/frappe/frappe/database/database.py”, line 171, in sql
self._cursor.execute(query)
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 170, in execute
result = self._query(query)
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 328, in _query
conn.query(q)
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 732, in _read_query_result
result.read()
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 1075, in read
first_packet = self.connection._read_packet()
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/home/ahmad/frappe-bench/env/lib/python3.5/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1054, “Unknown column ‘warehouse’ in ‘where clause’”)

It seems you have taken warehouse field in your script and that is custom field which has not been migrated to your production.

  1. If it is custom field that you have taken in development environment, you have to export the fixtures from local and have to migrate to production.
1 Like

I have verified. I am not using any custom field here. All fields are available in the respective database tables as well. What else could go wrong?

I have gone through your script
Please check all child table are they having the field name as warehouse only or some other field name

1 Like

In your function get_stock_ledger_entries(), you are returning entries for a voucher type (read doc type, for example Invoice) that does not have a ‘warehouse’ field.

Then you have a query that fails :
SELECT …
FROM tab{0}
WHERE … warehouse=’{3}’

1 Like

Thank you for going through the script. There was a name change in Stock entry details Table. warehouse was named as s_warehouse/t_warehouse. I updated the code as required and it is working fine now.