Skip to Content
Menu
This question has been flagged
1 Reply
8491 Views

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.

Avatar
Discard
Best Answer

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)                

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 17
7484
2
Nov 16
6219
1
Sep 15
4960
3
Aug 15
9043
1
Mar 15
5660