Link to home
Start Free TrialLog in
Avatar of infinitegatorade
infinitegatorade

asked on

OpenERP Functional Field

How do I create a functional field in OpenERP?  For example, given an existing "width" and "height" fields, how would I create an "area" field that automatically calculates itself using the other two fields?
Avatar of Sinoj Sebastian
Sinoj Sebastian
Flag of India image

A function field is just like other fields with a function to calculate the value.

It may look like this

'area': fields.function(_calculate_area, string='Area', type="float", store=True),

Open in new window


In this case the _calculate_area is a function pointer and you should have that function in the same class.

Here is a sample function (Please note that I assume you have width and height defined as float or integer field on the same model)

    def _calculate_are(self, cr, uid, ids, name, args, context=None):
        res = {}
        for object in self.browse(cr, uid, ids):
            area = object.width * object.height
            res[object.id] = area
        return res

Open in new window

Avatar of infinitegatorade
infinitegatorade

ASKER

That looks like Python.  Which file would that go in?  I only see XML files when editing the view.
ASKER CERTIFIED SOLUTION
Avatar of Sinoj Sebastian
Sinoj Sebastian
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!
Note: the python needs to be added to /opt/openerp/server/openerp/addons/SOMETHING/SOMETHING.py