Hmm
,
You can use to update your custom field for calculating the Unit Production Cost of a BOM:
frappe.provide("frappe.model");
frappe.ui.form.on("BOM", {
// This function is called whenever the Total Cost field is updated
total_cost: function(frm, cdt, cdn) {
// Get the total cost and quantity from the BOM
var total_cost = frm.doc.total_cost;
var qty = frm.doc.qty;
// Calculate the unit production cost
var unit_production_cost = total_cost / qty;
// Set the value of your custom field
frappe.model.set_value(cdt, cdn, "unit_production_cost", unit_production_cost);
}
});
With this script, your custom field for the Unit Production Cost should be updated automatically every time the Total Cost field is updated, whether it’s done manually or through a scheduled task.
I hope this helps.
Thank You!