Odoo Help


Warning for fields.selection??

on 7/19/13, 2:08 PM 1,722 views


I need to warning when user change my fields.selection. I create a function onchange and works when I edit the registry but the problem is this field have a default value and when I create a new registry the onchange function is called again. I tried resolve the problem like this:

def onchange_sourcebilling(self, cr, uid, ids, sourcebilling, context=None):

    result = {}

    if not sourcebilling:
        return {}

    is_new = self.browse(cr, uid, ids, context)

    if is_new.context is None:
        raise osv.except_osv(_('Atenção!'),
                    _('Tem a certeza que quer alterar este campo?'))

    return {'value': result}

But this doesn't work like I want. When I create a new field the warning doesn't appear, that is good, but with this code, while I don't save the registry the warning doesn't work.

Basically I need the warning when user change my field selection only and not when the user click in the button "Create". In this moment the warning don't appear when I click on button "Create" but if I change the fields.selection the warning doesn't work. When I save registry works fine.




| 5 4 7
On 7/19/13, 6:46 PM

You shouldn't use use raise in example provided here. Instead of you need to return value like this:

return {'value': result,
        'warning': {'title': 'Atenção!',
                    'message': 'Tem a certeza que quer alterar este campo?',

More about values returning from on_change event you can read here. In provided example result is a dictionary, where key is field name and value is it's value, in you example result will looks like:

result = {'sourcebilling': sourcebilling}.

Not sure about what are you checking by is_new - if record is already created it have 'id' attribute, so you can check by if ids: pass.

Thanks for your answer. The problem is that my function onchange is called when I click on button create because my fields.selection have a value default. I want that warning works only the user click the fields.selection. In this moment works when user click the fields.selection and when user create a registry.

on 7/22/13, 7:45 AM

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.


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

0 follower(s)


Asked: 7/19/13, 2:08 PM
Seen: 1722 times
Last updated: 3/16/15, 8:10 AM