Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6539 มุมมอง

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 ?

คำตอบที่ดีที่สุด

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")

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 23
1631
0
ธ.ค. 22
2295
0
มิ.ย. 21
2348
0
มิ.ย. 20
4813
One2many or many2one แก้ไขแล้ว
1
พ.ย. 19
2277