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

Warning for fields.selection??

By
Luís
on 7/19/13, 2:08 PM 1,320 views

Hi,

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.

0
nazarii
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.

Luís
on 7/22/13, 7:45 AM

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: 7/19/13, 2:08 PM
Seen: 1320 times
Last updated: 3/16/15, 8:10 AM