- I have a Doctype called : Plan Management Invoice
- On Invoice there is a child table called : Services Support List
- Services Support list has 7 fields:
- Select Price type ( A select field with Strings as options e.g “Price Limit
National Non Remote MMM 1 to 5”) - Enter Quantity (Float type)
- Total (Currency Type)
- Select Service (Link type field - Linked to a doctype “Service” with Price
Types) - Price Limit National Non Remote MMM 1 to 5 ( A currency field fetched from Doctype “Service” - Fetches Perfectly fine)
- Price Limit National Non Remote MMM 1 to 6 (similar to field 5 - a currency field fetched from doctype “Service”)
- There are multiple similar fields like 5 and 6 of currency types which are being fetched from the doctype “Service”. They all fetch perfectly fine.
- Select Price type ( A select field with Strings as options e.g “Price Limit
Now what I wanted to do was to add a script, which would choose a rate based on what the user selects Price type i.e (a basic algo - not the actual code)
if (doc.price_type == “Price Limit National Non Remote MMM 1 to 5”){
doc.rate = doc.price_limit_nt_satas_wa_mmm_1_to_5;
}
What this would do is make rate = price_limit_nt_satas_wa_mmm_1_to_5 (the fetched price).
However my code does not work, Any help is appreciated. Here is my code:
frappe.ui.form.on("Services Support List", {
rate:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frappe.model.set_value(d.doctype, d.name, "total_delivered", d.quantity * d.rate);
frm.doc.services_support_list.forEach(function(d) {
if (d.price_limit_type == "Price Limit NT SATAS WA MMM 1 to 5"){
d.rate = d.price_limit_nt_satas_wa_mmm_1_to_5;
}
else if (d.price_limit_type == "Price Limit ACT NSWQLD VIC MMM 1 to 5"){
d.rate = d.price_limit_act_nswqld_vic_mmm_1_to_5;
}
else if (d.price_limit_type == "Price Limit National Non Remote MMM 1 to 5"){
d.rate = d.price_limit_national_non_remote_mmm_1_to_5;
}
else if (d.price_limit_type == "Price Limit National Remote MMM 6"){
d.rate = d.price_limit_national_remote_mmm_6;
}
else{
d.rate = d.price_limit_national_very_remote_mmm_7;}
total += d.total_delivered;
});
frm.set_value('grand_total', total);
rate : rate field in child table
total_delivered: field in child table (found by rate * quantity)
grand_total: field in parent table which is the sum of all total_delivered from child table
Here are my attached screenshots