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

I have four many2one fields from which only one can be populated at a time so I set on_change events on each of them to clear other three fields if something is selected but there's a recursion problem; changing one field clears other fields which in turn clears the initial field.

How would one go about avoiding this?

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

After a lot of faffing about, solution turned out to be rather simple; all I had to do was to check whether the field is empty or not before executing the code body of on_change function, here's a little example:

def onchange_item1(self, cr, uid, id, item1_id=None, context=None):
    domain = {}
    value = {}

    if item1_id:
        #Clear all selections
        value = {'item2_id': False,}

    return {'domain': domain,
            'value': value}

def onchange_item2(self, cr, uid, id, item2_id=None, context=None):
    domain = {}
    value = {}

    if item2_id:
        #Clear all selections
        value = {'item1_id': False}

    return {'domain': domain,
            'value': value}
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ธ.ค. 18
13
0
ก.ค. 16
3831
Onchange many2one partner_bank_id แก้ไขแล้ว
1
พ.ค. 16
4386
1
มี.ค. 15
5421
1
พ.ค. 24
2559