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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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
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).
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)