Function Calling Error

I made one method to fetch the record of child table
Py Method is

@frappe.whitelist(allow_guest=True)
def fetchTable(self,method):
frappe.msgprint(self.flat_tax)
doc_req = []
if not self.flat_table and self.flat_tax:
doc_master = frappe.get_doc(“MasterTable”, self.flat_tax)
#frappe.msgprint(doc_master)
for value in doc_master.get(“child_table”):
doc_req = {
“doctype”: “ChildTable”,
“description”: value.description,
“rate”: value.rate,
“amount”:self.flat_total*value.rate/100
}
self.append(“flat_table”, doc_req)

If i am calling this method from hooks.py ex: as follows

doc_events = {
“Sales Invoice”: {
“validate”: “erpnext.crm.ef_doc.fetchTable”
},
}

Successfully run and my table getting filed , But when i calling this same function through Custom Script which is as follows

cur_frm.cscript.flat_tax= function(doc) {
if(1) {
cur_frm.call({
method: “erpnext.crm.ef_doc.fetchTable”,
args: {
“flat_tax”: doc.flat_tax,
},
callback: function(r, rt) {
if(r.message) {
}

		 }
	});
 }

}

I getting this error

Traceback (innermost last):
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/app.py”, line 51, in application
response = frappe.handler.handle()
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/handler.py”, line 69, in handle
execute_cmd(cmd)
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/handler.py”, line 92, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/init.py”, line 751, in call
return fn(*args, **newargs)
TypeError: fetchTable() takes exactly 2 arguments (0 given)

Which type of argument error it’s giving (only one args required to fetch the table)

Hi,

You configured your method for two parameters self and method

And passing only one parameter to it, which is None (i.e. Null or Empty)

1 Like

I guess the self keyword is for local instance (Ex:this) so no need to pass any parameter for that…
Event if i remove method args now it’s giving this error
Traceback (innermost last):
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/app.py”, line 51, in application
response = frappe.handler.handle()
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/handler.py”, line 69, in handle
execute_cmd(cmd)
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/handler.py”, line 92, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/erpnext4/frappe-bench/apps/frappe/frappe/init.py”, line 751, in call
return fn(*args, **newargs)
TypeError: fetchTable() takes exactly 1 argument (0 given)

Self is similar to this parameter, but it only exist if method is part of class. In your case, method is not a part of class.

You have to pass parameter to it, if you want to access doctype.

Check output of doc.flat_tax, might be it producing NoneType output.

Quick Suggestion: Instead of passing doc.flat_tax, just pass doc .

Thanks to response…And i checked “doc.flat_tax”(with msgprint(doc.flat_tax) value which giving right value…! Is there any other solution please provide me

@DNGupta did you figured out the solution for this?

Yes @mzain I solved this issue…!

@DNGupta If you doon’t mind sharing how did you resolve this issue as i am currently facing it