How to hide Edit button based on state in Odoo 10

This can be done by inserting conditional CSS.

Frist add a html field with sanitize option set to False:

x_css = fields.Html(
    string='CSS',
    sanitize=False,
    compute='_compute_css',
    store=False,
)

Then add a compute method with your own dependances and conditions:

# Modify the "depends"
@api.depends('state_str_modify_me')
def _compute_css(self):
    for application in self:
        # Modify below condition
        if application.state_str_modify_me= 'In Progress':
            application.x_css = '<style>.o_form_button_edit {display: none !important;}</style>'
        else:
            application.x_css = False

Finally add it to the view:

<field name="x_css" invisible="1"/>

Leave a comment