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

Based on user particular Field readonly applied using field_view_get method

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = super(class_name,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
    if 'filed_name' in res['fields'] and uid!=1:
        res['fields']['filed_name']['readonly'] = True
    return res

The code worked in version 6.0.4 but in the latest version 7 not working. How to make works?...

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

Hi, This is solution for that.

from openerp.osv.orm import setup_modifiers


def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
            res = super(uma_stock_picking_in, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type,
                                                                    context=context, toolbar=toolbar, submenu=submenu)
           if view_type == 'form':
                    doc = etree.XML(res['arch'])
                    for node in doc.xpath("//field[@name='min_date']"):
                            node.set('readonly', "0")
                            setup_modifiers(node, res['fields']['min_date'])

                    res['arch'] = etree.tostring(doc)
            return res

You should notice function setup_modifiers if you want to set option in ['invisible', 'readonly'] because in version 7 when you set readonly or invisible it will generate the modifiers attribute to take care this.

Cheer.

อวตาร
ละทิ้ง
ผู้เขียน

Thanks i will try using fields_view_get method to Particular Groups and Users to set field read-only is it possible in version 7 ?...

I don't know, most of work I am working on version 7. In that code above you can set user or group or other choice easy. But one thing I don't know how to override the tree view of field one2many or many2many field in form view because in fields_view_get we can not get its.

Thanks, it helped

คำตอบที่ดีที่สุด
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
พ.ค. 25
1658
1
เม.ย. 25
1250
one2one relational field แก้ไขแล้ว
3
ก.ย. 24
14121
2
ก.พ. 24
2426
1
ก.ค. 23
2691