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

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

By
PY
on 11/26/15, 10:09 AM 759 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...

PY
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.

PY
on 11/26/15, 11:03 AM

I'll accept your answer if you convert it.

PY
on 11/26/15, 11:17 AM
0
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 ?

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: 11/26/15, 10:09 AM
Seen: 759 times
Last updated: 11/26/15, 11:26 AM