从其他类odoo 9调用函数

时间:2016-12-20 15:15:05

标签: openerp odoo-9

在自定义模块中,我有两个类。 test中的@api.one课程如何在点击按钮上调用test2_func

我应该在def call_test2_func(self)中添加什么?

例如:

class test(models.Model):
    _name = "test.class"
    _description = "TEST"
@api.one
    def call_test2_func(self):
  """call test2_func here"""

class test2(models.Model):
    _name = "test2.class"
    _description = "TEST 2"

@api.one
    def test2_func(self):
        print("TEST 2")

1 个答案:

答案 0 :(得分:3)

也许我应该留言而不是评论。如果您正在使用Odoo和新的OpenERP api,您可以通过模型类中的self.env访问模型词典。因此,要在模型test2_func中调用函数test2.class,您应该编写

@api.one
def call_test2_func(self):
    self.env["test2.class"].test2_func()
相关问题