Using pyson, I can set the states attribute for a field based on the context.
As an example, if the number of groups in context is greater than 2, the following will set a field to be read-only:
description = fields.Char('Description',
states={'readonly': Len(Eval('context', {}).get('groups') ) > 2 } )
Now, suppose I want to allow the above field to be read-only if the group with id
= 20 is in groups.
I tried using: 'readonly': In(20, Eval('context', {}).get('groups') )
, but that gave the error:
File "C:\Users\user\.virtualenvs\tryton_test\lib\site-packages\trytond\pyson.py", line 485, in __init__
assert obj.types().issubset({dict, list}), \
AssertionError: obj must be a dict or a list
I also tried: 'readonly': 20.in_(Eval('context', {}).get('groups') )
, but that gave the error:
File "C:\Users\user\.virtualenvs\tryton_test\lib\site-packages\trytond\modules\sale\sale.py", line 137
states={
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
Where am I going wrong?