BOM is not set to custom Doctype

Let’s see, I have a custom Doctype that is a duplicate of the Production Order, but with some fields modified. When I select an Item or a quantity for manufacturing, the BOM that corresponds to the selected Item must be automatically assigned, but, instead, the following error occurs:

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 (method, ** frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 939, in call
    return fn (* args, ** newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 81, in runserverobj
    frappe.desk.form.run_method.runserverobj (method, docs = docs, dt = dt, dn = dn, arg = arg, args = args)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/", line 34, in runserverobj
    fnargs, varargs, varkw, defaults = inspect.getargspec (getattr (doc, method))
AttributeError: 'Document' object has no attribute 'erpnext.manufacturing.doctype.ot_gran_formato.ot_gran_formato.get_items_and_operations_from_bom'

In fact, the appropriate BOM is assigned to the BOM field, but the error occurs and does not load the list of material required in the table for the Item to be manufactured.

The code in the JS file related to the BOM event is as follows:

bom_no: function (frm) {
    return ({
        method: "erpnext.manufacturing.doctype.ot_gran_formato.ot_gran_formato.get_items_and_operations_from_bom",
        doc: cur_frm.doc,
        freeze: true

How can I fix this? I’ve been stuck for a long time and I need this to work.
Thanks in advance!

PS: In PY file the function get_items_and_operations_from_bom is not whitelisted.

Any suggestions?

I would be grateful that someone could help me.

Please check if this help in your case.

Thanks for your answer @Salmanmulani!

I am not sure I understood the function add_fetch();.
In the example, a custom field called vat_id is used, which is found in both the Customer and Sales Invoice doctypes.
Then, through the customer field, which is also in both doctypes, the information is updated in the field vat_id, in both doctypes, am I wrong?

That is, the information in the vat_id field in the doctype Customer is placed in the vat_id field in the doctype Sales Invoice.

I try this code in custom Script:

frappe.ui.form.on("OT Gran Formato",
	item_name: function (frm, cdt, cdn) {
		if (frm.doc.item_name)
			cur_frm.add_fetch('item_name', 'default_bom', 'bom_no');

	qty: function (frm, cdt, cdn) {
		if (frm.doc.qty && frm.doc.production_item)
			cur_frm.add_fetch('item_name', 'default_bom', 'bom_no');

It works correctly as far as inserting the correct BOM is concerned, the only thing I would need is to be able to extract the items and the operations from BOM to insert them in the table of required items.

My goal is to perform the same function as the doctype Production Order, the function of inserting to BOM, extract the required operations and items, and be able to make a material transfer for the material created and the articles used for it.