How to make the calculations automatically

Please read the whole post.

You have to use the frappe.model.set_value