mrmo
December 8, 2015, 9:06am
#9
@kolate_sambhaji @rmehta , Hi guys, I have items that are sold by piece units, but we need to input weight * price per weight = total price per weight, just to print in the sales order with no extra function in the system, so I have made 3 custom fields:
item_weight (manual input)
item_weight_price (manual input)
item_weight_price_total (auto input “item_weight * item_weight_price = item_weight_price_total ”)
I use this script that I took from above:
frappe.ui.form.on(“Sales Order Item”, “item_weight_price_total”, function(frm, doctype, name) {
var row = locals[doctype][name];
row.item_weight_price_total = row.item_weight * row.item_weight_price;
refresh_field(“item_weight_price_total”);
});
Hope you can help me out, thank you so much!
Mo
write script on item_weight and item_weight_price,
So on changing item_weight/item_weight_price, item_weight_price_total will be calculated
frappe.ui.form.on("Sales Order Item", "item_weight", function(frm, doctype, name) {
var row = locals[doctype][name];
row.item_weight_price_total = row.item_weight * row.item_weight_price;
refresh_field("item_weight_price_total");
});
frappe.ui.form.on("Sales Order Item", "item_weight_price", function(frm, doctype, name) {
var row = locals[doctype][name];
row.item_weight_price_total = row.item_weight * row.item_weight_price;
refresh_field("item_weight_price_total");
});
1 Like
mrmo
December 8, 2015, 1:16pm
#11
@kolate_sambhaji thank you for your help.
Your code works only if I change
refresh_field(“item_weight_price_total”);
into the following:
refresh_field(“items”);
But then I have to enter something in field “item_weight_price_total” manually to refresh. I appreciate your help, thanks.
mrmo
December 8, 2015, 1:57pm
#12
Hi @kolate_sambhaji I have got it set with the following script
frappe.ui.form.on(“Sales Order Item”, “item_weight”, function(frm, doctype, name) {
var row = locals[doctype][name];
row.item_weight_price_total = row.item_weight * row.item_weight_price;
refresh_field(“items”);
});
frappe.ui.form.on(“Sales Order Item”, “item_weight_price”, function(frm, doctype, name) {
var row = locals[doctype][name];
row.item_weight_price_total = row.item_weight * row.item_weight_price;
refresh_field(“items”);
});
Now it refreshes automatically, strange but it works. Thanks for your kindness.
@mrmo
if you use
frappe.model.set_value(cdt, cdn, "field_name", value);
then no need to refresh_field
1 Like
mrmo
December 10, 2015, 3:00am
#14
@kolate_sambhaji Could you please give a hint where to insert this
frappe.model.set_value(cdt, cdn, “field_name”, value);
Thanks
jof2jc
December 10, 2015, 4:44am
#15
frappe.ui.form.on("Sales Order Item", "item_weight", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "item_weight_price_total", d.item_weight * d.item_weight_price);
});
3 Likes
JamesE
February 4, 2016, 12:47pm
#17
I’d like to do something extremely similar to this with Material Request Items, but I can’t find the file to insert this code.
Do you just insert the python into the Material Request doctype, or where?
mrmo
February 16, 2016, 2:46pm
#18
@JamesE You insert it into the custom script which you can find in the Setup module under customize
ahmed
August 31, 2016, 3:48pm
#19
Hello @Roy_Stephen , how did you sort our the refresh issue you have? I have the same problem.
Hi Ahmed
I never got it working perfectly and it is long but this was my last effort
I’m sure there’s a better way but I haven’t worked on it for months now.
Hope it helps
1 Like
Hi, guys. Thanks everybody in this thread for valuable discussion. Hope my case is not very off-topic here. I’ve modified Quality Inspection
doctype so that it calculates repair rate with the help of following script:
frappe.ui.form.on("Quality Inspection", "repaired_qty", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "repair_rate", d.repaired_qty * 100 / d.inspected_qty);
});
frappe.ui.form.on("Quality Inspection", "inspected_qty", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "repair_rate", d.repaired_qty * 100 / d.inspected_qty);
});
Everything works great, but the problem is that I created repair_rate
custom field as Data type and resulting numbers are shown like 10.256410256410257
.
Is there any way to set precision in custom script? Or the only solution would be to create another custom field with Float type?
You can do this I guess
frappe.model.set_value(cdt, cdn, "repair_rate", flt(d.repaired_qty * 100 / d.inspected_qty, precision('repair_rate')));
flt(2.xxx, precision('fieldname')) should round it for you
3 Likes
bedo
June 17, 2017, 10:02pm
#24
I’m trying to calculate the total billing hrs for Sales Invoice, using this post: Sum fields amount From Child Table V7 - #25 by Randy_Lowery
But it doesn’t work…where is the problem please?
frappe.ui.form.on("Sales Invoice Timesheet", {
billing_hours: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var total = 0;
frm.doc.timesheets.forEach(function(d) { total += d.billing_hours; });
frm.set_value('total_hrs', total);
}
});
bghayad
November 4, 2017, 8:27pm
#25
Hello;
How I can access (get and set) the value of field in previous row of the changed row in the child table?
Regards
Bilal
jof2jc
November 5, 2017, 2:57am
#26
Try this… Not sure if it helps
var d = locals[cdt][cdn]
var previous row = frm.doc.items[d.idx-1];
rmehta:
frappe.ui.form.on(“Quotation Item”, “full_price”, function(frm, doctype, name) {
var row = locals[doctype][name];
row.full_price = row.qty * row.price_list_rate;
refresh_field(“items”);
});
rmehta:
Its a bit different for child items.
frappe.ui.form.on("Quotation Item", "full_price", function(frm, doctype, name) {
var row = locals[doctype][name];
row.full_price = row.qty * row.price_list_rate;
refresh_field("items");
});
I try same code to change the rate of item in quotation but it doesnt work
pls reply
In Quotation, the item rate is automatically fetched when selecting the item code …what are you trying to accomplish?
Please explain thoroughly so we can help you