Item valuation rate not linked to bom valuation rate

When reading through the forum this topic is mentioned countless times but seems there is no fix or answer for the last 9 years. please help me understand if I am at fault.

  1. My Item-A is linked to a BOM.
  2. The BOM can calculate the manufacturing cost correctly.
  3. When does the BOM evaluation rate pull through to the item-A?
    4.Valuation rate always stays 0

+1 I am also totally puzzled by this.

In my case, I want to transfer stock, and transferring needs a valuation >0.
(No, I can’t check the checkbox to allow valuation==0, because the checkbox is deactivated)
Manually editing the valuation of the Item-A is error-prone as hell.

Would there be at least a script to run regularly to set an item’s valuation to the cost of its BOM?

To reduce my pain with this, I added a button next to the item’s valuation field, that updates the field value from the BOM. It’s quick and dirty hack with a little help from AI. But at least this one click is faster than looking up the BOM cost to copy-and-paste the value…

Create a new “Client Script”
for the DocType: “Item”
(Apply to “Form”)

frappe.ui.form.on('Item', {
    refresh: function(frm) {
        if (frm.fields_dict.valuation_rate) {
            // Wrapper fĂĽr Feld und Button auf Flexbox umstellen
            let $wrapper = $(frm.fields_dict.valuation_rate.wrapper).css({
                "display": "flex",
                "align-items": "center"  // Sorgt fĂĽr vertikale Ausrichtung
            });

            // Eingabefeld verkleinern
            $wrapper.find("input").css({
                "flex": "1",
                "height": "30px"  // Falls notwendig, gleiche Höhe setzen
            });

            // Button mit passender Höhe erstellen
            let $btn = $('<button class="btn btn-primary btn-sm" style="margin-left: 5px; height: 30px; line-height: 15px;">Update from BOM</button>')
                .click(function() {
                    calculate_bom_cost(frm);
                });

            // Button ins Wrapper-Element einfĂĽgen
            $wrapper.append($btn);
        }
    }
});

function calculate_bom_cost(frm) {
    frappe.call({
        method: "frappe.client.get_value",
        args: {
            doctype: "BOM",
            filters: { item: frm.doc.name, is_active: 1, is_default: 1 },
            fieldname: "total_cost"
        },
        callback: function(r) {
            if (r.message) {
                let bom_cost = r.message.total_cost || 0;
                
                // Wert in das Feld setzen
                frm.set_value("valuation_rate", bom_cost);
                
//                frappe.msgprint(`BOM-Kosten aktualisiert: ${bom_cost}`);
            } else {
                frappe.msgprint("No active default BOM was found.");
            }
        }
    });
}

“Works for me”:tm:

1 Like

hi @rabrab
this actually works brilliantly.
thanks. there is a refresh issue, but im sure i will get that fixed.
you are a star