Hi,
I have written a code for Delivery Note in python and calling it at ‘validaiton’. I does some calculations base on Delivery Note Items and update values in both child doc Delivery Note Item and parent doc Delivery Note on save . I would like to know how can I call this function when I change a value in the child doc Delivery Note Item. I can not figure out the arguments to pass for self and cdt during call from javascript
For example:
Python code
def update_pipe_weight_um(self, cdt):
estimate_weight_um_temp = 0
total_um_temp = 0
discount_temp = 0
total_scale_weight_um_temp = 0
weight_difference_um_temp = 0
weight_difference_percentage_um_temp = 0
has_pipe = 0,
for d in self.items:
if 'Pipe-MS' in str(d.item_code):
estimate_weight_um_temp += d.total_weight_um
total_um_temp += d.amount_um
total_scale_weight_um_temp += d.total_scale_weight_um
has_pipe = 1
if has_pipe == 1:
self.total_weight_um = self.loaded_vehicle_weight_um - self.empty_vehicle_weight_um
weight_difference_um_temp = self.total_weight_um - estimate_weight_um_temp
weight_difference_percentage_um_temp = (weight_difference_um_temp / estimate_weight_um_temp) * 100
discount_temp = self.total - total_um_temp
self.estimate_weight_um = estimate_weight_um_temp
self.total_um = total_um_temp
self.weight_difference_um = weight_difference_um_temp
self.weight_difference_percentage_um = weight_difference_percentage_um_temp
self.total_scale_weight_um = total_scale_weight_um_temp
self.discount_amount = discount_temp
self.calculate_taxes_and_totals()
Javascript code
frappe.ui.form.on("Delivery Note Item", {
scale_weight: function(frm,cdt,cdn){
var item_code = frappe.model.get_doc(cdt, cdn);
if (item_code.item_code){
if(item_code.item_code.includes("Pipe-MS",0)){
frm.call({
method: "steelpipes.sp_delivery_note.sp_delivery_note_item.update_pipe_weight_um",
args: {self: "what should i pass", cdt: "what should i pass"},
callback:function(r){
}
})
}
}
}
})