Changing one-to-many relation on create/update?

I have a doctype Foo with fields “bars” (relation to many “Bar” doctypes) and “sum” (readonly, float).
I have a doctype Bar with fields “foo” (relation to single Foo, required) and “price” (required, float).

Each time I create a Bar (or update its ‘price’ field) with relation to some Foo - I need to recalculate ‘sum’ field of that Foo to be the sum of all ‘price’ fields of Bars Foo is related to.

How can I do that in erpnext?

In django its quite simple with post-save signals.