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

fields_view_get not working as expected

By
Shawn Varghese
on 12/20/14, 6:30 AM 887 views

I am using the fields_view_get function to change certain properties of the form. However, I am facing 2 issues:

1) the fields_view_get function gets invoked everytime when I click on tree view but only the first time when I click on form view . I want it to be invoked each time I click on the form view.

2) Using context.get('active_ids') always returns None, when I use it inside fields_view_get.

Code Snippet:   

def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
        res = super(hr_travel_allowance_request, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=submenu)
        active_id=context.get('active_ids')
        print "Context",active_id
        print res
        return res

Is there something I am doing wrong when I invoke it?

P.S.    Please tell me how to add formatted code to my question. I couldn't find an option to do it.

2

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 12/22/14, 1:14 AM

What you have noticed is correct...

"fields_view_get", is method which will be called only once, that is to load the view, as the name indicates, it will load the XML view & the fields associated to that object...

once the view is loaded, then the datas are fetched from database, after that the view is unaltered...

So when you open a form, only once the function will be evoked... So does in the case of tree view, however since you click on the action menu, it is like evoking the action newly, inturn it will evoke the "field_view_get" again, seeming it look like it is called repeatedly, but technically it is no, ...

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/22/14, 2:31 AM

Don't expect context.get('active_ids') to be populated properly in fields_view_get.  That method is invoked BEFORE any search/read on the selected model is carried out.  If you can described what you are trying to achieve, maybe we can help you better.

0
Shawn Varghese
On 12/22/14, 1:24 AM

Thank you for the response. However, I have also observed that when I select the 'Tree' view from the available modes on the right side, the fields_view_get gets invoked each time. But it does not happen  in the case of form view. Also, do you know how to get the context.get('active_ids') to work properly?

contex.get('active_ids') is mostly used in wizards/transient models, and holds the id(s) of model from wich the wizzard is called....

Bole
on 12/22/14, 3:03 AM

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

2 follower(s)

Stats

Asked: 12/20/14, 6:30 AM
Seen: 887 times
Last updated: 3/16/15, 8:10 AM