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.

0

Odoo v8: How can I change the context trough python code.

By
Sergej
on 4/13/15, 4:57 AM 1,007 views

The context of self is a frozendict. Is there a way to change this context of self or is there another way to alter context in odoo v8 ?

1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3918
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 4/13/15, 5:32 AM

by using self.with_context you can add context value.

Passing single value:
    self = self.with_context(default_partner_id: partner_id)

Passing multiple value as a dictionary (ctx) self = self.with_context(ctx)
Note:you need to re-assign the changed context to self.  If this is not done, then the context will not be passed to other functionalities.

Code available @ github: https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L5266-L5283

def with_context(self, *args, **kwargs): 
""" with_context([context][, **overrides]) -> records
Returns a new version of this recordset attached to an extended
context.
The extended context is either the provided ``context`` in which
``overrides`` are merged or the *current* context in which
``overrides`` are merged e.g.::
# current context is {'key1': True}
r2 = records.with_context({}, key2=True)
# -> r2._context is {'key2': True}
r2 = records.with_context(key2=True)
# -> r2._context is {'key1': True, 'key2': True}
"""

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: 4/13/15, 4:57 AM
Seen: 1007 times
Last updated: 4/13/15, 6:03 AM