Calculate Total of Rows data

HI all…

i need to calculate the total items weight in the sales order and delivery order for transportation reasons, how can i calculate the weight in that column?

thanks

Hi @ramielian,

Could you provide the names of the fields for weight in item form, and the total weight in sales order form?

@tanuj i mean the UOM of the product…

we mostly use KG so i need a total of this column : {{ row.stock_uom}}

@ramielian
For custom field on Sales Order “total_weight”, try this custom script (on Sales Order):

frappe.ui.form.on("Sales Order Item", "stcok_uom", function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
	weight = 0;
	$.each(frm.doc.items || [], function(i, d) {
		if (d.stock_uom == "Kg"){
		weight += flt(d.stock_uom);
                }
	});
	frm.set_value("total_weight", weight);
});
1 Like

@Tanuj thank you for your help but can you please tell me how to make this function work? so where i need to add this script and how to call it in the sales order?

another thing please, if i need to calculate time for example 08:00 Am till 05:00 PM how many hours,how would i do this?

thanks

@ramielian
You have to write custom script for Sales Order Doctype.
Goto Setup > Customization > Custom Script.
Select Doctype > Sales Order
Write above script in Script block and Save it.

@ramielian

First, figure out the name of the two fields. Example: start_time and end_time.

the code for above would be:

frappe.utils.data.time_diff(end_time,start_time)

Make sure you’ve set the fields to Time in Customize Form.

EDIT: Thats the Python code

@nabinhait: Is there a way to do this in custom script?

UPDATE: You could also call the method with Frappe.call

1 Like

@Tanuj @Sangram its not working for me…

what i want to do is:

i added a layoff and login time in the attendance form, i need to make two steps mainly:

  1. calculate how much time difference between layoff and login and the value have to be in the new field Total Working Hours.
  2. i need to change the status of the document if the hours is less than 9 hours to incomplete working day.

what i did now is set frappe.utils.data.time_diff(end_time,start_time) in a new field in the document attendance and added frappe.utils.data.time_diff(doc.attendance_time,doc.layoff_time) in the options, but its not calculating…

i know am doing something wrong which is using this snippet in the options field but where else i can add it?

thanks