I have some Doctypes in a custom App. One of them work as Production Order. In that Doctype, when I click on the Start button to make a material transfer, I get an error, which is the following:
500 (INTERNAL SERVER ERROR)
Traceback (most recent call last):
File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
response = frappe.handler.handle()
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
return fn(*args, **newargs)
TypeError: make_stock_entry() takes at least 2 arguments (2 given)
This is the Javascript code that triggers the function:
frappe.ui.form.on("Work Order", "refresh", function (frm)
{
if (frm.doc.docstatus === 1 && frm.doc.status != 'Stopped')
custom_app.make_se(frm, "Material Transfer for Manufacture");
});
custom_app = {
make_se: function (frm, purpose)
{
frappe.prompt(
{
fieldtype: "Float",
label: __("Qty for {0}", [purpose]),
fieldname: "qty",
description: __("Max: {0}", [max]),
'default': max
},
function (data)
{
frappe.call({
method: "custom_app.work_order.doctype.work_order.work_order.make_stock_entry",
args: {
"work_order_id": frm.doc.docname,
"purpose": purpose,
"qty": data.qty
},
callback: function (r)
{
var doclist = frappe.model.sync(r.message);
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
}
});
}, __("Select Quantity"), __("Make"));
}
}
This is the Python code where I defined the function:
@frappe.whitelist()
def make_stock_entry(work_order_id, purpose, qty=None):
work_order = frappe.get_doc("Work Order", work_order_id)
if not frappe.db.get_value("Warehouse", work_order.wip_warehouse, "is_group"):
wip_warehouse = work_order.wip_warehouse
else:
wip_warehouse = None
stock_entry = frappe.new_doc("Stock Entry")
stock_entry.purpose = purpose
stock_entry.production_order = work_order_id
stock_entry.from_bom = 1
stock_entry.bom_no = work_order.bom_no
stock_entry.fg_completed_qty = qty or (flt(work_order.qty) - flt(work_order.produced_qty))
if purpose == "Material Transfer for Manufacture":
stock_entry.to_warehouse = wip_warehouse
else:
stock_entry.from_warehouse = work_order.wip_warehouse
stock_entry.fg_warehouse = work_order.fg_warehouse
stock_entry.get_items()
return stock_entry.as_dict()
I think all is right, so I do not know why I get this error.