Skip to Content
Menu
This question has been flagged
2 Replies
2759 Views

Hi All,


I am trying to defined the invisible attribute of a button based on a field that is a many2many field which is supposed to have a list of ids; however, I am not quite sure how I can access this many2many field in xml.

Below is the code:


<record id="sale_order_approver_condition_inherited" model="ir.ui.view">
<field name="name">sale_order_approver_condition_inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='print_quotation']" position="after">
    <field name="id" invisible="1"/>
    <field name="q_validators" invisible="1"/>
    <field name="q_validators_pending" invisible="1"/>
    <button string="Approve Quotation" type="object" name="validate_quotation" class="btn-primary"
    context="{'sale_order_id':context.get('id'),'q_validators':context.get('q_validators'),
    'q_validators_pending':context.get('q_validators_pending')}"
    
attrs="{'invisible':[('state','not in',['q_validate'])]
}"
    />
</xpath>

</field>

q_validators_pending   is the many2many field that I want my condition to access, and the bold line is where I would like to insert the condition.

What I want to achieve is for example (but I want it in xml):
if uid not in q_validators_pending:
    invisible = True


Avatar
Discard
Best Answer

Hi,

Can you try to re-write the attrs like below

attrs="{'invisible':[('uid','not in','q_validators_pending')]

Regards

Avatar
Discard
Author

I tried, it does not work. It seems like the second argument is taken as a string instead of a list.

Author Best Answer

I made an alternative solution which uses a computed boolean field to check if the current user has validated and is in the validators' list, it works, but not pretty.

If anyone knows how to access the many2many field as a list in xml, please do share with me here, thank you, I do appreciate it.

Avatar
Discard