Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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'])