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

I have a scenario where I am raising exception in some conditions. But I need to make some fields 'Blank' or pass value '0' if the exception occurs.

I am using @api.onchange method and have tried following ways but none of them worked:

1. 

self.holiday_status_id = False
raise except_orm('No Joining Date!', 'There is no joining date defined for this employee')

2.

res = {'warning':{'title':_('No Joining Date!'),
            'message':_('There is no joining date defined for this employee')},
            'value':{'holiday_status_id':False}}
return res

Thanks.


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

Ok I got this. As I am using onchange method I have to use the 'Warning' like this:


                self.holiday_status_id = False
return {'warning': {
'title': "Warning",
'message': "There is no joining date defined for this employee",
}
}


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

Hello, use this:

from openerp.exceptions import except_orm, Warning, RedirectWarning
raise except_orm('Warning', warning_message)
raise Warning(warning_message)
raise RedirectWarning(warning_message, True, _('continue'))
Ảnh đại diện
Huỷ bỏ
Tác giả

I am not sure about your answer. I have used except_orm and Warning but result is same. It only shows the warning but value doesn't get updated.

please show me full code.

@api.onchange('your_field')

def _funct_name(self):

if self.your_field == False:

self.another_field = ''

except_orm('Warning', warning_message)

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 15
3658
1
thg 1 16
5240
0
thg 9 15
3753
0
thg 8 15
4473
1
thg 7 15
7776