Hello Everyone,
I have created a doctype called “Vomax Cycle Order Form”.
This doctype has a child table called “Items Table1”.
This “Items Table1” doctype contains below mentioned fields.
-
Category
-
Item
-
XS
-
S
-
M
-
L
-
XL
-
XXL
-
3XL
-
4XL
-
Pad Type
-
Zipper Size
-
Zipper Colour
-
Price Each
-
Total Price
I want to do the calculation for the child table.
The formula is Total Price= ((XS+S+M+L+XL+XXL+3XL+4XL) * (Price Each))
Also, there is a field called “Total” in the parent doctype.
Whenever the above calculation is performed, the field value of the “Total” should be calculated automatically.
I have tried with different custom scripts as shown below, but it is not working.
Script 1: frappe.ui.form.on(‘Items_Table1’, {
xs: function(frm, cdt, cdn)
s: function(frm, cdt, cdn)
m: function(frm, cdt, cdn)
l: function(frm, cdt, cdn)
xl: function(frm, cdt, cdn)
xxl: function(frm, cdt, cdn)
3xl: function(frm, cdt, cdn)
4xl: function(frm, cdt, cdn){
let child = locals[cdt][cdn];
let total_price = ((child.xs + child.s + child.m + child.l + child.xl + child.xxl + child.3xl + child.4xl) * (child.price_each));
frappe.model.set_value(cdt, cdn, “total_price”, total_price);
calculate_total_price(frm);
},
price_each: function(frm, cdt, cdn) {
let child = locals[cdt][cdn];
let total_price = ((child.xs + child.s + child.m + child.l + child.xl + child.xxl + child.3xl + child.4xl) * (child.price_each));
frappe.model.set_value(cdt, cdn, “total_price”, total_price);
frappe.model.set_value(cdt, cdn, “total_price”, total_price);
calculate_total_price(frm);
}
});
// frappe.ui.form.on(“Items_Table1”, {
// xs: function(frm, cdt, cdn)
s: function(frm, cdt, cdn)
m: function(frm, cdt, cdn)
l: function(frm, cdt, cdn)
xl: function(frm, cdt, cdn)
xxl: function(frm, cdt, cdn)
3xl: function(frm, cdt, cdn)
4xl: function(frm, cdt, cdn){
// let row = locals[cdt][cdn];
// {
// frappe.model.set_value(cdt, cdn, ‘total_price’, flt(child.xs + child.s + child.m + child.l + child.xl + child.xxl + child.3xl + child.4xl) * (child.price_each))
// frm.events.calculate_total_price(frm);
// }
// },
// price_each: function(frm, cdt, cdn) {
// let row = locals[cdt][cdn];
// {
// frappe.model.set_value(cdt, cdn, ‘total_price’, flt(child.xs + child.s + child.m + child.l + child.xl + child.xxl + child.3xl + child.4xl) * (child.price_each))
// frm.events.calculate_total_price(frm);
// }
// },
// })
Script 2: cur.frm.cscript.xs=function(doc,cdt,cdn)
cur.frm.cscript.s=function(doc,cdt,cdn)
cur.frm.cscript.m=function(doc,cdt,cdn)
cur.frm.cscript.l=function(doc,cdt,cdn)
cur.frm.cscript.xl=function(doc,cdt,cdn)
cur.frm.cscript.xxl=function(doc,cdt,cdn)
cur.frm.cscript.3xl=function(doc,cdt,cdn)
cur.frm.cscript.4xl=function(doc,cdt,cdn)
{
var d=locals[cdt][cdn]
var total_price_value=((d.xs + d.s + d.m + d.l + d.xl + d.xxl + d.3xl + d.4xl) * (d.price_each));
d.total_price=total_price_value;
refresh_field(“Items_Table1”);
}
Script 3: frappe.ui.form.on(“Items Table1”, “xs”, “s”, “m”, “l”, “xl”, “xxl”, “3xl”, “4xl”, function(frm, cdt, cdn) { var child = locals[cdt][cdn]; child.total_price = (((child.xs + child.s + child.m + child.l + child.xl + child.3xl + child.4xl) * (child.price_each)); cur_frm.refresh(); });
Here is the screenshots of both parent doctype and child table doctype.
Please help.
Thanks & Regards
Sujay