This question has been flagged
1 Reply
10581 Views

Hi!

Is there a way to hide a workflow button based on logged user?

I'm developping an OpenERP 7.0 Module and in a certain point of this process a user can take a the worflow of to his responsability. I tried this <button name="take_request" string="Take request" help="Take this request to your responsability" attrs="{'invisible': ['|', ('state','!=','treatment'),('owner','=',user.id)]}" /> (like I would do in a domain rule), but I am getting the following error:

NameError: name 'user' is not defined

If I try <button name="take_request" string="Take request" help="Take this request to your responsability" attrs="{'invisible': ['|', ('state','!=','treatment'),('owner','=','user.id')]}" /> (whit user.id inside quotes) I get no error, but it isn't hiding the button.

Thanks in advance.

Avatar
Discard
Author Best Answer

I finaly sorted it out, and it's working fine. I used a field.function in my object and used this field in my button's 'invisible' attibutes. I'll leave here the relevant code for future reference.

In my py, created a function that checks if I'm responsible for any of the requests and added a field.function on my object:

    def _check_ami_responsible(self, cr, uid, ids, field_name, arg, context):
        """ Checks if user is responsible for this request
        @return: Dictionary of values
        """
        res = {}
        for req in self.browse(cr, uid, ids, context=context):
            if req.responsible_name.id == uid:
                res[req.id] = True
            else:
                res[req.id] = False
        return res

    (...)

   _columns={
        (....)
        'ami_responsible': fields.function(_check_ami_responsible, type="boolean", obj="generic.request", method=True),
    }

Then in my view I added condition ('ami_responsible', '=', False) on button to hide it when not responsible for that request.

    <button name="confirm_request" class="oe_highlight" string="Confirm Request" type="workflow" attrs="{'invisible': ['|',('ami_responsible', '=', False), '|',('state','!=', 'submitted'), ('needs_reformulation', '=', True)]}" />

Hope this helps!

Avatar
Discard