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(r) {
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?
snv
January 21, 2019, 10:45am
2
Modifying core apps (frappe
& erpnext
) is a bad idea!
1 Like
@snv
so how to call python method accepting arguments inside js file ?
snv
January 21, 2019, 10:51am
4
why don’t you use the inbuilt method in frappe.utils
:
else:
out = main_currency + ' ' + _(in_words(main, in_million).title())
if cint(fraction):
out = out + ' ' + _('and') + ' ' + _(in_words(fraction, in_million).title()) + ' ' + fraction_currency
return out + ' ' + _('only.')
#
# convert number to words
#
def in_words(integer, in_million=True):
"""
Returns string in words for the given integer.
"""
locale = 'en_IN' if not in_million else frappe.local.lang
integer = int(integer)
try:
ret = num2words(integer, lang=locale)
except NotImplementedError:
ret = num2words(integer, lang='en')
except OverflowError:
@snv
i am using inbuilt function but i want to access that method inside js file not in python
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(r) {
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.
snv
January 21, 2019, 11:02am
8
Are you doing this in a production instance?
Yes doing in production instance
snv
January 21, 2019, 11:04am
10
Well, that’s a bad idea too.
Anyway, for changes to effect in a production instance, you must:
reboot the instance.
clear the cache.
rebuild assets if you’re modifying JS files in apps.