While duplicating a doctype , amount is not calculating automatically

While duplicating a doctype , amount is not calculating automatically

Any update???

Thanks in Advance

You’ll have to give us more details. Tell us step wise what exactly you were doing, what you were expecting and what you got instead. Also show us any custom python or javascript code you may have written in order to get this done.

Hi

In Quotation , i duplicated the ‘Quotation Item’ Doctype as " Optional accessories " in the same Quotation Page. And it works fine.

But while choosing the item Rate is populating but the Amount is not calculated as based on the Rate and Qty. Its displaying zero

i tried using this code , still its not working

frappe.ui.form.on("Optional Accesories", {
        validate: function) frm) {
        frm.trigger("calculate_amount")
    },
    qty: function(frm) {
        frm.trigger("calculate_amount")
    },
    rate: function(frm) {
        frm.trigger("calculate_amount")
    },
    calculate_amount: function(frm) {
        if (frm.doc.qty && frm.doc.rate) {
            amount = flt(frm.doc.qty * frm.doc.rate);
            frm.set_value('amount', amount)
        }
    }
})

Kindly help

i was doing some calculation on quotation item recently kindly read my post hope it might help

1 Like

Thanks a lot, let me check and update

@Pirated

Hi please see the below screenshot

and i used the script like this , but not working

frappe.ui.form.on(‘Optional Accessories’,
{
opt:function(frm,cdt,cdn)
{
var d = locals[cdt][cdn];
var opt_amount = (flt(d.qty) * flt(d.rate));
frappe.model.set_value(cdt, cdn, “amount”, opt_amount);

},
qty:function(frm,cdt,cdn)

{
var d = locals[cdt][cdn];
var opt_amount = (flt(d.qty) * flt(d.rate));
frappe.model.set_value(cdt, cdn, “amount”, opt_amount);

},
rate:function(frm,cdt,cdn)

{
var d = locals[cdt][cdn];
var opt_amount = (flt(d.qty) * flt(d.rate));
frappe.model.set_value(cdt, cdn, “amount”, opt_amount);
}
})

@root13F @Pirated

try this script enter your correct child doctype name in the first line.

   frappe.ui.form.on('Doctype_Name', {
    	qty:function(frm,cdt,cdn){
    		var d = locals[cdt][cdn];
    		var amount = flt(d.qty) * flt(d.rate) ;
    		frappe.model.set_value(cdt, cdn, "amount", amount);
    	},
    	rate:function(frm,cdt,cdn){
    		var d = locals[cdt][cdn];
    		var amount = flt(d.qty) * flt(d.rate) ;
    		frappe.model.set_value(cdt, cdn, "amount", amount);
    	}
    })
1 Like

@Pirated

Hi , thanks for the code, its working. but once i refresh the qty Suppose change Qty 1 from 2 then only it will works, how we can refresh that qty field

Kindly assist

them amount field will be recalculated whenever you make changes to qty field or rate field .

Yes that is right but here when logged in to screen itself amount is showing 0 , when changing qty from 1 to 2 amount value comes, if it is 1 i need to change again to 1 as qty

i dont understand what is your goal. Kindly briefly explain may be we can help.

Hi @Pirated i will explain in Steps with screenshot

  1. When i am creating a new quotation , while i am choosing products in Optional Accessories section, i will be like below, Amount Field will be zero even the qty is 1 and rate is 129

  2. While i am changing qty from 1 to 2 only the amount will be get populated

My concern is why the amount is not populating when at Step 1.

Below is the code i used

frappe.ui.form.on(‘Optional accessories’, {

	qty:function(frm,cdt,cdn){

		var d = locals[cdt][cdn];

		var amount = flt(d.qty) * flt(d.rate) ;

		frappe.model.set_value(cdt, cdn, "amount", amount);

	},

	rate:function(frm,cdt,cdn){

		var d = locals[cdt][cdn];

		var amount = flt(d.qty) * flt(d.rate) ;

		frappe.model.set_value(cdt, cdn, "amount", amount);

	}

})

i dont know if it works but you can try

	item_code:function(frm,cdt,cdn){

		var d = locals[cdt][cdn];

		var amount = flt(d.qty) * flt(d.rate) ;

		frappe.model.set_value(cdt, cdn, "amount", amount);

	},
	qty:function(frm,cdt,cdn){

		var d = locals[cdt][cdn];

		var amount = flt(d.qty) * flt(d.rate) ;

		frappe.model.set_value(cdt, cdn, "amount", amount);

	},

	rate:function(frm,cdt,cdn){

		var d = locals[cdt][cdn];

		var amount = flt(d.qty) * flt(d.rate) ;

		frappe.model.set_value(cdt, cdn, "amount", amount);

	}

})
1 Like

@Pirated
While adding this code -amount not at all populating even if after changing qty also

Hi, i have similar problem please assist me to solve it.

I have created duplicate doctype as ‘Service Quotation’ from ‘Quotation’ doctype, when i create new record item child table details are not set automatically like rate, amount as 0 and even if i enter qty and rate, amount is not calculating automatically.

1 Like

@D_N_Srinath , Try this below code

frappe.ui.form.on(‘Optional accessories’,
{
qty:function(frm,cdt,cdn)
{
var d = locals[cdt][cdn];
var amount = flt(d.qty) * flt(d.rate) ;
frappe.model.set_value(cdt, cdn, “amount”, amount);
},
rate:function(frm,cdt,cdn)
{
var d = locals[cdt][cdn];
var amount = flt(d.qty) * flt(d.rate) ;
frappe.model.set_value(cdt, cdn, “amount”, amount);
}
}
)

@Chinjuprotech thanks for response, will try with the above code.

pleas if you got solution share it with us , I have the same problem , and I am new in ERPNEXT.
Thank you

Please try this code, customize as per your doctype

frappe.ui.form.on(‘Optional accessories’,
{
qty:function(frm,cdt,cdn)
{
var d = locals[cdt][cdn];
var amount = flt(d.qty) * flt(d.rate) ;
frappe.model.set_value(cdt, cdn, “amount”, amount);
},
rate:function(frm,cdt,cdn)
{
var d = locals[cdt][cdn];
var amount = flt(d.qty) * flt(d.rate) ;
frappe.model.set_value(cdt, cdn, “amount”, amount);
}
}
)