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

How to write function fields for many2one or one2many?

By
babu
on 6/23/15, 7:02 AM 788 views

Hi All,

How to create function field for many2one or one2many.

Can any one suggest me with example, please

Thanks


Can you explain where you want to use it ?

Ankit H Gandhi(AHG)
on 6/23/15, 8:15 AM
0
nikesh
On 5/29/16, 11:39 PM

Hi Babu,

This can be implemented as follows. In old api,


def _get_default_address(self, cr, uid, ids, field_name, arg, context=None):
    res = {}
    partner_obj = self.pool.get('res.partner')
    for data in self.browse(cr, uid, ids, context=context):
        adr_id = False
        if data.partner_id:
            adr_id = partner_obj.address_get(cr, uid, [data.partner_id.id], ['contact'])['contact']
        res[data.id] = adr_id
    return res
_columns ={
        'default_address_id': fields.function(_get_default_address, type="many2one", relation="res.partner"),
}

 In new api, it will be as follows:



default_address_id = fields.Many2one(compute="_get_default_address", relation="res.partner")

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: 6/23/15, 7:02 AM
Seen: 788 times
Last updated: 5/29/16, 11:39 PM