How to make field readonly based on group and status?

前端 未结 5 1269
故里飘歌
故里飘歌 2020-12-14 20:26

I want to make field readony based on group, and status.

Like i have two grops 1. Manager Group 2. User Group

If I give User Group to any <

5条回答
  •  时光说笑
    2020-12-14 20:51

    There is another sweet way to achieve this. Create one functional field and in that check for group assigned to that user and do not store that field. In View use that field in attrs.

    Let say in product you don't want to allow any user to modify Internal Reference if user does not belongs to Product Modify group.

    Create one group.

    
        
            Product Modify
             
        
         
    

    Python file

    class product_template(models.Model):
        _inherit="product.template"
    
        @api.one
        def set_access_for_product(self):
            self.able_to_modify_product = self.env['res.users'].has_group('product_extended_ecom_ept.group_product_modify')
    
        able_to_modify_product = fields.Boolean(compute=set_access_for_product, string='Is user able to modify product?')
    

    XMl file should be looking like,

    
                Product Template extension
                
                product.template
                
                
                    
                        
                    
                    
                        {'readonly' : [('able_to_modify_product','=',False)]}
                    
                
               
    

提交回复
热议问题