If you want to show/hide the buttons in res.users view, you can use attrs as "Sehrish" suggested.
But if you want to do it in a different object's view, you need to override fields_view_get method in that object and show/hide the buttons based on the currently logged-in user.
Use the following code in your object:
from lxml import etree
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
result = super(MyClass, self).fields_view_get(
view_id, view_type, toolbar=toolbar, submenu=submenu)
doc = etree.XML(result['arch'])
hide = True
if self.env.user.my_boolean:
hide = False
for node in doc.xpath("//button[@name='my_button']"):
modifiers = json.loads(node.get("modifiers", '{}'))
modifiers.update({'invisible': hide})
node.set("modifiers", json.dumps(modifiers))
result['arch'] = etree.tostring(doc)
return result
This code you can use in any object to show/hide the buttons/fields/groups/tab, etc.
Do you want to show/hide the buttons/fields in res.users view or different object's view?
@Sudhir I want to hide the buttons that are in another model and in another view, but based on the value of a checkbox field that is in res.users