ERPNext Conference 2019* ERPNext.com Blog

Quotation Item column computation


#1

I am trying to update the quotation Item Amount to the following logic

Amount = Qty X rate X Area

By the following custom script (doc type quotation)

frappe.ui.form.on("Quotation Item",  'qty',  function(frm, cdt, cdn) {
    var item = locals[cdt][cdn];

item.amount = item.rate * item.qty * item.area;

});

back ground:

  1. The area is a custom field added in quotation item and it directly fetched from a field area in item Master

  2. The rate is a selling rate fetched from item master

  3. qty is entered by user while creating item

Appreciate if anyone can help me out


#2

Hi @srk,

Try the following code;

frappe.ui.form.on("Quotation Item", "qty", function(frm) {
    frm.set_value("amount", flt(frm.doc.qty) * flt(frm.doc.rate) * flt(frm.doc.area));
});

frappe.ui.form.on("Quotation Item", "rate", function(frm) {
    frm.set_value("amount", flt(frm.doc.qty) * flt(frm.doc.rate) * flt(frm.doc.area));
});

frappe.ui.form.on("Quotation Item", "area", function(frm) {
    frm.set_value("amount", flt(frm.doc.qty) * flt(frm.doc.rate) * flt(frm.doc.area));
});

This will update the “amount” field every time when any of the “qty”, “rate”, “area” field values are updated. If your field are child-tables use cdt, cdn as necessary in the code


#3

// Set the amount as a product of area (width X height) , quantity and rate

frappe.ui.form.on("Quotation Item",  'qty',  function(frm, cdt, cdn) {
    var items = frm.doc.items 
    for (var i in items)
    {
        if(items[i].width && items[i].height){
            var rate = flt(items[i].rate) * flt(items[i].width/100) * flt(items[i].height/100)
            // will change the rate accordingly
            frappe.model.set_value(cdt, cdn, "rate", rate)
        }
    }
    
});

Thank you the above code is working, Width and height are taken from item master and on changing the QTY in the quotation form the rate is changed accordingly and also the amount.