Hello.
I need a button that creates a pdf when pressed. I used the "get_pdf" function for this. But when I press the button I get this error.
“Cannot read properties of undefined (reading ‘responseText’)”
My JS Code;
frappe.ui.form.on('Offers', {
refresh: function(frm) {
frm.add_custom_button(__('Button'), function(){
frappe.call({
method: "crm.scripts.generate_invoice",
callback: function(r) {
// code snippet
}
});
}, __("Tasks"));
// buton finish
},
validate(frm){
location.reload();
}
});
My python function:
@frappe.whitelist(allow_guest=True)
def generate_invoice():
test = "test pdf"
html = '<h1>Invoice from Star Electronics e-Store!</h1>'
# Add items to PDF HTML
html += '<ol>'
html += f'<li>{test}</li>'
html += '</ol>'
# Attaching PDF to response
frappe.local.response.filename = 'invoice.pdf'
frappe.local.response.filecontent = get_pdf(html)
frappe.local.response.type = 'pdf'