This question has been flagged
2 Replies
4180 Views

a custombutton should check some Logic and show a simple Messagebox.

in views i added:

<button string="Start Tests" type="object" name="start_test"/>


in the model i tried the following

@api.one
def start_test(self):
#....
#....
return {
'warning': {
'title': 'Information',
'message': 'Testmessage!'
}
}


how can i achiev to show a Messagebox after Buttonclick?


Avatar
Discard
Best Answer

I think you need this: http://learnopenerp.blogspot.com/2017/12/how-to-display-confirmation-display-box.html

Avatar
Discard
Best Answer

You won't be able to return a warning entry in a dict, because that style is intended to be used for onchange warnings. To solve it you have the following options:

1- Raise a Validation Exception like:

from odoo import exceptions
...
raise exceptions.ValidationError("Validation Message")

2- Create a wizard like form to show the message and return an action in the button to instruct Odoo to open that form from your wizard model.

return {
'type': 'ir.actions.act_window',
'res_model': model_name,
'view_type': 'form',
'view_mode': 'form',
'views': [(view_id, 'form')],
'target': 'new',
'res_id': self.id,
'context': dict(self._context),
}

 You could pass the value for a field in the wizard using the context to display the needed message, just set a 'default_'+ field_name entry in the context with the value

Avatar
Discard