Skip to Content
Menu
This question has been flagged
2 Replies
4919 Views


I want to make button/field visible to only those user who is in the approved_user_id field.



This code is in my .py file

@api.depends()

    def _get_current_user(self):

        self.update({'current_user' : self.env.user.id})


This is code of my .xml file 

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


                        <button name="action_sendForApprove" type="object"  string="Request To Approve" class="oe_highlight" attrs="{'invisible': ['|',('state','=','draft'),('approved_by_id','!=','current_user')]}"/>




But this is not working for me. can any plz help me regarding it.


Any help will be thank full.

Avatar
Discard
Best Answer

if approved_user_id is a Boolean field in res.users try this way.

In py.

 is_approved_user_id = fields.Boolean(default=False, compute='_get_current_user_details')    

@api.multi

def _get_current_user_details(self):

        for record in self:

            current_user = self.env['res.users'].search([('id','=',self.env.user.id)]) 

            if current_user.approved_user_id ==True:

                self.is_approved_user_id= True

In XML

 <button name="action_sendForApprove" type="object"  string="Request To Approve" class="oe_highlight" attrs="{'invisible': ['|',('state','=','draft'),('is_approved_user_id','!=',True)]}"/>

hope this helps

Avatar
Discard
Best Answer



I improve Kiran's Answer here.

button_visible = fields.Boolean(compute='_compute_button_visible')
def _compute_button_visible(self):
for rec in self:
if rec.approved_by_id.id == self._uid:
rec.button_visible = True
else:
rec.button_visible = False


Regards


Global Creative Concepts Tech Co Ltd.


Avatar
Discard