Problem with material request api calling

I have added custom js and button(MR) on production order page. When we click on t ‘MR’ button then below ajax will call but I am not getting blank data parameter.
I am checking data parameter in this url : https://github.com/frappe/frappe/blob/develop/frappe/api.py (line 115)

frappe.call({
‘url’: ‘api/resource/Material Request’,
‘type’:‘POST’,
‘data’: JSON.stringify({data:{first_name : “John”}}),
‘callback’: function® {
alert()
}
});

You are not setting the correct URL for your frappe call. I’m also not at all clear what you are trying to do with your call? Create a material request maybe?

If so, you don’t need to use python to do that, just javascript. frappe.new_doc('Material Request'); should work I think.

Can you explain more clearly what you are trying to do?

@Ben_Cornwell_Mott

  1. I have added ‘Plan or Revise’ button on on production order page for sending ‘Material Request’.
  2. When we click ‘Plan or receive’ button then ‘MR’ request will send for selected items.

I have written above code for ajax calling for ‘MR’.

I am getting this error when we click on ‘Plan or Revise’ button:
Traceback (most recent call last):
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/api.py”, line 115, in handle
data = json.loads(frappe.local.form_dict.data)
File “/usr/lib/python2.7/json/init.py”, line 339, in loads
return _default_decoder.decode(s)
File “/usr/lib/python2.7/json/decoder.py”, line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python2.7/json/decoder.py”, line 382, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded

This is happening because you do not have the correct url.

Have you created a python function that will create these Material Requests? You need something that will take the data (and you need to pass the data for the rows you have checked off) and create material requests for them. You need to either do that with a server side script or write something in Javascript (I’m not 100% sure you can do it in javascript).

Simply calling the REST API function with the frappe.call method will not do anything in this case.

@Ben_Cornwell_Mott Can you explain below point briefly

Simply calling the REST API function with the frappe.call method will not do anything in this case.

frappe.ui.form.on(“Production Order”, “plan_or_revise”, function(frm) {
frappe.call({
// doc: frm.doc,
method: “erpnext.manufacturing.doctype.production_planning_tool.production_planning_tool.raise_material_requests”,
doc: frm.doc,
});
});
Traceback (most recent call last):
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/handler.py”, line 52, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/init.py”, line 907, in call
return fn(*args, **newargs)
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/handler.py”, line 80, in runserverobj
frappe.desk.form.run_method.runserverobj(method, docs=docs, dt=dt, dn=dn, arg=arg, args=args)
File “/windows/sapconproject/frappe-bench/apps/frappe/frappe/desk/form/run_method.py”, line 33, in runserverobj
fnargs, varargs, varkw, defaults = inspect.getargspec(getattr(doc, method))
AttributeError: ‘ProductionOrder’ object has no attribute ‘erpnext.manufacturing.doctype.production_planning_tool.production_planning_tool.raise_material_requests’

Calling a function which is defined inside a Class of another doctype is not possible via frappe.call. You can only call whitelisted functions (and outside Class) of other doctypes.

Thanks for reply