Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
7 Besvarelser
6278 Visninger

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
Kassér
Bedste svar

hello , 

Just try this in xml

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

Avatar
Kassér
Forfatter

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

Forfatter Bedste svar

It's my own module ( from scratch)

Avatar
Kassér
Bedste svar

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
Kassér
Forfatter

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.

Forfatter

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