This question has been flagged
1 Reply
7089 Views

I am trying to put a link to download docs files in form view. I already have the links and I made a custom web controller that actually does the download but the problem is that they present in every part of the view. I want it to appear based on specific condition where the state field of an applicant is set to a specific value similar to buttons in form view.

Bellow is an example of a button that appears based on the state condition:

<button name="action_open_agreement_form" type="object" string="P020 Declaration and undertaking" attrs="{'invisible':[('state','!=','done')]}"/>

this allows me to show a button if the state of the applicant is not done.

The link I have is as bellow in the xml

<record model="ir.ui.view" id="view_sefarer_applicant_form">
    <field name="name">Jobs - Recruitment Form</field>
<field name="model">seafarer.applicant</field>
<field name="arch" type="xml">
    <form string="Jobs - Recruitment Form" version="7.0">
        ...
        <sheet>
            ......
    <div class="oe_right oe_button_box">
                ....
                <a href="#" onclick="window.open('/sc/some_html?id=P014-'+$('.seafarer_id span').text(), '_blank')" class="applicant_docs_forms"  id="P014">P014 Drug/Alcohol Delcaration</a>
                .....
            </div>
        </sheet>
     .....

I need to use something like attrs but it is not working, I also tried to use javascript with on window load or document ready but that's not working too. I also tried desperate things like having a button with attrs with the condition and having a onclick action on it that clicks the link and having the link hidden but that didn't work as well.

I am pretty desperate and any help would be appreciated.

Avatar
Discard
Best Answer

please check in the xml file state field is available before the button. If not add the same.

Example attrs tag in button:-

<field name="state" invisible="1"/>
<button name="action_open_agreement_form" type="object" string="P020 Declaration and undertaking" attrs="{'invisible':[('state','!=','done')]}"/>

Example attrs tag in link:

<group  attrs="{'invisible':[('state','!=','done')]}">
 <a href="#" onclick="window.open('/sc/some_html?id=P014-'+$('.seafarer_id span').text(), '_blank')" class="applicant_docs_forms" id="P014">P014 Drug/Alcohol Delcaration</a>
</group>
Avatar
Discard
Author

thank you but I want the attrs attribute on the link not on the button itself, so I need sth like: <a href="#" onclick="window.open('/sc/some_html?id=P014-'+$('.seafarer_id span').text(), '_blank')" class="applicant_docs_forms" id="P014" attrs="{'invisible':[('state','!=','done')]}">P014 Drug/Alcohol Delcaration</a>

I updated the answer try attrs tag to add in the group.

Author

Thank you very much really great help