TypeError in frappe.call args

Im trying do a call with ajax but this is not working at all…

PY:

    @frappe.whitelist()
    def make_titulo(due_date, bill_no, posting_date, supplier_name, purchase_invoice, bill_date, company=None):
    	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.documento = purchase_invoice
    	titulo.data_emissao = bill_date
    	titulo.empresa = company
    	titulo.save()
    	frappe.db.commit()
    	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
    			}
    		});
    	});
    });
**Error:**
`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 at least 4 arguments (4 given)

edit: format

Could you post your code formatted? You’ll increase the chances of someone helping you since its easier to read.

I don’t know how can i do that

Anybody?

Check values you getting in js of following fields,

due_date, bill_no, posting_date, supplier_name, purchase_invoice, bill_date

As company is your optional field. You passing value of it and missing required one.

Add console.log() to check values in js

I’ll do that, thanks

It’s not showing the value with console.log() in my console…
And the syntax are correctly.

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, }, callback: function(r) {r.message} }); }); console.log(due_date) });

Check if any of the values you are passing is undefined.

console.log(frm.doc)

For example, my model is brazilian date, dd/mm/yyyy. And returned me: 2017-09-23
This will be changed automaticaly or i have to get date format?
If yes i have to ask format, can u tell me how can i do this?
Thank you!