Call function from other class odoo 9

2.1k views Asked by At

In a custom module I have two classes. How can class test in @api.one call test2_func on a button click?

What should I put in def call_test2_func(self)?

For example:

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

There are 1 answers

0
yorodm On BEST ANSWER

Maybe I should leave a reply instead of a comment. If you're using Odoo and the new OpenERP api you can can access the model dictionaty though self.env in your model classes. So to call the function test2_func in the model test2.class you should write

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