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){{
			method: "financeiro.financeiro.doctype.titulos.titulos.naming_parcelas",
			args: {
			callback: function(r){console.log(r)}

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
	return purchase_invoice.parcelas

UpdateAfterSubmitError: Not allowed to change Series after submission

Changed “on_submit” event to “before_submit”.