Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
1688 Vistas

Hi There,


I have developed an approval process for employee profile. I need to restrict the edit option on the  frontend once the employee profile is approved.  Using the 'attrs' attribute for this purpose isn't easy to inherit.

Then I tried 'fields_view_get' to remove edit button but it didn't work as i expect.

Does anyone have solution to hide or disable edit button based on the state in odoo 15?

Avatar
Descartar
Mejor respuesta

You can override fields_view_get method and disable edit according to condition.

example :- 

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    res = super(, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
    if view_type == 'form' and :
        root = etree.fromstring(res['arch'])
        root.set('edit', 'false')
        res['arch'] = etree.tostring(root)
    else:
        pass
    return res



Avatar
Descartar
Mejor respuesta

  Sale Edit Button Hide You Tick This , Not Visiable Edit Button Of Sale Order Form View





class SaleOrder(models.Model):

    _inherit = "sale.order"


  @api.depends('state')

    def _compute_edit_hide(self):

        for record in self:

            if self.env.user.has_group('uni_customization.group_sale_edit_permission') and record.state != 'draft':

#self.env.user.has_group('user_module.group_name') and record.state != 'draft':

                record.edit_hide = ''

            else:

                record.edit_hide = False

                

                

                

class SaleOrderLine(models.Model):

    _inherit = "sale.order.line"

  @api.model

    def create(self, vals):

        order = self.env['sale.order'].browse(vals['order_id'])

        if self.env.user.has_group('uni_customization.group_sale_edit_permission') and order.state != 'draft':

            raise exceptions.UserError('You Have Not Permission, Please !contact your Admin')

        return super(SaleOrderLine, self).create(vals)


    @api.constrains('order_id')

    def _check_order_state(self):

        for line in self:

            if self.env.user.has_group('uni_customization.group_sale_edit_permission') and line.order_id.state != 'draft':

                raise exceptions.ValidationError('You have not permission add or modify products in a sale order.')


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 23
12765
3
jul 22
23148
2
jun 21
18586
0
sept 20
3732
0
may 16
4141