Hide group in xml form

77 views
Skip to first unread message

Richmond Fiko

unread,
Jul 24, 2018, 2:35:06 AM7/24/18
to tryton
Hello,

I have a little noob question. In a form view, is it possible to hide a group with a condition for instance in:

<label name="is_insured"/>
<field name="is_insured"/>
<newline/>
<group string="Insurance Infos" id="statement_insurance_info">
<label name="insurance_part"/>
<field name="insurance_part"/>
<label name="insurance_number"/>
<field name="insurance_number"/>
<label name="party_insurance"/>
<field name="party_insurance"/>
</group>

group "Insurance infos" will be hide if is_insured (a bool field) is false and will appear if the field is set true.
If is it possible, how can I do it?
Thanks

Cédric Krier

unread,
Jul 24, 2018, 4:20:06 AM7/24/18
to tryton
Yes, you can. You must override view_attributes of the Model to return
the xpath that match the group and set a 'states' attribute with the
PYSON expression that will make 'invisible' state True.

http://doc.tryton.org/4.8/trytond/doc/ref/models/models.html#trytond.model.ModelView.view_attributes


--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Richmond Fiko

unread,
Jul 24, 2018, 6:50:06 AM7/24/18
to tryton
Something like:

@classmethod
def view_attributes(cls):
# Hide the group when is_insured is not
# true
return [('//group[@id="statement_insurance_info"]', 'states', {
'invisible': Not(Bool(Eval('is_insured'))),
})]

Cédric Krier

unread,
Jul 24, 2018, 7:25:06 AM7/24/18
to tryton
On 2018-07-24 03:37, Richmond Fiko wrote:
You should always call super for modularity, otherwise it seems OK.
You could simplify the PYSON expression: ~Eval('is_insured')

Richmond Fiko

unread,
Jul 24, 2018, 7:55:06 AM7/24/18
to tryton
OK
Thanks for your help Cédric
Reply all
Reply to author
Forward
0 new messages