Try ERPNext Buy Support Partners Foundation

Calculation and update field of child table

I have…
1…parent form = sales order
there are some filed for calculation., these are… end_date, start_date, and month(this field is show the no of month between two dates) problem is this how to calculate no of month using custom script…
2… child form = sales order item ( that is table view in parent form)
i need to no of month multiply with amount( amount is in child form as view in parent form)
and after multiply… the value shows in total_amount ( this is field in parent form)
how to do this…any body please help…

here i write this script for calculate no of month…
frappe.ui.form.on(‘Sales Order’, “months”, function(frm){
var membership_start_date= new Date(frm.doc.membership_start_date)
console.log(membership_start_date);
var membership_end_date_=new Date(frm.doc.membership_end_date_);
console.log(membership_end_date_);
numberOfMonths = (membership_end_date_.getFullYear() - membership_start_date.getFullYear()) * 12 + (membership_end_date_.getMonth() - membership_start_date.getMonth()) + 1;
console.log(numberOfMonths);
frm.set_value(“months”,numberOfMonths);
});
but its not working…

you didnt define your numberOfMonths, put a var infront of it and it will work

1st no i done…i get no of month in parent form field…but how to multiply with amount(that is child table field)…
example…
parent field – month_no;
child table name – items;
child field name --amount,total_amt,qty,rate(but use only amount);
and condition is… month_no * amount == total_amt(this is also in child table)
this is how to execute in script…can anybody write a script for this execution…

provide screenshots and context and clear problem defenition so that people can understand clearly.

where is this no of months coming from? is it inside child table or parent doctype?

to calculate values for every item in child table, use a $.each loop inside child table

note : people will help you to do it yourself, but you will have a slim chance of doing the work for you for free

frappe.ui.form.on(‘Sales Order Item’, ‘qty’, function(frm, doctype, name) {
var row = locals[doctype][name];
var doc = frm.doc;
row.total_amt = row.rate * row.qty * 5;
// I WANT {ROW.TOTAL_AMT = ROW.RATE * ROW.QTY * MONTHS}
// FIND MONTH IS BELOW IN PARENT FORM…BUT I WANT TO USE HERE…HOW IS POSSIBLE??
refresh_field(‘items’);
});

frappe.ui.form.on(‘Sales Order’, “membership_end_date_”, function(frm, doctype, name){
var row = locals[doctype][name];
var doc = frm.doc;
var membership_start_date= new Date(frm.doc.membership_start_date);
var membership_end_date_=new Date(frm.doc.membership_end_date_);
row.numberOfMonths = (membership_end_date_.getFullYear() - membership_start_date.getFullYear()) * 12 + (membership_end_date_.getMonth() - membership_start_date.getMonth()) + 1;
frm.set_value(“months”,row.numberOfMonths);
});