how to set a floor price (using custom script)

Use the following code in the Custom Script section for Sales Order Form/Doctype.

The logic is that it will run the code during the validation stage, or just right after user attempts to save the form. In this case, the form is the Sales Order. The code then runs a for loop to check if the price is below a certain price (1000 in this example) and at the same time is of a specific item code. If both conditions are met, then a message will be shown to the user via the msgprint command. The save is not continued due via the frappe.validated=false command.

   frappe.ui.form.on('Sales Order', 'validate', function(frm) {
      for(var i=0;i < cur_frm.doc.items.length; i++){
        if(cur_frm.doc.items[i].rate < 1000 && cur_frm.doc.items[i].item_code == 'WIDGET001'){
          msgprint('Price is below floor price! Please seek approval.');
          frappe.validated=false;
        }
      }
    });