Not allowed to change after submit

Parcelas is a child table linked on purchase invoice and serie_parcela(label: Series) is a read only field. When i submit the document, i need that receive the i variable value, but it’s not working.

frappe.ui.form.on("Purchase Invoice", "on_submit", function(frm){
		frappe.call({
			method: "financeiro.financeiro.doctype.titulos.titulos.naming_parcelas",
			args: {
				doc_name: frm.doc.name,
			},
			callback: function(r){console.log(r)}
		});
});

@frappe.whitelist()
def naming_parcelas(doc_name):
	purchase_invoice = frappe.get_doc("Purchase Invoice", doc_name)
	i = 0
	for d in purchase_invoice.parcelas:
		d.serie_parcela = i
		i += 1
	purchase_invoice.save()
	return purchase_invoice.parcelas

UpdateAfterSubmitError: Not allowed to change Series after submission

Solved!
Changed “on_submit” event to “before_submit”.