The Python Oracle

How to make field in OpenERP required only for specific workflow state?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3

--

Chapters
00:00 How To Make Field In Openerp Required Only For Specific Workflow State?
00:55 Accepted Answer Score 13
01:11 Answer 2 Score 6
01:42 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.

  1. Make required=True in .py file and set default value for that field.
  2. Make required=False and set required=True in view.xml.
  3. Make required=False and set required=True in view.xml for some state of object.

This may help to solve your problem.