How to add FROM Date and TO Date in ERPNext Query Report

@crafter - any ideas?

@ValS

I don’t suppose you have any other pointers?

Can you post your whole .py code AND .js code. Declare the filters in .js just like @SanRam suggested . Right after declaring it in js you should be able to see the filters on your report page after refreshing it. You can then move on to retrieving and manipulating data via server side.

I’m sorry, I can’t be of any more help right now.

@ValS

Noted with thanks.

@marination

Thank you for the assistance.

Here is the .py:
How to add FROM Date and TO Date in ERPNext Query Report - #14 by Eli

And the .js is identical to what is mentioned here:

Thanks in advance.

If this still is the issue, there could be a missing comma in your .js file , which is why i asked if i could see your .js. I understand that it is similar to the one above, but clearly there is a minor error. It should work fine otherwise. Also what do you see on your screen ? Does it go blank? Its hard to debug without knowing what is going on here

@marination

Here is the .js

frappe.query_reports["sales report"] = {
	"filters": [
	{
		"fieldname":"from_date",
		"label": __("From Date"),
		"fieldtype": "Date",
		"width": "80",
		"reqd": 1,
		"default": frappe.datetime.month_start()
	},
	{
		"fieldname":"to_date",
		"label": __("To Date"),
		"fieldtype": "Date",
		"reqd": 1,
		"width": "80",
		"default": frappe.datetime.month_end()
	}

	]
}

Thanks in advance

@marination

:wave:

@clarkej

This issue is still unresolved.

The marked solution was in response to a request for more data

1 Like

@marination

Just bumping this up in case you missed it.

frappe.query_reports["sales report"] = {
	"filters": [
	{
		"fieldname":"from_date",
		"label": __("From Date"),
		"fieldtype": "Date",
		"width": "80",
		"reqd": 1,
		"default": frappe.datetime.month_start()
	},
	{
		"fieldname":"to_date",
		"label": __("To Date"),
		"fieldtype": "Date",
		"reqd": 1,
		"width": "80",
		"default": frappe.datetime.month_end()
	}

	]
}

Maybe terminate that expression with ‘;’

An online Javascript validator complains that is missing!

For example

@clarkej

Thank you very much for following up.
I am so ashamed of the mistake I had been making that wasted everyone’s time.

I only realized yesterday that the report’s name value is case sensitive!

Instead of
frappe.query_reports["sales report"]

is should have been

frappe.query_reports["Sales Report"]

After making this small change, everything worked as advertised!

On the contrary I disagree @Eli - mistakes are human and inevitable and learning is never wasted time - you also have informed me and many more too.

Yet another discovery and bug prospect for me just now as a result:

A DocType name must be capitalised - ERPNext forces that rule by simply capitalising name violations when it saves and validates a new DocType.

However for a new Query Report, ERPNext does not apply that same rule in that case too?

And that can mean confusion as you have found.

Attached is my test case Query Report named ‘dummy doctype query report’ :slight_smile:

Hi, I am trying to implement a similar thing in a query report. The SQL query works fine (except the WHERE Date >= %(from_date)s and Date <= %(to_date)s part). I searched the entire documentation/forum but couldn’t get a grasp how the query report actually works if hosted on frappe.cloud. On V13, the filters can be added above the SQL query:


This works and I can see the filter boxes above the report:


However when I include the query in the SQL command I get following error message:

As said the docs are quite confusing and it isn’t clear whether this is possible at all if hosted on Frappe Cloud. I can add a script below the query box, but how/if this works on Frappe Cloud.
Any suggestion would be really helpful!

hi @bluesky, i have this:

and ( date_format(inv.creation, “%%Y-%%m-%%d”) between %(fecha_inicial)s and %(fecha_final)s )


and it works.

1 Like

@landaverdelbo Thanks for your help! I could fix it now and it work.

How did you fix this? I have the same error.
in a script report, some at the last query then,
AND p.posting_date >%(start_date)s
SO I want to filter the records according to the user select date.
this doesn’t working. Can someone help pls?

I asked the question here few days ago, no one care to help me yet :frowning:

can you share the code i want to also pass the parameters from js to py file