Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
6294 Lượt xem

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,


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

hello , 

Just try this in xml

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả Câu trả lời hay nhất

It's my own module ( from scratch)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Tác giả

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