Link to doctype with automatic entries

Hi,

I’m trying to do a link from the form Issue to create a Sales Invoice specifically for repairs.

I’ve been able to create a button in my header, open a new sales invoice when I open it, and automatically fill in the customer to have the same one as in my issue.

I’m trying to do automate other parts of my form, without success:

  • Naming series -> by default, my sales invoice uses the naming series “SINV-”. In the dropdown menu, I have the choice between “SINV-”, SINV-RET-" and “SINV-REP-”. I’d like to put the naming series to “SINV-REP-” when I create a Sales Invoice through an Issue.
  • When doing a repair, I list the items that have been changed in a table within my issue. To ensure that it is the same table as in the sales invoice, it is a “Sales Invoice Item” table. I’d like to copy this table in my sales invoice automatically when i create my invoice.
  • To ensure that the stock is correct, I’d like to have the checkbox “Update Stock” automatically ticked, only when coming from an Issue.

I’ve tried doing all of this, but without success. Please find my attempt hereunder.

frappe.ui.form.on('Issue', {
    refresh: function(frm) {
      frm.add_custom_button(__('Repair Invoice'), function(){
	frappe.route_options = {
		"naming_series": "SINV-REP-",
		"customer": frm.doc.customer,
		"update_stock": true,
		"items": frm.doc.items
	};
	frappe.set_route('Form','Sales Invoice','New Sales Invoice 1');
    }, __("Make"));
  }
});

In case it makes a difference, here are my current settings:
ERPNext: v11.1.35 (master)
ERPNext Support: v0.0.1 (master)
Frappe Framework: v11.1.32 (master)

Thanks for your help!