REST API Production order creation with default BOM

We are creating a simple app to handle operations and part tracking on the floor of a production facility.

We have the API working and can create a new production order by specifying a part number. The problem is, that the production order that is generated does not have the default BOM that has been configured for that item.

Is there something we are doing wrong?

It probably doesn’t populate properly just from the python server-side code. Here’s how it does it in the client side:

https://github.com/frappe/erpnext/blob/develop/erpnext/manufacturing/doctype/production_order/production_order.js#L47

I’d suggest using the api to find the default BOM for the item and plug it in “manually” when first creating the production order. The flag is is_defaultin BOM, so you can just filter for item and is_default, and you should be fine.

Thank you for the information. The odd part is that using the API to create a production order REQUIRES a BOM to be specified, or it generates an error. We have hard coded a valid BOM and that number shows up in the production order on the ERPnext web interface correctly. However, the BOM operations data is not populated.

It looks as though the method: get_items_and_operations_from_bom only gets called through the javascript (client-side) code.

https://github.com/frappe/erpnext/blob/develop/erpnext/manufacturing/doctype/production_order/production_order.py#L419

I don’t think you can call this method from the REST API (it’s not whitelisted), but maybe give it a try anyways. Alternatively, you can create a whitelisted function (in a custom app) that calls this function for your production order before submitting it.

Thanks again! That at least confirms we are doing things correctly and it is a limitation of the API. We are not able to use non-Public methods with the REST API unfortunately. The custom app is probably the easiest workaround. Manually (via code) parsing the BOM for the operations and populating the correct fields in the production order would require overhead that makes it kludgy and impractical.

Is there some way to request a change that makes it possible to tell the operations to be populated from the BOM via the API?

Here is the whitelisted method you’d need. I’ve created a pull request to add it to the core code so you don’t have to use a custom app (but it may take a while to get accepted).

@frappe.whitelist()
def set_production_order_ops(name):
	po = frappe.get_doc('Production Order', name)
	po.set_production_order_operations()
	po.save()

This was merged. Should be out in the next day or so…

https://github.com/frappe/erpnext/pull/9997

Thank you very much for following up! I got pulled away on other projects. I will try it out in the next couple weeks and see if it works for us. We are putting out ERP integration on hold while we develop some other parts of our product.