Get "Total Item Stock" at Item List in ERPNext

This development in ERPNext you will find very simple but its really helpful to the end users of ERPNext.

 · 1 min read

We have taken "Bin Qty: into " Item Master "Total Stock" field and then fetched to item list view.



Client Script:



Here is the script:

frappe.ui.form.on('Item', {

  refresh(frm) {

    if (frm.doc.item_code) {

      fetch_total_stock(frm);

    }

  },

  item_code(frm) {

    fetch_total_stock(frm);

  },

  onload(frm) {

    // Center align the custom_total_quantity field if it exists

    if (frm.fields_dict['custom_total_quantity']) {

      frm.fields_dict['custom_total_quantity'].$wrapper

        .find('input')

        .css('text-align', 'center');

    }

  }

});


function fetch_total_stock(frm) {

  frappe.call({

    method: "frappe.client.get_list",

    args: {

      doctype: "Bin",

      filters: {

        item_code: frm.doc.item_code

      },

      fields: ["actual_qty"]

    },

    callback: function (response) {

      if (response.message) {

        let total_qty = response.message.reduce((sum, bin) => sum + bin.actual_qty, 0);


        let current_qty = parseFloat(frm.doc.custom_total_quantity || 0).toFixed(2);

        let new_qty = parseFloat(total_qty).toFixed(2);


        if (current_qty !== new_qty && frm.fields_dict['custom_total_quantity']) {

          frm.set_value("custom_total_quantity", total_qty);

          frm.save(); // Auto-save

        }

      }

    }

  });

}



Satish Aralkar

Satish Aralkar (Founder – Vedarth Solutions) is SAP consultant having 15 years of SAP implementation and 12 years of Domain experience in manufacturing domain. Currently working on ERPNext implementations, Automation and Digital Transformation.

No comments yet.

Add a comment
Ctrl+Enter to add comment