Odoo Help


Function Fields In Open Erp ?

Ali Abdelmonem Mustafa Amer
on 11/6/13, 12:48 PM 4,136 views

Hi All

I'm New In OpenErp Developing So I Have Many Questions That I Want To Know It's Answers

I Want To Deal With Function Fields So I Want A Good Example With Little Explanation

Subhin P V
On 11/7/13, 3:40 AM

Function Fields are created by declaring them in the _columns section of a class just like any other field is done. for eg:

 _columns = {
        'name': fields.char('Name',size=128),
        'subfield_id':fields.many2one('ir.model.fields','Sub Field'),
        'rules': fields.char("Rules", size=128, help="Set rules for filtering the data in the CSV file"),
        'model_name': fields.function(_get_model, string="Sub Model", type='char', store=True)

in this the field model_name is a function field. _get_model is the function name. type specifies the type of field. It may be integer, boolean, many2one ect.. here type is char. on giving store=True the functional field is stored in The database. Otherwise it is not stored. Functional fields are readonly and the value in them is updated on saving the record.

then you need to define the function _get_model. for eg :

def _get_model(self, cr, uid, ids, field_name, arg, context=None):*
        res = {}
        for line in self.browse(cr, uid, ids, context):
                res[line.id] = "Some Value"
        return res

In the above function res is a dictionary. What i am doing in this function is, i am taking all the record ids in this model as keys of the dictionary and "Some Value" as the value. Then in the client, on saving a record of the corresponding model, the value "Some Value" will be automatically updated in the field "Sub Model" (model_name).



| 2 1 4
Buenos Aires, Argentina

Python developer, big fan of sailing

On 11/6/13, 1:42 PM

The best resource is:


You have an example there, otherwise you can find many examples in the code (that's the best way to learn how OpenERP works)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/6/13, 12:48 PM
Seen: 4136 times
Last updated: 3/16/15, 8:10 AM