İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
1132 Görünümler

Hi all,


I want to show a form field of a project task only if the tag "PoC" is set. I tried the invisible condition:


[["tag_ids","=","PoC"]]

But it doesn't work. The field is always hidden with this condition, no matter if the tag is set or not. I have some automation's which also get triggered when a PoC tag is set. There the domain looks like this:


[["tag_ids.name","=","PoC"]]

Which works nicely for automation but if I try to use it for the invisible condition I get this error:


Error while validating view near:

<form string="Task" class="o_form_project_tasks" js_class="project_form" __validate__="1">
                    <field name="allow_subtasks" invisible="1"/>
                    <field name="is_closed" invisible="1"/>

Invalid composed field tag_ids.name in attrs ({"invisible": [["tag_ids.name","=","PoC"]]})

Any hints how to only show a form field if the tag "PoC" is set?


Thanks a lot!


Avatar
Vazgeç
En İyi Yanıt

Hi Björn

as tag_ids is a manytomany I woul try to use 'in'

[["tag_ids.name","in","[PoC]"]]

or 

[["tag_ids","in","[your_id]"]]


Alternative you can create a computed field


display_fieldx = fields.Boolean(compute='_compute_display_fieldx')

@api.depends('tag_ids')
def _compute_display_fieldx(seld)
​for rec in self:
​rec = any(tag_id.name == 'PoC' for tag_id rec.tag_ids)


then in form view
<field name="display_fieldx" invisible="1"/>

and use attrs ({"invisible": [["display_fieldx","=",False ]]}) for your field




hope this helps

Daniel

Avatar
Vazgeç
Üretici En İyi Yanıt

Hi Daniel,


[["tag_ids","in","[your_id]"]]

gets accepted and it looks good, also the "visual" part of the rule builder (unfortunately I don't have enough karma points to post a screenshot or even a link to a screenshot :( ) 


But the field is shown afterward in all forms, no matter if the tag is set or not.


The other suggestion:

[["tag_ids.name","in","[PoC]"]]


Doesn't work, I get again a error message that tag_ids.name is not known:

Error while validating view near:

<form string="Task" class="o_form_project_tasks" js_class="project_form" __validate__="1">
                    <field name="allow_subtasks" invisible="1"/>
                    <field name="is_closed" invisible="1"/>

Invalid composed field tag_ids.name in attrs ({"invisible": [["tag_ids.name","in",["PoC"]]]})


I have the feeling that we are close to the solution but something is still missing.


Thanks!

Björn

Avatar
Vazgeç

Hi Björn
i updated my answer with a second appraoch, hope this helps

Üretici

Hi Jan,

I got it now working. First I had to find the ID of the tag which was not that easy. I inspected the HTML code to find it, than I had to turn "in" to "not in". This worked than:

[["tag_ids","not in",[5]]]

Thanks a lot for all your ideas and support!

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Tem 24
2562
1
Şub 23
5518
1
Tem 19
5561
1
Haz 23
3280
1
Kas 22
3518