Purchase Order UOM research

So, with my problems with units of measure in ERPnext, I have been doing some research, trying to learn more about how the underlying system works. So, what I’ve found:

  • The unit of measure can be decided in the Purchase Order Item doctype
  • The way to select the desired UOM is a link field, that shows all available UOMs.
  • When the desired UOM is selected, the conversion rate is shown on a ‘float’ type field.
  • I cannot figure out how this field pulls from the item master.
  • This changes the ‘stock_qty’ field as a multiplication of stock uom * conversion factor.
  • I can’t figure out how this calculation is made. The purchase_order_item.json file gives me no clues.
  • If the rate field can be a similar calculation, stock UOM rate*conversion factor, then this would fix the issue of the price not updating. However, I am unable to find the underlying math for these calculations.
1 Like

here is code for Purchase UOM
https://github.com/frappe/erpnext/blob/develop/erpnext/buying/doctype/purchase_common/purchase_common.js#L91

 qty: function(doc, cdt, cdn) {
        this._super(doc, cdt, cdn);
        this.conversion_factor(doc, cdt, cdn);
    },

    conversion_factor: function(doc, cdt, cdn) {
        if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
            var item = frappe.get_doc(cdt, cdn);
            frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
            item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
            refresh_field("stock_qty", item.name, item.parentfield);
        }
    },

If you need rate calculation, you can do this using custom script.