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 avoid on_change recursion?

By
Moin
on 4/10/13, 2:46 PM 1,098 views

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?

0
Moin
On 4/11/13, 1:19 PM

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}

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

0 follower(s)

Stats

Asked: 4/10/13, 2:46 PM
Seen: 1098 times
Last updated: 3/16/15, 8:10 AM