Validation of Rate Not Less Than Price List Rate

Hi,

I would like to validate that Item Rate in Sales Invoice is not less than Item Price in Master (not Price List Rate fetched in Sales Invoice Item table) according to Default Price List set in Customer Group under which the customer is added. So, I added the following code:

    frappe.ui.form.on("Sales Invoice", "validate", function(frm){
    $.each(frm.doc.items || [], function(i, row){
        if(frappe.db.get_value('Item Price',{'batch_no': row.batch_no, 'item_code': row.item_code, 'price_list_rate': frappe.db.get_value('Customer Group', frappe.db.get_value('Customer', frm.doc.customer, 'customer_group'), 'default_price_list')}, 'price_list_rate') > row.rate) {
            msgprint(__("Rate of " + row.item_name + " cannot be less than Price List Rate"));
            validated = false;
            
        }
  });
});

But, unfortunately, it doesn’t work. Where is the wrong in the code? Can someone help in this respect?

@ahmed.sharaf

You Can Try With This Code

frappe.ui.form.on(“Sales Invoice”, “validate”, function(frm, cdt, cdn) {
$.each(frm.doc.items || [], function(i, d) {
console.log(d.price_list_rate);
console.log(d.rate);
console.log(d.item_name);
if(d.price_list_rate > d.rate) {
msgprint(“Price for Item : “+d.item_name+” is not acceptable.”);
validated = false;
}
})
});

Thank you but assume that price list rate is not fetched or the price list rate in master has been changed after creating the sales invoice (before submitting) therefore I cannot count on price list rate and I added below code to compare the item price list rate based on the default price list in customer group.

Hi can someone help?