Error in Function Argument

Hi Everyone,

I am trying to create a function but I am receiving error related to arguments passed to it.

I appreciate, if anyone can let me know what I did wrong in this:

Python Code:

def uom_conversion_factor(item_code, uoms):
    i=frappe.db.sql("""select distinct conversion_factor from `tabUOM Conversion Detail` where parent=%s and uom!=%s limit 1""", (item_code,uoms))
    frappe.msgprint(i[0][0]);
    if i[0][0]!=0:
	return i[0][0]
    else:
	return 0

Javascript Code:

frappe.ui.form.on("Supplier Quotation Item","purchase_uom", function(frm, cdt, cdn) { 
var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);
var data =  {
	    "item_code": d.item_code,
            "uoms": d.purchase_uom
           };
	    frappe.call({
                       method: "library_management.conversion_details.uom_conversion_factor",
	                args: data, 
                       callback: function(r) 
                      {  
                        if(r.message) 
                        {
                         
                        frappe.model.set_value(cdt, cdn, "conversion_factor", r.message);
                        }
                      }
});
cur_frm.refresh_fields();
});

Hi @ruchin78

add the parent and uom value in quotes like where parent='%s' and uom!='%s' may be this is causing error.

Can you share the error traceback ?

Thanks, Makarand

@makarand_b

I did that but it is still showing the same error.
Apart from that, I just want to say that my earlier functions are not using any quote for the same and are working fine.

Regards
Ruchin Sharma

@ruchin78 can you share the traceback ?

@makarand_b

Here is the traceback, however I did change the name of the function by thinking that it may resolve the problem.

Traceback (innermost last):
File “/home/vishnu/frappe-bench/apps/frappe/frappe/app.py”, line 57, in application
response = frappe.handler.handle()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 806, in call
return fn(*args, **newargs)
TypeError: check_uom() takes exactly 2 arguments (1 given)

@ruchin78 If check_uom is defined is class the first parameter must be ‘self’ like

def check_uom(self,uom):

@gangadhar_k
It is resolved now, actually the problem was conflicting of 2 arrays therefore it was passing an undefined to the function.

However, my code was perfect.

Regards
Ruchin Sharma