Skip to Content
Menu
This question has been flagged
7 Replies
5899 Views

Hi,

To make a required field based on the state is easy we should make something like that  :

note = fields.Text(string='Motif d\'ouverture', states={'Done': [('required', True)]} )

but what i'm looking for is when we want to change  the state from New to Done it should give us an error message to attribute a value for this field ( note ).

note is not required in New State.

note field is just required in Done state


Any idea,


Regards,


Avatar
Discard
Best Answer

hello , 

Just try this in xml

attrs="{'required' :[('state','in',['done'])]}"

Avatar
Discard
Author

proceed by using XML as your comment or with python as i described it give the same result.

Author Best Answer

It's my own module ( from scratch)

Avatar
Discard
Best Answer

Hope this help:

from openerp import models, fields, api, exceptions, _

@api.multi
def button_change_state(self):
     if not self.note:
         raise exceptions.Warning(_('Warning!'), _("Please put note!"))
     self.state = 'done'
     return True
Avatar
Discard
Author

Thanks, but Sadly nothig happen when adding your code

U need to add the button in xml view as an object. Or if its module by Odoo then u need to inherit class and use the super method.

Author

It's My own module and buttons are already created as type="object"