How to enable same UPC barcode in 2 different items

I think not possible,
But i free from workspace then if possible solution then we will provide the script.
Currently not possible.

Thank You!

1 Like

thanks!!

Hi @l4cky,

Here we set the Standard Selling Price in the Valuation Rate field.
Please check the video.

Code:

frappe.ui.form.on('Item', {
	refresh: function(frm) {
		frappe.db.get_value("Item Price", {
            "item_code": frm.doc.item_code,
            "price_list": "Standard Selling"
        }, ['price_list_rate'],
        function (value) {
            if (value.price_list_rate !== undefined) {
                if (frm.doc.valuation_rate === 0 || frm.doc.valuation_rate !== value.price_list_rate) {
                    frm.set_value("valuation_rate", value.price_list_rate);
                }
            }
        });
	}
});

If comfortable with it then use it.

Thank You!

1 Like

Hello,

Where can I copy paste this script (which section)?

Please check it.

Thanks!

This is wonderful, I just replaced the valuation_rate field with a new field called: rate_fetch_from_standard_selling_price_list and as expected, the field is not editable and will not save unless we go to standard price list.

@NCP

Thank you! such a great help for the entire thread! Couldn’t have done it without you Sir!

Do you know if we update ERPNext version, or bench update, bench backup, bench restore commands will be able to save the added fields and client script we modified?

Hi @l4cky,

When you update the erpnext then it does not affect customization like (Custom Field, Server Script, or Client/Custom Script.)

Keep one thing in mind when you update the erpnext first take a backup.
Okay.

Have a good day!
Thank You!

1 Like

Hi @NCP

Thank you.

I have a small problem with currency decimal using the script and occurs in print format, the 0 at the end of the rate is missing.

In my client script

frappe.ui.form.on('Item', {
	refresh: function(frm) {
	    set_css(frm);
		frappe.db.get_value("Item Price", {
            "item_code": frm.doc.item_code,
            "price_list": "Standard Selling"
        }, ['price_list_rate'],
        function (value) {
            if (value.price_list_rate !== undefined) {
                if (frm.doc.rate_fetch_from_standard_selling_price_list === 0 || frm.doc.rate_fetch_from_standard_selling_price_list !== value.price_list_rate) {
                    frm.set_value("rate_fetch_from_standard_selling_price_list", value.price_list_rate);
                }
            }
        });
	}
});

var set_css = function (frm)
    {
    document.querySelectorAll("[data-fieldname='rate_fetch_from_standard_selling_price_list']")[1].style.height ="25px";
    document.querySelectorAll("[data-fieldname='rate_fetch_from_standard_selling_price_list']")[1].style.width ="70px";
    document.querySelectorAll("[data-fieldname='rate_fetch_from_standard_selling_price_list']")[1].style.color ="black";
    document.querySelectorAll("[data-fieldname='rate_fetch_from_standard_selling_price_list']")[1].style.backgroundColor ="yellow";
    }

In item master, I have created a new field for the fetched rate:

So far everything works.


But in the print format, then I use the code

      <div class="label-item-price label-field">
          {{ frappe.get_doc('Item Price', item_code).price_list_rate }}
      </div>

The price displayed is all good but ONLY WHEN it has a 0 at the end, it removes it.

So If the price is 1.17 → It will show 1.17 (Good)
So If the price is 0.07 → It will show 0.07 (Good)
But If the price is 1.00 → It will show 1.0 (missing a 0 at the end)
But If the price is 1.10 → It will show 1.1 (missing a 0 at the end)

Do you know how and where I can fix the 0 missing at the end?

Thank you!

Hi @l4cky,

Please check it whole post regarding jinja rounding.

Thank You!

{{ "{:,.2f}".format(frappe.get_doc('Item Price', item_code).price_list_rate) }}

Yes, it works super well! thank you!! @NCP