Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
1118 Visualizações

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
Cancelar
Melhor resposta

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
Cancelar
Autor Melhor resposta

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
Cancelar

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

Autor

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!

Publicações relacionadas Respostas Visualizações Atividade
2
jul. 24
2526
1
fev. 23
5497
1
jul. 19
5555
1
jun. 23
3256
1
nov. 22
3495