Reputation: 1538
I have a form view with a button whose objective is to test a connection. I need to return a message if the connection is successful and at the same time update some values in the form view.
I have something like this in my .py file:
def test_connection(self):
connected = self.connect(self.ip_address, self.port)
if connected:
self.data1='a'
self.data2='b'
return True
So far I have only been able to update the values but if I raise a warning with the message: raise Warning(_('Connection OK.'))
,the data is not updated.
Is there any way to update the form data and at the same time display an info message? or is there any other way to accomplish something like this?
Upvotes: 0
Views: 653
Reputation: 1675
You can update value and return a wizard as message at same time. That is good I think. If you use ant exceptions or the warning raised, the server flow will block there, hence value cant be updated and the updated values at same time will be revoked.
Upvotes: 0
Reputation: 14721
You don't have to define a message field just add div Tag with some beautiful css styling. And use attrs to show ot or hide it according to the connection Status.
In odoo you cannot show error and update values in same time
Upvotes: 2
Reputation: 2135
Rather than using a raise
message, you can just define a message
field on your wizard.
message = fields.Char('Message')
def test_connection(self):
connected = self.connect(self.ip_address, self.port)
if connected:
self.update({data1: 'a',
data2: 'b',
message: 'Your Message'})
return True
You can display it on the view in such a way that it is invisible
unless there is a message set.
<field name="message" attrs="{'invisible': [('message', '=', False)]}"/>
Upvotes: 2