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

I need to add a field with the help of fields_view_get ORM method.

For example: I have to add field Test after field Summary.  How should I add the field directly at py.

        eview = etree.fromstring(res['arch'])
        summary = eview.xpath("field[@name='summary']")
        if len(summary):
            summary = summary[0]
            summary.addnext(etree.Element('field', {'name': 'test', 'nolabel': '1'}))

        res['arch'] = etree.tostring(eview)

If I don't have a field named "test" defined in XML, this code shows the following client error

OpenERP Client error

Error: Field 'test' specified in view could not be found.
http://localhost:8069/web/static/src/js/view_form.js:1236

Note:
I know how to add the field directly in XML, so provide me help with regards to fields_view_get only.

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

Hi  Atchuthan

As I don't have 'summary' field I used instead 'product_id' field

I added it again with a new title

In your code you should've added the two slashes, "//" before the field[@name='product_id']"

I ran it and it is ok

            eview = etree.fromstring(res['arch'])
            summary = eview.xpath("//field[@name='product_id']")
            if len(summary):
                summary = summary[0]
                summary.addnext(etree.Element('field', {'name': 'product_id', 
                                                        'string':'title of new field',
                                                        'nolabel':'0',
                                                        }))
            res['arch'] = etree.tostring(eview)                

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 17
7633
fields_view_get not being triggered แก้ไขแล้ว
2
พ.ย. 16
6442
New API style for fields_view_get? แก้ไขแล้ว
1
ก.ย. 15
5087
3
ส.ค. 15
9232
1
มี.ค. 15
5802