Reputation: 17
<button string="Merge" name="merge_beneficiaries" type="object" class="oe_highlight"
attrs="{'invisible': ['|', '|', ('stage_id', '!=', 2),('active', '=', False)]}"/>
I have this button and want to appear only when there are some id's present in many2many field 'duplicate_beneficiaries__ids'.
duplicate_beneficiaries_ids = fields.Many2many(
"openg2p.beneficiary",
string='Potential Duplicates'
)
Upvotes: 1
Views: 792
Reputation: 2825
if Bhavesh Odedra's answer is not working, you can create another boolean computed field in the model to apply button viewing logic in python code, for example:
view_merge_beneficiaries = fields.Boolean(compute='_get_view_merge_beneficiaries')
def _get_view_merge_beneficiaries(self):
for record in self:
record.view_merge_beneficiaries = bool(record.duplicate_beneficiaries_ids)
<field name="view_merge_beneficiaries" invisible="1" />
<button string="Merge" name="merge_beneficiaries" type="object" class="oe_highlight"
attrs="{'invisible': [('view_merge_beneficiaries', '=', False)]}"/>
Upvotes: 2
Reputation: 11143
We can do it like
attrs="{'invisible': [('duplicate_beneficiaries_ids', '=', False)]}"
And JFI, instead of using id on the attrs, we can use name like
attrs="{'invisible': ['|', ('stage_id.name', '!=', 'Stage Name'), ('active', '=', False)]}"
Upvotes: 0