This question has been flagged
2 Replies
8021 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

Avatar
Discard
Best Answer

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),
        'sequence':fields.integer('Sequence'),
        '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).

Avatar
Discard
Best Answer

The best resource is:

https://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/field_type.html/

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

Avatar
Discard