To Validate that Rate Is Not Less Than Price List Rate if Update Stock Is Checked

Hi,

I added below Client Script to validate Rate in Sales Invoice is not less than Price List Rate, but I want to add a condition to run this validation if Update Stock is checked. How to do that?

frappe.ui.form.on("Sales Invoice", "validate", function(frm){
  $.each(frm.doc.items, function(idx, item){
     if(item.price_list_rate > item.rate) {
       msgprint(__("Rate of " + item.item_name + "  cannot be less than Price List Rate"));
       validated = false;
  } 
});
});

Is there someone who can help?

Just put the loop inside an if.

if (frm.doc.fieldname) {
    Your loop here
}

Use appropriate fieldname.

Thank you but could you please help to add it in my script. I have a little experience in coding.

The condition I would like to add if doc.update_stock=1

frappe.ui.form.on(“Sales Invoice”, “validate”, function(frm){
if (frm.doc.update_stock){
$.each(frm.doc.items, function(idx, item){
if(item.price_list_rate > item.rate) {
msgprint(__(“Rate of " + item.item_name + " cannot be less than Price List Rate”));
validated = false;
}
}
});
});

1 Like