Try ERPNext Buy Support Partners Foundation

Custom calculation for custom fields

Hi

I have created custom field Ammount1 on DocType Sales Order Item which should be quantity multiply by Price list rate

ammount1 = qty*price_list_rate

I tired The following script to give me amount1 value when i’m entering items in sales order item but it doesn’t give me anything:

frappe.ui.form.on(“Sales Order Item”, “ammount1”, function(frm) {
frm.set_value(“ammount1”, frm.doc.price_list_rate * frm.doc.qty);
});

Appreciate any help.

@Elie Your idea is inversed!

The events are raised by qty and price_list_rate, so, if you bind an value into the target field ammount1 it never will be raised.

Another aproach, is use validate event, on main form.

hi @max_morais_dmm,
Can you help me to do it?

Hi, you can try this code:

frappe.ui.form.on('Sales Order Item', {
    qty: function(frm, cdt, cdn){
        var d = locals[cdt][cdn];
        d.amount1 = flt(d.qty) * flt(d.price_list_rate);
        refresh_field('amount1', d.name, 'items');
    },
    price_list_rate: function(frm, cdt, cdn){
        var d = locals[cdt][cdn];
        d.amount1 = flt(d.qty) * flt(d.price_list_rate);
        refresh_field('amount1', d.name, 'items');
    },
})

hi @hendrik_zeta,

It didn’t work!!

Thanks for your helpp

Check his field names against your field names. Looks like you misspelled amount as ammount in your original code.

Hi @cpurbaugh
Yes i checked it but it doesn’t work. any help?

Can anyone help me?

can you add a screenshot so we better understand your issue

is ‘items’ field name in the Sales Order Item?

try to configure it like this: it works with me

frappe.ui.form.on(‘Task’, {
validate: function(frm, cdt, cdn) {
// make calculation on the fields
var b = flt(frm.doc.rate_per_fedden);
var c = flt(frm.doc.treated_area);
var d = flt(frm.doc.work_days_per_week);
var a = b * c * d;
frm.set_value(‘total_quantity’, a);
frm.refresh_field(‘total_quantity’);
}
})

try to configure it like this: it works with me

frappe.ui.form.on(‘Task’, {
validate: function(frm, cdt, cdn) {
// make calculation on the fields
var b = flt(frm.doc.rate_per_fedden);
var c = flt(frm.doc.treated_area);
var d = flt(frm.doc.work_days_per_week);
var a = b * c * d;
frm.set_value(‘total_quantity’, a);
frm.refresh_field(‘total_quantity’);
}
})