This question has been flagged
1 Reply
3616 Views

Hi everyone, 

I'm currently trying to implement a client-side variable on Odoo 10 (if that makes any sense).

What I mean by that would be a variable usable globally in Odoo, easily readable/editable, and bound to only one computer.

I tried several methods:

  1.  In my ignorance, I tried to use a python file globalv.py inside which I put the line "variable=0". Then I imported it anytime I needed the variable in my code. This way I had almost everything I needed, except that the variable was shared by every computer of the network. It made me understand that the python methods were only used server side (at least to my knowledge).

  2. I then tried to use Javascript which is said to be client-side. As a complete beginner, I defined a variable in an odoo function but couldn't export it in order to use it or manipulate it like something passed by reference in C++ (I think I can't use pointers here). Therefore, I gave up on Javascript as well. 

  3. Then I tried to use the context, because I believe it to be client-side (not sure tho?). The problem is, it seems the context is in fact bound to a recordset, and it looks complicated to pass my variable everytime and everywhere since I in fact need it everytime and everywhere.

Finally I imagined that the user accessible with self.env.user, is client-side as two computers can connect to two different users even though they're connected to the same server. I tried to modify the api completely to include a variable inside the environment class and a custom sudo that would edit this variable but I gave up since little by little, I was modifying every method and class.

I hope you can tell me if I'm being logical here or if it's completely impossible to implement such a thing. (And if someone can explicit what is the context or see some inaccurate detail here, please feel free to share your knowledge too)



Avatar
Discard

I really appreciate for your efforts to add all the possible details in the question. Such details really help people to give answer. +1 for good question and enough details.

Best Answer

Hi Antoine,

Why don't you use Odoo HTTP session? This will be saved at client-side for temporary time period.

from odoo.http import request

# Save value in session by using current logged user ID as key
request.session[request.env.uid] = 'Your Value'

#Get session value
print request.session[request.env.uid]

I hope this will help you at some level to move further.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Avatar
Discard