简体   繁体   中英

Call python object - odoo 9

In python console(jupyter) I use a python library in the form:

class SomeClass(object) 
    def __init__(self, arg1, arg2):
        ... 
    def fct1(self):
        ...
    return something

And I get no problem creating an object with:

x = SomeClass(arg1,arg2)

I would like to use those methods in Odoo. I tried the following:

class SomeClass(**models.Model**)
    def **connect**(self, arg1, arg2):
        ...
    def fct1(self):
        ...
    return something

Replacing "object" with "model,Models" to have it as an odoo class + renaming init with a method name.

But

x = connect(arg1,arg2)

returns :

NameError: global name 'connect' is not defined

How would I use my python library in Odoo (new API)?

TIA

UPDATE:

I also tried calling

x= self.connect(arg1,arg2) or x=SomeClass.connect(arg1,arg2)

but it return "None" when I "print x". I think an instance is not created

thank you to zbik for the answer:

myclass.py in folder myaddons

class MyClass:
    def __init__(self, name):
        self.name = name
    def _test(self,a,b):
        return a+b

in other Odoo class:

from openerp.addons.myaddons.myclass import MyClass
...
x = MyClass('Hello')
y = x._test(2,3)
...
print x.name
> Hello
print y
> 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM