<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'
)
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)]}"/>