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?
infinitegatoradeAsked:
Who is Participating?
 
Sinoj SebastianConnect With a Mentor CTO & OpenERP Project managerCommented:
Function field should be defined in python file and then can be included in XML view. This code should go in to the same py file were you have the height and width fields defined.
0
 
Sinoj SebastianCTO & OpenERP Project managerCommented:
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

0
 
infinitegatoradeAuthor Commented:
That looks like Python.  Which file would that go in?  I only see XML files when editing the view.
0
 
infinitegatoradeAuthor Commented:
Thanks!
0
 
infinitegatoradeAuthor Commented:
Note: the python needs to be added to /opt/openerp/server/openerp/addons/SOMETHING/SOMETHING.py
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.