Restrict UOM Link Field Values in Point of Sale

Hi,

I want to restrict the values in the UOM (Unit of Measure) Link Field in the Sales Invoice Item of the Sales Invoice. Instead of showing all the values from the UOM documents, I only want to display the UOMs that are defined in the Item doctype’s UOM field.

For example, let’s say I have an item called “ABC” with its default UOM set as “Nos” (meaning “Number of Items”). Additionally, the product is also sold in “Boxes”. I have recorded the conversion factor between “Box” and “Nos” in the UOM table within the Item doctype.

Now, when I create a Sales Invoice with the item “ABC” in the items table, I only want the UOM field to show the values “Box” and “Nos”, which are the available UOMs for that particular item.
i found a custom client script to the Sales Invoice doctype n erpnext but its not working please help

frappe.ui.form.on('Sales Invoice', {
    onload: function(frm) {
        // Set the get_query function for the 'uom' field on form load
        frm.fields_dict.items.grid.get_field('uom').get_query = function(doc, cdt, cdn) {
            // Get the current row
            let row = locals[cdt][cdn];

            // Check if the row has uom_list data
            if (uom_lists[cdn]) {
                return { filters: { 'name': ['in', uom_lists[cdn]] } };
            } else {
                // If uom_list data is not available, show all UOMs
                return { filters: { 'name': ['!=', ''] } };
            }
        };
    }
});

let uom_lists = {};

frappe.ui.form.on('Sales Invoice Item', {
    item_code: function(frm, cdt, cdn) {
        let row = locals[cdt][cdn];
        frappe.db.get_doc('Item', row.item_code)
            .then(docs => {
                let uom_list = [];
                docs.uoms.forEach(uom => {
                    uom_list.push(uom.uom);
                });
                uom_lists[cdn] = uom_list;

                // Trigger a refresh of the 'uom' field to apply the updated get_query function
                frm.fields_dict.items.grid.get_field('uom').refresh();
            });
    },
});

please help me with achieving this requirement? Thank you!

Hey @Shuhain_Ismail :wave:

This should already be the standard behavior [1][2].

To investigate further:

  • What version of Dokos do you have installed?
    (Help > About, or bench version -f table)
  • Can you provide a screenshot of the About popup?
  • Can you provide a screenshot of the wrong behavior in your site?
  • “Point of Sale”: are you talking about the POS in Dokos, or just talking about sales documents?

Thanks,
Corentin


  1. It has been the case since two years.

  1. https://gitlab.com/dokos/dokos/-/blob/8e64883d0cbbb93cdf7cce1c1791f302c89cad87/erpnext/public/js/controllers/transaction.js#L249-261
		if (this.frm.fields_dict["items"].grid.get_field("uom")) {
			this.frm.set_query("uom", "items", function(doc, cdt, cdn) {
				const row = locals[cdt][cdn];
				return {
					query: "erpnext.controllers.queries.get_uoms",
					filters: {
						"item_code": row.item_code
					}
				};
			});
		}

@corentin
about

point of sale

sales invoice it show relevant UOM after using Clint script but don’t know how to set to point of sales

in open form view it works with currant code

but not in point of sale view any idea of DocType: it need

Hi @Shuhain_Ismail,

Indeed the default filter is only applied on sales invoices.
I invite you to create an issue on Gitlab if you want to have a similar behavior on the POS interface, as we are not able to track feature requests on the forum unfortunately.

Have a nice day