The code provided by @DReispt should work, and if you approve the answer, please confirm it, not mine.
It is important to understand that the function field in OpenERP returns a dictionary with the object identifiers for the key and the field value for the given object as the associated value.
In the source code:
result = 0.0 total[result] += anything
will cause a KeyError since the dictionary is empty first ( total = {} at the beginning of your code).
A shorter version of DReispt code will be
def get_result(self, cr, uid, ids, context=None): total = {} for obj in self.browse(cr, uid, ids, context=context): total[obj.id] = sum(o2m.float_field for o2m in obj.o2m_field) return total
This version uses a Python generator expression that can be passed to the sum() built-in function. It is also slightly faster because you avoid accessing the total dictionary several times for each object.
source share