I am trying to create a button in the projects module which is similar to the “Make Invoice” button that is found in a Sales Order screen. This will allow a user to create an invoice from a project task (assuming it is billable).
//Prepare the new Sales Invoice var si = frappe.model.make_new_doc_and_get_name('Sales Invoice'); var table_row = locals[doctype][name]; si = locals['Sales Invoice'][si]; si.customer = frm.doc.customer; si.project_name = frm.doc.name; //Add the item to the Sales Invoice Items table var d1 = frappe.model.add_child(si, 'Sales Invoice Item', 'items'); d1.item_name = table_row.title; loaddoc('Sales Invoice', si.name);
I can get all the way up to creating a new Sales Invoice and populating the relevant fields (without having to save the document yet - which is very important for me). But after loading the Sales invoice and populating the customer field, I would like to run the “customer: function()” found in sales_invoice.js which will help to populate other fields such as territory, tax etc. automatically. Is there a version of loaddoc with callback or onload?
I noticed that loaddoc will accept an onload parameter but it does nothing. I’ve also confirmed this after looking at loaders.js.