Se rendre au contenu
Menu
Cette question a été signalée
7 Réponses
6272 Vues

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
Ignorer
Meilleure réponse

hello , 

Just try this in xml

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

Avatar
Ignorer
Auteur

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

Auteur Meilleure réponse

It's my own module ( from scratch)

Avatar
Ignorer
Meilleure réponse

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
Ignorer
Auteur

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.

Auteur

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