how to change the field states

35 views
Skip to first unread message

Markus Bala

unread,
Apr 11, 2016, 11:55:50 PM4/11/16
to tryton-dev
Hi,

I had an inherit model ShipmentIn. Adding new field "order_confirm". The purpose when the order confirmed, other fields will be readonly.

How I am going to modify other fields base on the "order_confirm"?

Example:
Original :
company = fields.Many2One(.., states ={'readonly': Eval('state') != 'draft'})

Expected:
company = fields.Many2One(..., states = {'readonly': Eval('state') != 'draft' | Eval('order_confirm') }

Please help

Ralf Peschke

unread,
Apr 12, 2016, 2:58:55 AM4/12/16
to tryto...@googlegroups.com
Hi Markus,
The "states" of each field are a dictionary with the keys "readonly",
"required" and "invisible". You can change it in the setup-classmethod:

@classmethod
def __setup__(cls):
super(YOURCLASSNAME, cls).__setup__()
cls.company.states['readonly'] = (Eval('state') != 'draft' |
Eval('order_confirm'))


I hope it helps in time

Markus Bala

unread,
Apr 12, 2016, 3:09:58 AM4/12/16
to tryto...@googlegroups.com
Hi Ralf,

Thank you.

If let say I do not want to change the original state but only add the new condition. Is it possible?

    original_condition = cls.company.states['readonly']
    cls.company.states['readonly'] = (original_condition  | Eval('order_confirm'))

???

--
You received this message because you are subscribed to the Google Groups "tryton-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton-dev/570C9CAD.7000602%40peschke-it.de.

Raimon Esteve

unread,
Apr 12, 2016, 3:22:45 AM4/12/16
to tryto...@googlegroups.com
And example inherit in __setup__(cls):

cls.shipment.states['readonly'] |= Eval('moves', False)

In your code (without tested):

cls.company.states['readonly'] |= Eval('order_confirm')

Raimon

Ralf Peschke

unread,
Apr 12, 2016, 3:27:12 AM4/12/16
to tryto...@googlegroups.com
Hi Markus,
Yes, it is:
cls.company.states['readonly'] =
(cls.company.states.get('readonly', False) | Eval('order_confirm'))


Reply all
Reply to author
Forward
0 new messages