OpenERP Functional Field

Posted on 2012-08-10
Last Modified: 2012-08-10
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?
Question by:infinitegatorade
    LVL 12

    Expert Comment

    by:Sinoj Sebastian
    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[] = area
            return res

    Open in new window


    Author Comment

    That looks like Python.  Which file would that go in?  I only see XML files when editing the view.
    LVL 12

    Accepted Solution

    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.

    Author Closing Comment


    Author Comment

    Note: the python needs to be added to /opt/openerp/server/openerp/addons/SOMETHING/

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Messaging apps are amazing tools with the power to do a lot of good, but the truth is the process of collaborating with coworkers requires relationships established through meaningful communication - the kind of communication that only happens face-…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now