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

@ValS

Thanks for the prompt response.

I greatly appreciate it.

Yes- that is my full .py code. :pensive:

Thanks for pointing out where I went wrong.
Let me try to get it right and if/when I do- I’ll post the working code here.

There is something wrong with that code.

On line 3, you return from the execute function()
return columns, data

This means that lines 4 and 5 will never be executed.

@crafter @ValS - Thank you for the pointers .

I’ve tried the following but can’t seem to find joy. Could you advise where I’m getting it wrong still:

from future import unicode_literals
import frappe
from frappe import msgprint, _
from frappe.utils import getdate, cstr, flt, fmt_money


def execute(filters=None):
	if not filters:
		return [], []	
	if not filters.get("to_date"):
		frappe.throw(_("'To Date' is required"))
	if not filters.get("from_date"):
		frappe.throw(_("'From Date' is required"))

Have a look at my code here for a custom script report :

The file “client_statement.js” contains the filter parameters, which includes a start and end date.

The file “client_statement.py” contains the handling of the dates.
The dates are used within local functions, but you can see they are referred to by the notation as in the following example code

from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)

@crafter :clap::clap::clap::clap::clap:

Thank you very much. I’ll check it out right now

@crafter - May you grant me some grace today but I have tried the below and still no success .
May you advise what I’m mssing?

from future import unicode_literals
import frappe
from frappe import msgprint, _
from frappe.utils import getdate, cstr, flt, fmt_money


def execute(filters=None):

	if not filters:
		return [], []	
	

		

def get_conditions(filters):
	conditions = []
	from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)

Do you have any errors when you run this code?
What does the console return, if you print filters?

If it returns nothing, then if not filters will always be true, meaning your script ends at this point, if I’m not mistaken. I’m afraid I can’t help much more beyond that

@ValS

Thank you for replying.

The console gives the message below.

Uncaught SyntaxError: Invalid or unexpected token
    at Object.eval (dom.js:33)
    at query_report.js:172
query_report.js:177 Uncaught (in promise) TypeError: Cannot set property 'html_format' of undefined
    at query_report.js:177
    at request.js:381
    at new Promise (<anonymous>)
    at Object.frappe.after_ajax (request.js:374)
    at query_report.js:175

@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