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 actually use and modify context?

By
Alejandro Santana
on 12/30/14, 7:01 PM 4,226 views

When trying to use the context to avoid an onchange flieds recursion situation (see my other question about it: https://www.odoo.com/es_ES/forum/help-1/question/how-to-deal-with-api-depends-recursion-in-v8-71901 ), I tried doing:

self.with_context(skip_onchange_zip_ids=True).update()

That was in order to get that 'skip_onchange_zip_ids' from context in another onchange method to abort it to avoid infinite change recursion.

But I get this error:

TypeError: update() takes exactly 2 arguments (1 given)

So, how to actually use and modify context? What I am missing?

 

 

0

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 12/31/14, 12:27 AM

Change Context (more info at https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L5214)

rec_set2 = rec_set.with_context(context2)
rec_set2 = rec_set.with_context(lang='IN')

self.with_context(skip_onchange_zip_ids=True)

Perfect. This solved the problem. The ".update()" part was not necessary.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/5/15, 5:06 AM
1

Jeudy Nicolas

--Jeudy Nicolas--
1181
| 6 7 8
PELOUSEY, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 12/31/14, 5:02 AM

Hello, 

I you want to add a new param to existing context you can:

self.with_context(skip_onchange_zip_ids=True)

Doc:

# 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}

Note: please valid correct answer to have your question closed

 

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

3 follower(s)

Stats

Asked: 12/30/14, 7:01 PM
Seen: 4226 times
Last updated: 3/16/15, 8:10 AM