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

session global variable in Odoo V8

By
Gabor
on 7/1/15, 9:35 AM 1,062 views

Is there any possibility to define a session global variable which is accessible by several functions of the same class?

Example:

I have an on_change function which creates a dict array in a wizard (validation).

I would like to use that array within an other function (of the same class)


Or

is there any possibility to define a class level variable which is NOT a fields type

like that:

class base_plan(models.Model):

_name = 'base.plan'

account_number = fields.Char(equired=True)

myarray = []

0
Gabor
On 7/3/15, 2:20 PM

I've found the answer. It's easier than I've thought. The answer is python, rather then odoo. :-)

I just have to declare my variable outside of the classes, so it is available by every function within the same module.


Example:

mymodule.py


from openerp import models, fields, api

lines = []

class base_plan(models.Model):

_name = 'base.plan'

account_number = fields.Char(required=True)

name = fields.Char(required=True)


def func1(self)

    mydict = {}

    #some lines come here

    lines.append(mydict)


def func2(self)

    for i in range(0, len(lines)):

        # use lines[]

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: 7/1/15, 9:35 AM
Seen: 1062 times
Last updated: 7/3/15, 2:26 PM