Пример #1
0
 def __init__(self, srv, port, db, user, pwd):
     # port参数必须要使用关键字参数,否则匹配不上
     self.api = ODOO(srv, port=port)
     self.api.login(db, user, pwd)
     self.uid = self.api.env.uid
     self.model = 'library.book'
     self.Model = self.api.env[self.model]
Пример #2
0
class TodoAPI():

    def __init__(self, srv, port, db, user, pwd):
        self.api = ODOO(srv, port=port)
        self.api.login(db, user, pwd)
        self.uid = self.api.env.uid
        self.model = 'todo.task'
        self.Model = self.api.env[self.model]

    def execute(self, method, arg_list, kwarg_dict=None):
        return self.api.execute(
            self.model,
            method, *arg_list, **kwarg_dict)

    def read(self, ids=None):
        domain = [('id',' in', ids)] if ids else []
        fields = ['id', 'name', 'is_done']
        return self.Model.search_read(domain, fields)

    def write(self, text, id=None):
        if id:
            self.Model.write(id, {'name': text})
        else:
            vals = {'name': text, 'user_id': self.uid}
            id = self.Model.create(vals)
        return id

    def unlink(self, id):
        return self.Model.unlink(id)
Пример #3
0
class LibraryAPI():
    def __init__(self, srv, port, db, user, pwd):
        self.api = ODOO(srv, port=port)
        self.api.login(db, user, pwd)
        self.uid = self.api.env.uid
        self.model = 'library.book'
        self.Model = self.api.env[self.model]

    def execute(self, method, arg_list, kwarg_dict=None):
        return self.api.execute(self.model, method, *arg_list, **kwarg_dict)

    def search_read(self, text=None):
        domain = [('name', 'ilike', text)] if text else []
        fields = ['id', 'name']
        return self.Model.search_read(domain or [], fields)

    def create(self, title):
        vals = {'name': title}
        return self.Model.create(vals)

    def write(self, title, id):
        vals = {'name': title}
        self.Model.write(id, vals)

    def unlink(self, id):
        return self.Model.unlink(id)
class LibraryAPI():
    """
    Здесь мы храним всю информацию, необходимую в созданном объекте
    для выполнения вызовов модели: ссылку на API, uid, пароль - pwd,
    имя базы данных - db и используемую модель
    альтернативная реализация интерфейса library_api.py с сервером
    """
    def __init__(self, srv, port, db, user, pwd):
        self.api = ODOO(srv, port=port)
        self.api.login(db, user, pwd)
        self.uid = self.api.env.uid
        self.model = 'library.book'
        self.Model = self.api.env[self.model]

    def execute(self, method, arg_list, kwarg_dict=None):
        """
        вспомогательный метод для выполнения вызовов
        """
        return self.api.execute(self.model, method, *arg_list, **kwarg_dict)

    def search_read(self, text=None):
        domain = [('name', 'ilike', text)] if text else []
        fields = ['id', 'name']
        return self.Model.search_read(domain or [], fields)

    def create(self, title):
        vals = {'name': title}
        return self.Model.create(vals)

    def write(self, title, id):
        vals = {'name': title}
        self.Model.write(id, vals)

    def unlink(self, id):
        return self.Model.unlink(id)
Пример #5
0
def tasks(config, domain=[]):
    odoo = ODOO(config['host'], port=int(config['port']))
    odoo.login(config['dbname'], config['username'], config['password'])
    task_obj = odoo.env['project.task']
    task_ids = task_obj.search(domain)
    tasks = odoo.execute('project.task', 'read', task_ids, ['name'])
    return tasks
Пример #6
0
 def __init__(self, srv, port, db, user, pwd):
     """
     self dalam bahasa pemrograman python dapat diartikan sebagai "class itu sendiri"
     fungsi dari self adalah memanggil sebuah metode di dalam sebuah class
     """
     self.api = ODOO(srv, port=port)
     self.api.login(db, user, pwd)
     self.uid = self.api.env.uid
     self.model = 'res.partner'
     self.Model = self.api.env[self.model]
Пример #7
0
    def __init__(self, srv, port, db, user, pwd):
        self.api = ODOO(srv, port=port)
        self.api.login(db, user, pwd)
        self.uid = self.api.env.uid
        self.model = 'library.book'
        self.Model = self.api.env[self.model]

        def execute(self, method, arg_list, kwarg_dict=None):
            return self.api.execute(self.model, method, *arg_list,
                                    **kwarg_dict)
 def __init__(self, opts, odoo=None):
     self.opts = opts
     if not odoo:
         print("host: %s, port: %s" % (opts.host, opts.port))
         odoo = ODOO(host=opts.host, port=opts.port)
         print(
             "dbname: %s, user: %s, password : %s"
             % (opts.dbname, opts.user, opts.password)
         )
         odoo.login(db=opts.dbname, login=opts.user, password=opts.password)
     self.odoo = odoo
Пример #9
0
 def __init__(self, opts, odoo=None):
     self.opts = opts
     if not odoo:
         print("host: %s, port: %s" % (opts.host, opts.port))
         odoo = ODOO(host=opts.host, port=opts.port)
         print("dbname: %s, user: %s, password : %s" %
               (opts.dbname, opts.user, opts.password))
         odoo.login(db=opts.dbname, login=opts.user, password=opts.password)
     self.odoo = odoo
     self.ail = odoo.env["account.invoice.line"]
     self.pt = odoo.env["product.template"]
     self.mprods = self.pt.browse(self.pt.search([("id", "in", (5, 6, 7))]))
     self.ai = odoo.env["account.invoice"]
Пример #10
0
 def __init__(self, opts, odoo):
     self.opts = opts
     if not odoo:
         print('host: %s, port: %s' % (opts.host, opts.port))
         odoo = ODOO(host=opts.host, port=opts.port)
         print('dbname: %s, user: %s, password : %s' %
               (opts.dbname, opts.user, opts.password))
         odoo.login(db=opts.dbname, login=opts.user, password=opts.password)
     self.odoo = odoo
     self.ail = odoo.env['account.invoice.line']
     self.pt = odoo.env['product.template']
     self.mprods = self.pt.browse(self.pt.search([('id', 'in', (5, 6, 7))]))
     self.ai = odoo.env['account.invoice']
Пример #11
0
class kontakAPI():
    """
    def __init__ adalah konstruktor, yaitu method khusus yang akan dijalankan 
    secara otomatis pada saat sebuah objek dibuat
    """
    def __init__(self, srv, port, db, user, pwd):
        """
        self dalam bahasa pemrograman python dapat diartikan sebagai "class itu sendiri"
        fungsi dari self adalah memanggil sebuah metode di dalam sebuah class
        """
        self.api = ODOO(srv, port=port)
        self.api.login(db, user, pwd)
        self.uid = self.api.env.uid
        self.model = 'res.partner'
        self.Model = self.api.env[self.model]

    def execute(self, method, arg_list, kwarg_dict=None):
        return self.api.execute(self.model, method, *arg_list, **kwarg_dict)

    def search_read(
            self,
            text=None
    ):  #Metode ini menerima ID dan nama kontak yang akan dicari
        domain = [('name', 'ilike', text)] if text else []
        fields = ['id', 'name']
        return self.Model.search_read(domain or [], fields)

    def create(
        self, name
    ):  #Metode ini difunakan untuk membuat kontak baru dengan nama yang diberikan
        vals = {'name': name}
        return self.Model.create(vals)

    def write(self, name,
              id):  #Metode ini digunakan untuk dapat menulis ke dalam kontak
        vals = {'name': name}
        self.Model.write(id, vals)

    def unlink(self, id):  #Berfungsi untuk menghapus ID dari kontak
        return self.Model.unlink(id)
Пример #12
0
    def __init__(self, opts, odoo=None):
        """[summary]
        
        Arguments:
            opts {namespace} -- collection of selected options
        
        Keyword Arguments:
            odoo {odoo instance} -- a running odoo instance or nothing (default: {None})

        log into a running odoo,
        """
        self.opts = opts
        if not odoo:
            print("host: %s, port: %s" % (opts.db_host, opts.port))
            odoo = ODOO(host=opts.db_host, port=opts.port)
            print("dbname: %s, user: %s, password : %s" %
                  (opts.db_name, opts.user, opts.password))
            odoo.login(db=opts.db_name,
                       login=opts.user,
                       password=opts.password)
        self.odoo = odoo
        self.env = odoo.env
        self.ail = odoo.env["account.invoice.line"]
        self.pt = odoo.env["product.template"]
        self.mprods = self.pt.browse(self.pt.search([("id", "in", (5, 6, 7))]))
        self.ai = odoo.env["account.invoice"]

        # open log file
        # we assume it should be relative to where we are running
        try:
            self.logfile_path = os.path.normpath("%s/%s" %
                                                 (MY_PATH, opts.logfile))
            self.logfile = open(self.logfile_path, "w")
        except:
            print(bcolors.FAIL)
            print("*" * 80)
            print("could not open logfile:%s" % self.logfile_path)
            print(bcolors.ENDC)
            sys.exit()
Пример #13
0
class LibraryAPI:
    def __init__(self, srv, port, db, user, pwd):
        self.api = ODOO(srv, port=port)
        self.api.login(db, user, pwd)
        self.uid = self.api.env.uid
        self.model = "library.book"
        self.Model = self.api.env[self.model]

    def search_read(self, text=None):
        domain = [("name", "ilike", text)] if text else []
        fields = ["id", "name"]
        return self.Model.search_read(domain, fields)

    def create(self, title):
        vals = {"name": title}
        return self.Model.create(vals)

    def write(self, title, id):
        vals = {"name": title}
        self.Model.write(id, vals)

    def unlink(self, id):
        return self.Model.unlink(id)
    def __init__(self, opts):
        self.opts = opts

        # open and log in to source odoo
        print("host: %s, port: %s" % (opts.host, opts.port))
        try:
            odoo = ODOO(host=opts.host, port=opts.port)
        except Exception as e:
            print("odoo seems not to run:host: %s, port: %s" %
                  (opts.host, opts.port))
            return
        print("dbname: %s, user: %s, password : %s" %
              (opts.dbname, opts.user, opts.password))
        try:
            odoo.login(db=opts.dbname, login=opts.user, password=opts.password)
        except Exception as e:
            print(
                "could not login to source: dbname: %s, user: %s, password : %s"
                % (opts.dbname, opts.user, opts.password))
            return
        self._odoo = odoo

        # open and log in to target odoo
        print("host: %s, port: %s" % (opts.host, opts.port_2))
        try:
            odoo_2 = ODOO(host=opts.host, port=opts.port_2)
        except Exception as e:
            print("target odoo seems not to run:host: %s, port: %s" %
                  (opts.host, opts.port_2))
            return

        print("dbname: %s, user: %s, password : %s" %
              (opts.dbname_2, opts.user, opts.password))
        try:
            odoo_2.login(db=opts.dbname_2,
                         login=opts.user,
                         password=opts.password)
        except Exception as e:
            print(
                "could not login to target odoo: dbname: %s, user: %s, password : %s"
                % (opts.dbname_2, opts.user, opts.password))
            return

        self._odoo_2 = odoo_2
Пример #15
0
def task_by_id(config, id=0):
    odoo = ODOO(config['host'], port=int(config['port']))
    odoo.login(config['dbname'], config['username'], config['password'])
    return odoo.execute('project.task', 'read', [id], ['name'])
Пример #16
0
def create_new_db(opts):
    # what python do we need to use
    # if we run our old configuration we get it from the project dir
    # if we are running under virtualenv, we have to use this one
    #p.communicate()
    # now wait for 10 secs to allow odoo to spinn up
    # now we can create a new database
    # for this we attach to odoo first
    temp_name = uuid.uuid4().hex 
    site_name = PROJECT_NAME
    p_name = 'erp_bin'
    start_cmd = [
        '%%s/bin/erp_runner.py' %% PROJECT_HOME,
        'start',
        p_name,
        temp_name
    ]
    stop_cmd = [
        '%%s/bin/erp_runner.py' %% PROJECT_HOME,
        'stop',
        p_name,
        temp_name
    ]

    p = Popen(start_cmd, stdout=PIPE, stderr=STDOUT)
    p.communicate()
    print(bcolors.OKBLUE, '\n------------------------------')
    print('started erp system in the background')
    print('now waiting for 5 secs to allow it to spin up')
    print(bcolors.ENDC)
    time.sleep(5)

    odoo = ODOO()
    try:
        odoo.login(PROJECT_NAME, 'admin', opts.password)
    except:
        pass
    if not odoo:
        print(bcolors.FAIL, '\n------------------------------')
        print('could not start odoo')
        print('please try again. If this does not help, look for a prosses using')
        print('ps aux | grep ', p_name)
        print('and kill it')
        print(bcolors.ENDC )
    old_timeout = odoo.config['timeout']
    odoo.config['timeout']=600
    print(bcolors.WARNING, '\n------------------------------')
    print('dropping db:', site_name)
    print(bcolors.ENDC )
    # drop the old db
    try:
        odoo.db.drop('admin', db=site_name) 
    except:
        pass
    print(bcolors.WARNING, '\n------------------------------')
    print('creating new db:', site_name)
    print(bcolors.ENDC )
    odoo.db.create('admin', db=site_name, demo=True, admin_password=opts.password)
    # now kill the process again
    print(bcolors.WARNING, '\n------------------------------')
    print('killing background odoo process again',)
    print(bcolors.ENDC )

    #process_info = get_process_id(p_name)
    p = Popen(stop_cmd, stdout=PIPE, stderr=STDOUT)
    p.communicate()
    print(bcolors.OKGREEN, '------------------------------')
    print('all done',)
    print(bcolors.ENDC )
Пример #17
0
 def __init__(self, srv, port, db, user, pwd):
     self.api = ODOO(srv, port=port)
     self.api.login(db, user, pwd)
     self.uid = self.api.env.uid
     self.model = 'todo.task'
     self.Model = self.api.env[self.model]
Пример #18
0
 def __init__(self, srv, port, db, user, pwd):
     self.api = ODOO(srv, port=port)
     self.api.login(db, user, pwd)
     self.uid = self.api.env.uid
     self.model = "library.book"
     self.Model = self.api.env[self.model]
Пример #19
0
import thread
import time

from odoorpc import ODOO

odoo = ODOO(host='123.207.157.205', port=8888)
uid = odoo.login('custormdb', '*****@*****.**', '8hd3kf6ds9')

q_db = odoo.env['kaikong.qq.list']
q = q_db.search([['buddy.buddy', '=', '1501831170']])
q = q_db.browse(q)
cluster = q.clusters
#cluster = cluster.clusters_id
cc = cluster.search([])


def test():
    task, object, param = odoo.execute_kw('kaikong.qq.task', 'getTask', ('1501831170',))
    print task, object, param


for i in range(0, 20):
    thread.start_new_thread(test)

time.sleep(20)
print 'main thread exit...\n'