How to make field in OpenERP required only for specific workflow state?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Forest of Spells Looping
--
Chapters
00:00 Question
01:12 Accepted answer (Score 13)
01:34 Answer 2 (Score 6)
02:10 Thank you
--
Full question
https://stackoverflow.com/questions/1416...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #postgresql #openerp
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Forest of Spells Looping
--
Chapters
00:00 Question
01:12 Accepted answer (Score 13)
01:34 Answer 2 (Score 6)
02:10 Thank you
--
Full question
https://stackoverflow.com/questions/1416...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #postgresql #openerp
#avk47
ACCEPTED ANSWER
Score 13
To make a field required only in some states, leave it as not required in the Model, and in the form view set the conditions on which the field will be required:
<field
name="fiscal_position"
attrs="{'required':[('state','in',['pending','open'])]}"
/>
ANSWER 2
Score 6
If you write required=True in .py file then ORM will add not null constrain to that field.
There are multiple ways to do your code.
- Make
required=Truein.pyfile and set default value for that field. - Make
required=Falseand setrequired=Trueinview.xml. - Make
required=Falseand setrequired=Trueinview.xmlfor some state of object.
This may help to solve your problem.