Change state of various field

62 views
Skip to first unread message

Antonio Roncero

unread,
Nov 19, 2015, 8:15:04 AM11/19/15
to tryton
Hi,

In a particular case, i need to make invisible the name field on the party model and use only code field. In this case i need to make visible a page. I use the classmethod view_attributes

@classmethod
def view_attributes(cls):
   
return [('/form//field[@name="name"]', 'states', {
               
'invisible': Eval('is_robot'),
               
}),
           
('//page[@id="party_robot_data"]', 'states', {
               
'invisible': ~Eval('is_robot'),
               
}),
           
]

The second part works fine, but the field "name" not change. I tried with /form/field[@name="name"] /form//field[@name="name"] //form/field[@name="name"] //field[@name="name"] /field[@name="name"]...
I don't know if I am writing bad the xpath or there is another error

Thanks

Sergi Almacellas Abellana

unread,
Nov 19, 2015, 9:15:51 AM11/19/15
to try...@googlegroups.com
El 19/11/15 a les 12:04, Antonio Roncero ha escrit:
Why are you only setting the states on the view and not on the field? I
will override the states on name field, on the __setup__ function, so
it's applied to all the views.

Also make sure that the is_robot field is added to the name depends, so
the client will always fetch the is_robot field.

Hope it helps.


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Antonio Roncero

unread,
Nov 20, 2015, 4:55:09 AM11/20/15
to tryton
Really because I still am in the learning phase, so I don't know all the framework possibilities (I don't find to much doc and I'm reading a lot of other people modules). :P
But that code must be work, no? The second part makes the changes, the first part doesn't anything...
 
Hope it helps.


Sure!

Sergi Almacellas Abellana

unread,
Nov 20, 2015, 4:58:19 AM11/20/15
to try...@googlegroups.com
El 19/11/15 a les 15:30, Antonio Roncero ha escrit:
Yes the code must work, but can not give more help, without knowing more
about the view definition. I suspect it's the xpath that's not applying
correctly.

Cédric Krier

unread,
Nov 20, 2015, 9:30:05 AM11/20/15
to try...@googlegroups.com
No it can not work because the field definition override any XML view
states. By the way, states attribute is not allowed on field tag, see
trytond/ir/ui/form.rnc

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages