Error to receive value

Im trying get values of Purchase Invoice doctype and set them to my custom doctype ‘Titulos’ , but im getting some error when try do a event…
(I tried format the code but this is not working…)

Error when try save(it’s the event to call a function) document:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 56, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 52, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 914, in call
    return fn(*args, **newargs)
TypeError: make_titulo() takes exactly 5 arguments (4 given)

PY:
@frappe.whitelist() def make_titulo(due_date, bill_no, posting_date, supplier_name, company): titulo = frappe.new_doc("Titulos") titulo.naming_series = "TIT-A-PAGAR-" titulo.tipo_de_parte = "Supplier" titulo.tipo_documento = "Purchase Invoice" titulo.data_vencimento = due_date titulo.bill_no = bill_no titulo.data_postagem = posting_date titulo.parte = supplier_name titulo.empresa = company titulo.save() return titulo.name

JS:
frappe.ui.form.on("Purchase Invoice", "validate", function(frm) { $.each(frm.doc.parcelas || [], function(i, d) { // Create titulo frappe.call({ method: "erpnext.accounts.utils.make_titulo", args: { due_date: frm.doc.due_date, bill_no: frm.doc.bill_no, posting_date: frm.doc.posting_date, supplier_name: frm.doc.supplier_name, purchase_invoice: frm.doc.purchase_invoice, bill_date: frm.doc.bill_date, company: frm.doc.company, }, callback: function(r) {r.message} }); console.log(frm.doc.due_date, frm.doc.bill_no, frm.doc.posting_date, frm.doc.supplier_name, frm.doc.company) }); });

Console.log returned:
2017-09-23(due_date) teste123(bill_no) 2017-07-05(posting_date) Broto Legal(supplier_name) Feijuca Brasil(company)

Try this? the fields names and no of arguments should be same I guess

Seems like that works!
But when i try open the document generated, its not loading the page…

Console:
GET XHR http://192.168.0.160/socket.io/ [HTTP/1.1 502 Bad Gateway 1 ms]
ReferenceError: ppe is not defined[Learn More] form.min.js%20line%202528%20%3E%20eval:7:1

can show the console log?

@Leonardo_Augusto

Instead of passing a separate argument. pass it in bunch of args.

as follows. try it

JS:
frappe.ui.form.on("Purchase Invoice", "validate", function(frm) {
	$.each(frm.doc.parcelas || [], function(i, d) {
		frappe.call({
			method: "erpnext.accounts.utils.make_titulo",
			args: {
				"data" : {
					"due_date": frm.doc.due_date,
					"bill_no": frm.doc.bill_no,
					"posting_date": frm.doc.posting_date,
					"supplier_name": frm.doc.supplier_name,
					"purchase_invoice": frm.doc.purchase_invoice,
					"bill_date": frm.doc.bill_date,
					"company": frm.doc.company
				}
			},
			callback: function(r) {
				r.message
			}
		});
	});
});

PY:
@frappe.whitelist()
def make_titulo(data):
	titulo = frappe.new_doc("Titulos")
	titulo.naming_series = "TIT-A-PAGAR-"
	titulo.tipo_de_parte = "Supplier"
	titulo.tipo_documento = "Purchase Invoice"
	titulo.data_vencimento = data.get("due_date")
	titulo.bill_no = data.get("bill_no")
	titulo.data_postagem = data.get("posting_date")
	titulo.parte = data.get("supplier_name")
	titulo.empresa = data.get("company")
	titulo.save()
	return titulo.name

The console log is that what i said

It’s not that, i just take a breakfast and it works…
The framework has a little “delay” to reload my code