2016-12-20 36 views
1

在自定義模塊中,我有兩個類。 test如何在@api.one上點擊按鈕撥打test2_func來自其他類odoo 9的呼叫功能

我應該在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") 
+0

要調用函數從另一個模型,你可以使用'self.env [「MODEL_NAME」]。myfunction' – yorodm

回答

1

也許我應該離開的答覆,而不是評論。如果您使用Odoo和新的OpenERP API,您可以在模型類中使用self.env模型。所以要調用的函數test2_func模型test2.class你應該寫

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