Creating doctype object from dictionary object


I am making some custom changes to stock_entry object in my app(basically updating item quantity). In order to do that, I have used make_stock_entry() API from However that function returns the object in dictionary format, which doesn’t let me call stock_entry class methods. Is there any method that does the reverse of as_dict() function? A quick search didn’t show me any relevant methods.


make_stock_entry method in production order is used to make a new Stock Entry from Production Order.
The document is not saved.

This method is called from production_order.js and the page is rerouted to New Stock Entry 1 with predefined values.

You can try the following in javascript:
in the callback of the,

callback: function(r) {
    var doc = frappe.model.sync(r.message)[0];
    // doc is your document obj

reference: production_order.js

Actually I did not quite understand what you wanted to achieve. I gave a way to have doc obj.
Hope it helps

1 Like

Thanks @fahimalizain,

Perhaps I should have been little more explicit in my question. I am building a custom production order to make the process easy to use for our usecase. It takes some additional inputs which can’t be captured directly in BOM. Based on that, we create the stock entry. The base stock entry is created using make_stock_entry() method and then I update the raw material quantity for some specific items. Once that is done, I want the calculations updated automatically by calling stock_entry.calculate_rate_and_amount(). I am doing all these processing in python rather than javascript, so looking for a function that would create the stock_entry from as_dict object in python. Looks like your suggestion would work if I was doing this in javascript. Please let me know if there is any similar option in python.


Hi @spoojary

I just went into bench console and checked the contents of the returned doc dict. It doesnt have name set, that means there is no local doc cache from which you could get it.

Javascript with frappe.model.sync takes the items into a new doc object assigning the name New Stock Entry 1 which we can access by locals[cdt][cdn].

I suggest you to make a copy of the same method in your app, and dont return as a dict- this will be the most efficient solution I guess, everything else will be simply too much work for your simple problem.

Thank you

1 Like

Thanks @fahimalizain,

I have already refactored the function make_stock_entry() to return both object and as_dict. However that is a change to erpnext, which needs to be accepted by frappe team. Copying the entire function is another option, but not an elegant one. However, as you mentioned, it might be the pragmatic option for my current problem.

I managed to find the way to convert as_dict object back to doctype object in python.

stock_entry = make_stock_entry(, "Manufacture", qty)
se = frappe.new_doc("Stock Entry")
1 Like