ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

[Custom] Error make filter in report script


#1

help me to fixed error my report

i have code :

def get_conditions(filters):
	conditions = ""
	if filters.get("from_date"):
		conditions += " and posting_date>=%(from_date)s"
	if filters.get("to_date"):
		conditions += " and posting_date<=%(to_date)s"
	
	return conditions


@frappe.whitelist()
def download1(filters):

	conditions = get_conditions(filters)

	content = '\"' + '"|" '.join(map(str, (["FK", "KD_JENIS_TRANSAKSI", "FG_PENGGANTI", "NOMOR_FAKTUR", "MASA_PAJAK", "TAHUN_PAJAK", "TANGGAL_FAKTUR", "NPWP", "NAMA", "ALAMAT_LENGKAP",
                                         "JUMLAH_DPP", "JUMLAH_PPN", "JUMLAH_PPNBM", "ID_KETERANGAN_TAMBAHAN", "FG_UANG_MUKA", "UANG_MUKA_DPP", "UANG_MUKA_PPN", "UANG_MUKA_PPNBM", 'REFERENSI']))) + '\"' + "\n"
	content += '\"' + '"|"'.join(map(str, (["LT", "NPWP", "NAMA", "JALAN", "BLOK", "NOMOR", "RT", "RW",
                                         "KECAMATAN", "KELURAHAN", "KABUPATEN", "PROPINSI", "KODE_POS", "NOMOR_TELEPON"]))) + '\"' + "\n"
	content += '\"' + '"|"'.join(map(str, (["OF", "KODE_OBJEK", "NAMA", "HARGA_SATUAN", "JUMLAH_BARANG",
                                         "HARGA_TOTAL", "DISKON", "DPP", "PPN", "TARIF_PPNBM", "PPNBM"]))) + '\"' + "\n" 

and i have error

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
    return fn(*args, **newargs)
TypeError: download1() takes exactly 1 argument (0 given)

#2

and my js script :

// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.query_reports["Sales invoice script"] = {
	"filters": [
		{
			"fieldname": "from_date",
			"label": __("From Date"),
			"fieldtype": "Date",
			"default": frappe.defaults.get_user_default("year_start_date"),
			"width": "80"

			
		},
		{
			"fieldname": "to_date",
			"label": __("To Date"),
			"fieldtype": "Date",
			"default": frappe.datetime.get_today()
		}
		
	],


	onload: function (report) {
		report.page.add_inner_button(__('Download to CSV (CUSTOMISE)'), function () {
			return frappe.call({
				method: "erpnext.accounts.report.sales_invoice_script.sales_invoice_script.download1",
				args: {},
				callback: function (r) {
					// download("TAX Develop.csv", r.message.content);
					// frappe.msgprint("CSV Berhasil Di Download");
					console.log(r.message.content)
				}
			});
			function download(filename, content) {
				var element = document.createElement('a');
				element.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(content));
				element.setAttribute('download', filename);
				element.style.display = 'none';
				document.body.appendChild(element);
				element.click();
				document.body.removeChild(element);
			}
		})
	}
}

#3

The traceback is very clear. You need to pass the right arguments


#4

@rmehta thanks for reply,
how i pass the right arguments?


#5

how to get value args js to python script?

this python code :

@frappe.whitelist(allow_guest=True)
def download(filters):
	conditions = ""
	if filters.get("from_date"):
		conditions += "and posting_date>=%(from_date)s"
	if filters.get("to_date"):
		conditions += "and posting_date<=%(to_date)s"

if i use this python code, its didnt work, and eror attribut get


#6

You are declaring on Python that download needs only one argument i.e. filters.

Whereas from the JS you are sending two arguments, from_date and to_date. That is the problem.


#7

hai @root13F thanks for reply,

if i make js:

how i call value fieldname:from_date and to_date in filter report to args in button js?


#8

@root13F
or how to get value in python when i have from date and to_date in js :

and python code :

@frappe.whitelist(allow_guest=True)
def download(data):

frappe.msgprint(data)

return date

#9

You need to change definition of download function.

From this

@frappe.whitelist(allow_guest=True)
def download(data):

to this

@frappe.whitelist(allow_guest=True)
def download(from_date, to_date):

#10

thanks all this problem solved…


#11

how did you solve it ?