Odoo Help


[8] How to pass context from request to model ?

on 11/26/15, 10:09 AM 1,531 views

I created two radio inputs on the `/shop/product/<product>` page.

When the user clicks the `Add to cart` button, the value of the selected radio is passed to the controller, to the function `cart_update`.

There, I can check which radio input was checked, then put some value in the `request.context` dictionnary for example.

However, in the model functions called by the original `cart_update`  function, the context (`self.env.context`) does not show my value.

So, how can I notify model functions such as `_cart_find_product_line`, without redefining completly the controller function `cart_update`, which is a very bad practice ?

food for thought: I think self.env.context holds the server context, and request.context holds the client context. Can the solution be sessions ? But can the server access the session of the current user asking the method ? That's silly I think...

on 11/26/15, 10:27 AM

It should, but the call to this method is in the middle of the sale_order._cart_update function. I choose to override a smaller function (website_sale.cart_update) and make use of the **kwargs argument.

on 11/26/15, 11:03 AM

I'll accept your answer if you convert it.

on 11/26/15, 11:17 AM
Guillaume Seran
On 11/26/15, 11:25 AM

Hi, if you use this -> self.env['models.mymodel'].with_context(param=value)._cart_find_product_line(vals) // it doesn't work ?

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/26/15, 10:09 AM
Seen: 1531 times
Last updated: 11/26/15, 11:26 AM