Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5248 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
8091
1
thg 3 15
6447
0
thg 3 15
3588
0
thg 3 15
3403
1
thg 12 22
6318