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.

1

How to add a field from fields_view_get?

By
Atchuthan - Technical Consultant, Sodexis Inc
on 6/27/14, 1:29 AM 1,873 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.

0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 5/20/15, 3:59 PM

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)                

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

1 follower(s)

Stats

Asked: 6/27/14, 1:29 AM
Seen: 1873 times
Last updated: 7/10/15, 4:05 AM