We will create a class to set up the connection with an Odoo server, and read/write To-Do tasks data. It should expose the basic CRUD methods:
- read() to retrieve task data
- write() to create or update tasks
- unlink() to delete a task
Select a directory to host the application files and create the todo_api.py file. We can start by adding the class constructor, as follows:
from xmlrpc import client class TodoAPI(): def __init__(self, srv, port, db, user, pwd): common = client.ServerProxy( 'http://%s:%d/xmlrpc/2/common' % (srv, port)) self.api = client.ServerProxy( 'http://%s:%d/xmlrpc/2/object' % (srv, port)) self.uid = common.authenticate(db, user, pwd, {}) self.pwd = pwd self.db = db self.model = 'todo.task' ...