Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
58568 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

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

คำตอบที่ดีที่สุด

uid only work with domain not in attrs

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

คำตอบที่ดีที่สุด

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!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Andreas,

Good suggestion, I tried and It's working.

+1 from me.

Best Thanks,

อวตาร
ละทิ้ง

Hi Ankit

Please how did you create the boolean field function

คำตอบที่ดีที่สุด

That will work

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

 

อวตาร
ละทิ้ง

<class 'NameError'>: "name 'user' is not defined" while evaluating

Related Posts ตอบกลับ มุมมอง กิจกรรม
7
ธ.ค. 22
15402
Multi group user - security rule แก้ไขแล้ว
2
มี.ค. 15
9731
1
มี.ค. 15
5027
4
มี.ค. 15
5941
0
มิ.ย. 25
302