Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

How get current user id in XML

By
Vasiliy Birukov
on 3/28/13, 4:52 AM 12,345 views

Is it possible get UID in XML for use in attrs?

Like that:

<button name="button_cancel" string="Cancel" attrs="{'invisible':[('create_uid','!=',uid)]}"/>

Make button visible only for user, that create record?

6

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/28/13, 5:29 AM

It seems that he uid is currently not supported in the attrs attribute. See the following reported bug for more information:

https://bugs.launchpad.net/openobject-server/+bug/920033

But you can do a workaround:

  • Create a new boolean function field called "inv"
  • the function returns True if the field should be invisible (e.g. when uid = create_uid)
  • In the view you can write

    <button name="button_cancel" string="Cancel" attrs="{'invisible':[('inv','=',True)]}"/>
    

Can you please tell what should i return from the method? I tried but get an error, here's what i'm trying attribute={} if to_dep_manager==uid: attribute["visible"] = True else: attribute["visible"] = False return attribute 'visible' : fields.function(is_visible,type='boolean',obj='emp.department.change',method=True,string='Visibility'), I keep getting a key error

Shaumyadeep Chaudhuri
on 7/3/13, 11:26 AM

Same problem here. @Shaumyadeep: How you fixed it?

dirtyHandsPHP
on 10/17/14, 2:35 AM
0
Kevin Kong
On 5/16/16, 4:56 AM

if u are chiniese or u can read chinese, pls see here: http://www.cnblogs.com/kfx2007/p/5010550.html

if not,

here is the solution:

first, we have override the transfer_node_to_modifiers method in ir_ui_view.py file:

def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False):
    if node.get('attrs'):        
        modifiers.update(eval(node.get('attrs')))

    if node.get('states'):
        if 'invisible' in modifiers and isinstance(modifiers['invisible'], list):
            # TODO combine with AND or OR, use implicit AND for now.
            modifiers['invisible'].append(('state', 'not in', node.get('states').split(',')))
        else:
            modifiers['invisible'] = [('state', 'not in', node.get('states').split(','))]

    for a in ('invisible', 'readonly', 'required'):
        if node.get(a):
            v = bool(eval(node.get(a), {'context': context or {}}))
            if in_tree_view and a == 'invisible':
                # Invisible in a tree view has a specific meaning, make it a
                # new key in the modifiers attribute.
                modifiers['tree_invisible'] = v
            elif v or (a not in modifiers or not isinstance(modifiers[a], list)):
                # Don't set the attribute to False if a dynamic value was
                # provided (i.e. a domain from attrs or states).
                modifiers[a] = v

as we want to make odoo understand uid in attrs,so we add following codes:

if 'uid' in  node.get('attrs'):
            uid = 1

so odoo knows what uid stand for.

you can replace the 1 instead of your uid.


if you want to using it through an app, here is my app in app store:

https://apps.openerp.com/apps/modules/8.0/dynamic_attrs/


have fun!

0

Daniel Reis

--Daniel Reis--
3436
| 6 7 9
Lisbon, Portugal
--Daniel Reis--

Author of the "Odoo Development Essentials" book.

Applications Manager at Securitas Portugal

Github: https://github.com/dreispt

Twitter; @reis_pt


Daniel Reis
On 3/28/13, 5:41 AM

That should work: uid in an expression should evaluated to the current user. You can see some examples of this in addons/project/project_view.xml.

The uid is only used within the domain attribute. It is never used within the attrs attributes.

Andreas Brueckl
on 3/28/13, 5:54 AM
-2

That will work

<button name="button_cancel" string="Cancel" attrs="{'invisible':[('create_uid','!=',user.id)]}""/>

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/28/13, 4:52 AM
Seen: 12345 times
Last updated: 5/16/16, 4:56 AM