odooodoo-11formview

How to hide Edit button based on state in Odoo 11


how can I hide the edit button when the state is "In Progress" I tried doing ir.rule like this but it didn't work it only filter(domain) my treeview I also tried to doing it in JavaScript but i can't find any odoo 11 sample


Solution

  • 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"/>