2
votes

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
To call a function from another model you can use self.env["model_name"].myfunctionyorodm

1 Answers

4
votes

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()