Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7480 Lượt xem

I want to call same function from another class-object. I try this but doesn't work.Any help please.

class ClassA(models.Model):
    _name = 'class.a'
        def action_button(self):
              ......
        }

class ClassB(models.Model):
    _name = 'class.b'
    def call_func_b(self):
        self.env["class.b"].action_button()

 <button name="call_func_b" type="object" string="Create Action b"/>


class ClassC(models.Model):
    _name = 'class.c'
    def call_func_c(self):
        self.env["class.c"].action_button()

 <button name="call_func_c" type="object" string="Create Action c"/>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You are almost there except you are calling the method with wrong object.

Try this:

self.env["class.a"].action_button()

If you want to call the method of classA, then you should use the object name of classA (class.a)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 2 25
2494
0
thg 5 24
46
1
thg 4 24
2642
4
thg 9 23
4082
2
thg 9 23
6370