Odoo Help

0

How to write function fields for many2one or one2many?

By
babu
on 6/23/15, 7:02 AM 1,101 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")

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.

Register

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)

Stats

Asked: 6/23/15, 7:02 AM
Seen: 1101 times
Last updated: 5/29/16, 11:39 PM