Iam trying to call a method in client script, which is present in server script.
While iam doing this, iam getting error like below…
please help me to do this…
I will provide my client script and server script if needed…
Thanks in advance
Iam trying to call a method in client script, which is present in server script.
While iam doing this, iam getting error like below…
please help me to do this…
I will provide my client script and server script if needed…
Thanks in advance
@Kiranmai,
because the download method isn’t in the sales_invoice.py.
If you define the download, please check the path to the client script.
Thank You!
@NCP Thanks for your reply…
this is my server script code (sales_invoice.py).
@frappe.whitelist()
def download(docname):
document = frappe.get_doc(‘Sales Invoice’,{“name”:docname})
html_content = frappe.get_print(‘Sales Invoice’, document.name, print_format=‘Sales Invoice Custom Print’)
pdf = frappe.utils.pdf.get_pdf(html_content)
desktop_path = os.path.expanduser(“~/Downloads”)
current_datetime = datetime.now().strftime(“%Y-%m-%d_%H:%M:%S”)
file_name = f"{name}_{current_datetime}.pdf"
file_path = os.path.join(desktop_path, file_name)
# Save the PDF file
with open(file_path, “wb”) as f:
f.write(pdf)
return file_path
This is my client script code (sales_invoice.js)…
frappe.ui.form.on(‘Sales Invoice’, {
refresh: function (frm) {
frm.add_custom_button((‘Download Print’), function () {
frappe.call({
method: ‘sales_invoice.download’,
args: {
docname: frm.doc.name
},
callback: function (r) {
if (r.message) {
frappe.msgprint((‘Download successfully.’));
}
},
});
});
},
});
the file paths are :::
for server script : /home/kiranmai/Downloads/Hilltop/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
for client script : /home/kiranmai/Downloads/Hilltop/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
frm.call
please check the reference so you can understand of define the frm.call and frappe.call.
Please check the set_missing_values
method
How to call in the sales_invoice.py
I hope this helps.
Thank You!
Good day,
I am also trying to call a server script using a button and client script. Here is my test client script.
It should call the script when the button “recalculate attendance” is clicked. But I got this error.
even though the server script is whitelisted
I checked this document already, Frappe Ajax Call
Thank you.