Odoo Help


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.


How to use context in function defined with "self" as sole parameter?

Jeff Beidler
on 11/7/14, 7:31 PM 2,841 views

I have defined my function like this:

    def name_get(self):
        retvals = []     
        for record in self:
            if context.get('prod_form', False):
                catstring =  "[" + record.name + "] " + record.description
        return retvals

I've tried to use "context" by itself, as "self.context", "context.get()", etc.  I get errors all around.  How do I test to see if a context is set, if I use "self" as the only parameter?  Can I just say "def name_get(self, context=None)" ?

Marvin Taboada
On 11/7/14, 10:30 PM

Hello Jeff, good question.

As the new API guidelines state, 'cr', 'uid' and 'context' are encapsulated in the new 'Environment' object.

Property attributes are available in the 'Environment' object for 'user' ('self.env.user') and 'lang' ('self.env.lang').

Context values can be retrieved directly as 'self.env.context.get('value_key', value_if_undefined)',  sample usage at 'res.partner'


Thanks, Marvin! I had read over that part, but it didn't register in my brain. Your example of 'self.env.context.get()' made it click. :)

Jeff Beidler
on 11/10/14, 12:31 PM

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)


Asked: 11/7/14, 7:31 PM
Seen: 2841 times
Last updated: 5/9/16, 8:53 PM