Set route/ mapped doc

This starts as a UX question:
I’m working on a contribution to Accounts called Indirect Expense (functionally, it’s non-stock Purchase Invoice or a Journal Entry that lets you easily split expenses between currencies, projects, account, campaigns, cost centers or any combination of those, without dealing with Items). So. When I’m in an accounting flow and entering bills I know that I, personally, am likely to start entering an expense for a stocked item (which should be a Purchase Invoice) when it should be a straight-up expense or vice versa. I want a bailout button at the top that converts the work I’ve done in either case to the other, shown here as “Convert to Purchase Invoice”. I want this to happen before saving.


Now the technical part:
I am using a verbose pattern for this; gather variables into route_options and then populating them on the other side (half the code is shown here, but they’re basically identical). This works fine, I just want to know if there’s a better way.

function route_to_pi(frm){
	let new_purchase_invoice = frappe.model.make_new_doc_and_get_name("Purchase Invoice");
	frappe.route_options =
		{ "company": frm.doc.company,
			"supplier": frm.doc.party,
			"due_date": frm.doc.due_date,
			"bill_date": frm.doc.invoice_date,
			"bill_no": frm.doc.ref_number,
			"payment_terms_template": frm.doc.payment_terms_template,
			"credit_to": frm.doc.accounts_payable_account,
			"items": frm.doc.accounts
		};
	frappe.set_route("Form", "Purchase Invoice", new_purchase_invoice);
}

function setup_set_route(frm){
	if(frappe.route_options != undefined){
		frm.set_value("party_type", "Supplier");
		frm.set_value("company", frappe.route_options.company);
		frm.set_value("party", frappe.route_options.party);
		frm.set_value("due_date", frappe.route_options.due_date);
		frm.set_value("invoice_date", frappe.route_options.invoice_date);
		frm.set_value("ref_number", frappe.route_options.ref_number);
		frm.set_value("payment_terms_template", frappe.route_options.payment_terms);
		frm.set_value("accounts_payable_account", frappe.route_options.credit_to);
		frappe.route_options = {};
	}
}