Custom Button at Script Report Header level?

Is there a way to add button at header level in script report?

If yes from where should i start and how could i add custom button at header level?

(Example UseCase - adding checkbox at line level in script report and based on checkbox selection at line level, Button Click at report header level which will create payment entry record for all selected sales invoices where status is unpaid.)

Any pointer will be appreciated!

"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": "Date",
		"label": __("Date"),
		"fieldtype": "Date",
		"default":frappe.datetime.get_today()
		
	},
	{
		"fieldname": "Test",
		"label": __("Test"),
		"fieldtype": "Button"
		
	}


]

1 Like

Thanks @Maheshwari_Bhavesh for solution. Just curious to know how can we call js method for this “Test” button created?

@Maheshwari_Bhavesh Is there a way we can bind onclick event from py file for this “Test” button created?

frappe.query_reports["KYC Owners' Birthday Calendar"] = {
	"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": "Date",
			"label": __("Date"),
			"fieldtype": "Date",
			"default":frappe.datetime.get_today()
			
		}

	],
	onload: function(report) {
		report.page.add_inner_button(__("Test"), function() {
			frappe.msgprint("Test");
		});
	}
}
3 Likes

@Maheshwari_Bhavesh I tried to call python method using below code but getting an error:

onload : function(report) {
	report.page.add_inner_button(__('Approve'), function() {
		return frappe.call({
			method: "erpnext.accounts.report.internal_voucher.internal_voucher.get_all_sales_invoice",
			callback: function(r) {
				frappe.msgprint("Approved sucessfully");
			}
		});
	})
}

Not sure how to call Python method from report.page.add_inner_button?

check your get_all_sales_invoice method

Py file:

@frappe.whitelist()
def test_button():
user_detail = frappe.get_all(“User”,{“name”:frappe.session.user}, [“first_name”, “last_name”, “user_image”, “email”])
return user_detail

Js file:

	onload: function(report) {
		report.page.add_inner_button(__("Test"), function() {
			return frappe.call({
				method: "erpnext.api.test_button",
				callback: function(r) {
				frappe.msgprint("Approved sucessfully");
				}

				});
		});
	}

1 Like

Here is the one as below: But not sure what’s wrong here?

@frappe.whitelist()
def get_sales_invoice(doctype, si_name):
	pe = get_payment_entry("Sales Invoice", si_name)
	pe.reference_no = "1"
	pe.reference_date = nowdate()
	pe.insert()
	pe.submit()
	frappe.db.commit()

@frappe.whitelist()
def get_all_sales_invoice():
	query = "select si.name from `tabSales Invoice` AS si	WHERE si.naming_series = 'INTERNAL-' and si.customer_group = 'Internal Customer' and si.status IN ('Unpaid','Overdue')"
	for si in query:
		get_sales_invoice('Sales Invoice', si)

I can show button, but can’t bind event with button using your code.