我有点怀疑。我是odoo 8的新手,所以在我的模型中,我使用Sel.env‘# model’来访问特定的模型。现在,我的模型中有大约10个不同的函数,在每个模型中,我使用模型env引用其他两个模型。以下是代码:
def test(self):
location = self.env['stock.location']
# i get values from database models
def test1(self):
location = self.env['stock.location']
# i get values from database models现在,我需要在两个不同的函数中使用相同的环境。是否有类似于__init__函数的方法,它将初始化模型对象,我们可以在所有函数中使用它。
谢谢,
发布于 2016-07-07 19:58:24
当然,您只需将其设置为类的属性,并使用如下所示的self
def test(self):
self.location_obj = self.env['stock.location']
# i get values from database models
def test1(self):
# You can use self.location in this method and other methods
self.location_obj.search([('id', '=', 1)])从现在开始,您可以在类中的任何方法中访问self.location (静态方法除外)。但你不需要这个)
https://stackoverflow.com/questions/38253348
复制相似问题