I have a custom field of type Data called “costing” in Quotation, and I want it to be updated once the grand_total standard field in Quotation is updated. I wrote the below custom script which updates but only if I save the document. How can I make it so that the costing field is updated always the same way the grand_total field is being updated, without the need to save.
Please check field names if you have further issues.
Validate is a way to check BEFORE saving - not live in the app. For this use solution which @rohit_w posted.
Hello @rohit_w, before_save is also not updating until you save!. How is the grand_total field updating easily like this? Will the field type has an effect? Mine is Data, with all default settings for a Data type.
Thanks @Marcin_Walkow, parsefloat didn’t help too. I had the same understanding about validate, but couldn’t find anywhere guidance of how I can get the updates Live in the app.
Check how did you updating grand total value? @Marcin_Walkow is right, if you used frm.set_value(‘grand_total’, value) to update the grand_total then below code will work
@rohit_w, I am actually not updating grand_total by code, but rather by adding items in Quotation Items, or adding Taxes and Charges, or Additional Discounts. So I see the value of grand_total changing in front of me, but not the costing value.
You need to write function to calculate costing and call the function on trigger of qty, rate, price list rate, which is the only customisable solution for it.
OR
Add one more custom field with data type button(“calculate_costing”) and on click of button calculate the costing
@rohit_w, these 2 options sounds doable, but I am really starting my way around coding (even these simple things). Would you be so kind by giving a complete example of how to write the function (simple formula of grand_total * 0.5), and how to call it on trigger on rate and discount_amount?
Also, for the button where will I write the code? and how to?
I know that this might be a little too much, but your help will be much appreciated as we advance out use of ERPnext.
Here you need to add Calculate Costing custom field whose field type is Button after costing field. After preparing quotation, click on button which show you the costing amount before save