TypeError: method() takes exactly 3 arguments (0 given)

Im trying test a call of my method.

frappe.ui.form.on(“Purchase Invoice”, “validate”, function(frm) {

JS
// For each Parcela
$.each(frm.doc.parcelas || [], function(i, d) {

  // Create titulo
  frappe.call({
method: "erpnext.accounts.utils.make_titulo",
args: {},
callback: function(r)
console.log("worked")

});
});
});

PY
@frappe.whitelist()
def my_method():
pass

Traceback: TypeError: make_titulo() takes exactly 3 arguments (0 given)

@Leonardo_Augusto,

can you share the make_titulo method code? the error indicates that the method requires 3 variables

@frappe.whitelist()
def make_titulo(valor, vencimento, nota):
titulo = frappe.new_doc(“Titulos”)
titulo.naming_series = “TIT-A-PAGAR-”
titulo.empresa = doc.company
titulo.data_postagem = doc.posting_date
titulo.vencimento = doc.vencimento
titulo.tipo_de_parte = “Supplier”
titulo.parte = doc.supplier
titulo.valor_total = doc.valor
titulo.tipo_documento = “Purchase Invoice”
titulo.documento = doc.name
titulo.data_emissao = doc.bill_date
titulo.bill_no = doc.bill_no
titulo.save()
return titulo.name

Im fine, the problem was js code

Is it working now?

Try this,

In JS

// For each Parcela
$.each(frm.doc.parcelas || [], function(i, d) {
	// Create titulo
	// assuming valor, vencimento, nota, posting_date, supplier_name, purchase_invoice, bill_date, bill_no, company are fields on doctype
	frappe.call({
		method: "your_app.path.to.make_titulo",
		args: {
			valor:frm.doc.valor, 
			vencimento:frm.doc.vencimento, 
			nota:frm.doc.nota,
			posting_date: frm.doc.posting_date,
			supplier_name:frm.doc.supplier_name, 
			purchase_invoice:frm.doc.purchase_invoice, 
			bill_date:frm.doc.bill_date, 
			bill_no:frm.doc.bill_no, 
			company:frm.doc.company,
		},
		callback: function(r)
			console.log("titulo name", r.message);
		}); 
	});
});

frappe.call documentation https://frappe.github.io/frappe/user/en/guides/basics/frappe_ajax_call

In your_app.path.to.py add

@frappe.whitelist()
def make_titulo(valor, vencimento, nota, posting_date, supplier_name, purchase_invoice, bill_date, bill_no, company=None):
	titulo = frappe.new_doc("Titulos")
	titulo.naming_series = "TIT-A-PAGAR-"

	# This will take default company
	titulo.empresa = company or frappe.defaults.get_defaults().get("company") 

	titulo.data_postagem = posting_date
	titulo.vencimento = vencimento
	titulo.tipo_de_parte = "Supplier"
	titulo.parte = supplier_name
	titulo.valor_total = valor
	titulo.tipo_documento = "Purchase Invoice"

	#Purchase Invoice docname
	titulo.documento = purchase_invoice 

	titulo.data_emissao = bill_date
	titulo.bill_no = bill_no
	titulo.save()

	frappe.db.commit()

	return titulo.name
1 Like

Actually it was not, I was generating documents without taking values​​…
Perfect example!!
Thank you for reply, i’ll try now!

I got this when i tried execute the function…

      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 50, in execute_cmd
is_whitelisted(method)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 72, in is_whitelisted
raise frappe.PermissionError(‘Not Allowed, {0}’.format(method))
PermissionError: Not Allowed, <function make_titulo at 0x7f78f09ca140>

Solved this, i forget to declare @frappe.whitelist()

I commented the lines to test the function and returned:

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 6 arguments (5 given)

PY:
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()
return titulo.name

JS:
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,
},

I deleted the company arg and parameter:

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.save()
return titulo.name

JS:
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,
},

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 6 arguments (6 given)

Close this topic, i created another one: