I have some Doctypes in a Custom App. One of them will work as a Production Order, and I need to call the functions stop_unstop
and make_stock_entry
from Production Order.
How can I do this?
In the case that I have to create my own functions and then call them from my Custom Doctype, how should I do it?
First I tried this JS function:
frappe.ui.form.on("Work Order", "refresh", function (frm)
{
if (frm.doc.docstatus === 1)
custom_app.stop_work_order(frm, status);
});
custom_app = {
stop_work_order: function (frm, status)
{
frappe.call({
method: "custom_app.orders.doctype.work_order.work_order.stop_unstop",
args: {
work_order: frm.doc.name,
status: status
},
callback: function (r) {
if (r.message) {
frm.set_value("status", r.message);
frm.reload_doc();
}}
});
}
}
Then I tried this:
frappe.ui.form.on("Work Order", "refresh", function (frm)
{
if (frm.doc.docstatus === 1)
custom_app.stop_work_order(frm, status);
});
custom_app = {
stop_work_order: function (frm, status)
{
frappe.call({
type: "POST",
args: {
work_order: frm.doc.name,
status: status
},
url: "/api/method/work_order/POST?run_method=stop_unstop",
callback: function (r) {
if (r.message) {
frm.set_value("status", r.message);
frm.reload_doc();
}}
});
}
}
The PY code is this:
@frappe.whitelist()
def stop_unstop(work_order, status):
w_order = frappe.get_doc("Work Order", work_order)
w_order.update_status(status)
w_order.update_planned_qty()
frappe.msgprint(_("Work Order has been {0}").format(status))
w_order.notify_update()
return w_order.status
Always I received the message error 404 (NOT FOUND).
P.S.: I already visited the following links without success: