How to call python method inside javascript

I have python function which is executing fine and but I want to call itinto javascript
js file code:
grand_total: function(frm) {
return frappe.call({
method: “erpnext.buying.doctype.purchase_order.purchase_order.num_to_word”,
args:{“grand_total”:frm.doc.grand_total,
“company_curreny”:frm.doc.currency

	},

callback: function® {
if (r.message) {
alert(“done”);
}
}
});
},

show whenever i am calling in js it is giving error

error:-
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 57, 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 935, in call
return fn(*args, **newargs)
TypeError: num_to_word() takes exactly 2 arguments (1 given)

an argument passed in args is the correct way to pass it?

Modifying core apps (frappe & erpnext) is a bad idea!

1 Like

@snv
so how to call python method accepting arguments inside js file ?

why don’t you use the inbuilt method in frappe.utils:

@snv
i am using inbuilt function but i want to access that method inside js file not in python

  1. It is whitelisted?
  2. Are you providing all required args?
  3. Have you spelled the args correctly? I can see you’ve misspelled company_currency as company_curreny.

Yes it is whitelisted
js file :-
grand_total: function(frm) {
frappe.call({
method: “erpnext.buying.doctype.purchase_order.purchase_order.num_to_word”,
args:{ “grand_total”:cur_frm.doc.doc.grand_total,
“company_currency”:cur_frm.doc.doc.currency

	},

/*
args: {
“total”: frm.doc.grand_total,
“curreny”:frm.doc.currency
},*/
callback: function® {
if (r.message) {
alert(“done”);
}
}
});
},

python file:-
@frappe.whitelist()
def num_to_word(grand_total, company_currency):
msgprint(‘in num_to_word’)
total_amount_in_words = money_in_words(grand_total, company_currency)
return total_amount_in_words

but i do not whether i am passing arguments in right way or not in js file.

Are you doing this in a production instance?

Yes doing in production instance

Well, that’s a bad idea too.

Anyway, for changes to effect in a production instance, you must:

  1. reboot the instance.
  2. clear the cache.
  3. rebuild assets if you’re modifying JS files in apps.