Odoo Help

Welcome!

This community 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.

0

Function Fields In Open Erp ?

By
Ali Abdelmonem Mustafa Amer
on 11/6/13, 12:48 PM 3,950 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

2
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),
        '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).

1

Gustavo

--Gustavo--
950
| 2 1 4
Buenos Aires, Argentina
--Gustavo--

Python developer, big fan of sailing

Gustavo
On 11/6/13, 1:42 PM

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)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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