Child Item reference to Parent BOM

Consider

Item: Computer.
All computers are assembled inhouse.

Computer BOM
a. HDD-001
b. RAM-003
c. MotherBoard-002

Now lets assume that I have only Computers in stock at this point.

So lets say some customer wants to buy RAM-003 immediately. But I dont have it in stock. But since the computers have RAM-003 in them, I can extract it and sell it.

But the problem is finding this item in stock. Stock Balance will show it as 0. So I have to go to BOM search and search RAM-003, which will show a list of parent BOMs that has this item as child. Then I have to go the parent BOM and find the item for this BOM and then check if the Item is in stock. If it is, then break it up in child units and then make the sale.

This is very confusing for a non technical person.

Is there a better way of doing this. What I would expect is to, when searching a child item, it should show up which item it is associated to. But there doesnt seem to be a way to do that.

I tried adding a BOM column to the stock balance ledger, but that doesn’t help.

Have any one been in this situation and found a solution to this ?

Hi:

This could be a valid approach …

Create a client script for Item doctype, and paste this code:

frappe.ui.form.on('Item', {
    
   refresh: function(frm) {
  
    frm.add_custom_button(__('Show BOM Parent Items'), function(){
      get_parent_items(frm);
    }, __("View"));
    
  },
});

function get_parent_items(frm){
   parent_items = frappe.db.get_list('BOM', {
        fields: ['item', 'description'],
        filters: [["BOM Item", "item_code", "=", frm.doc.item_name]],
        as_list: 1
    }).then(function(res){

        let data = frappe.utils.dict(["item", "description"], res)
        console.log(data)
        const table_fields = [
        {
            fieldname: 'item',
            fieldtype: 'Link',
            in_list_view: 1,
            label: 'Item Code',
            options: 'Item',
            read_only: 1
        },
        {
            fieldname: 'description',
            fieldtype: 'Data',
            in_list_view: 1,
            label: 'DescripciĂłn',
            reqd: 1
        },
        ]

        let err_dlg = new frappe.ui.Dialog({
            title: 'BOM containing item: ' + frm.doc.item_name,
            fields: [
                
                {
                    label: 'Items',
                    fieldname: 'customs_errors',
                    fieldtype: 'Table',
                    fields: table_fields,
                    options: 'Item',
                    cannot_add_rows: 1,
                    cannot_delete_rows : 1,
                    data: data
                },
            ],
            primary_action_label: 'Close',
            primary_action(values) {
                err_dlg.hide();
             }
        })
    
        err_dlg.show();  
    }
)}

This client script adds a button, and shows a dialog with all the “parent” items … each item row links directly to the item doctype so you can check stock avaliability, etc …

Even is possible to get the current stock and showing it in dialog with a little bit deeper customization. But you can found a lot of different situations … (wich warehouse, stock reservations, etc…)

Hope this helps.

2 Likes