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

Change context from within controller

By
Odooveloper (by Rui Franco)
on 6/21/16, 4:39 PM 415 views

I'm trying to update context from within class DataSet(http.Controller) (web module)


I want the do_search_read method to change the context of the caller. However, although everything seems to be fine, the context is not updated.


Here's my code:


if model == 'mymodel':

     request.context['result_ids'] = [x.product_tmpl_id.id for x in Model.browse(aux)]

 

request.context is, indeed, updated but the caller's context remains the same.

NOTE: I've already tried the "antidote" to the "frozen dictionary" problem.

The code here is just that an example.

Odooveloper (by Rui Franco)
on 6/22/16, 9:13 AM
1
Nikunj Antala
On 6/22/16, 9:09 AM

Hello Rui Franco

context is a frozen dictionary. so, we can not directly change.

you can try this.    

     request.with_context({'result_ids':[x.product_tmpl_id.id for x in Model.browse(aux)]})


Hope this help.

Thanks but it won't work:

AttributeError: 'JsonRequest' object has no attribute 'with_context'

Odooveloper (by Rui Franco)
on 6/22/16, 9:14 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

1 follower(s)

Stats

Asked: 6/21/16, 4:39 PM
Seen: 415 times
Last updated: 6/22/16, 9:09 AM