ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Issue with the arguments of a Python function when it is called



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:


Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 62, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 53, in execute_cmd
    return, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", 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)
                fieldtype: "Float",
                label: __("Qty for {0}", [purpose]),
                fieldname: "qty",
                description: __("Max: {0}", [max]),
                'default': max
            function (data)
                    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:

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
        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
        stock_entry.from_warehouse = work_order.wip_warehouse
        stock_entry.fg_warehouse   = work_order.fg_warehouse

    return stock_entry.as_dict()

I think all is right, so I do not know why I get this error.


Does anyone know how to approach this?


Try this:

Instead of qty=None take qty=0. I’m assuming qty means quantity in the context of a regular stock transaction


Thanks for your answer.
It makes sense what you say, but still it keeps returning the same error.


“qty”: data.qty

this is some times none so make sure it must have some value when its none

you can try this

“qty”: data.qty ? data.qty:0


That error gets thrown when you’re not passing some of the mandatory arguments.

In your case, either the document name, or the purpose is not getting passed to the function. Might be a possible bug.

What version are you on, @vazdan?


@root13Fk your issue is because frm.doc.docname, it should be frm.docname or


I have changed "qty": data.qty by "qty": data.qty ? data.qty : 0 and I tried to use frm.docname and instead of frm.doc.docname, and now I get the error 404 (NOT FOUND) related to the Doctype.


ERPNext version: 10.1.18
Frappé version: 10.1.16


I receive 404 error (NOT FOUND) with the message: The resource you are looking for is not available, but I do not know what may be failing.

In the .PY code, when it reaches the frappe.get_doc() function, it can not find the current Doctype, but if I execute the frappe.get_doc() function from the web browser console, it returns all the fields and information about the Doctype.

def make_stock_entry(work_order_id, purpose, qty=0):
    work_order = frappe.get_doc("Work Order", work_order_id)

From the web browser console, I tried this:

frappe.get_doc("Work Order", "WO-008")

and also this:

frappe.get_doc(cur_frm.doctype, cur_frm.docname)

and in both cases everything is executed in the correct way.

What can I do?


I can not find a way to do this


Could someone help me with this problem?