Skip to Content
Menu
This question has been flagged
2 Replies
1706 Rodiniai

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?

Portretas
Atmesti
Best Answer

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



Portretas
Atmesti
Best Answer

  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.')


Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
2
gruod. 23
12769
3
liep. 22
23153
2
birž. 21
18589
0
rugs. 20
3734
0
geg. 16
4150