How it works...

After installing the odoorpc library, you can start using it straightaway. To do so, you will need to import the odoorpc package and then we will create the object of the ODOO class by passing the server URL and port. This will make the /version_info call to the server to check the connection. To log in, you need to use the login() method of the object. Here, you need to pass the database name, username, and password.

Upon successful login, you can access the user information at odoo.env.userodoorpc provides a user-friendly version of RPC so you can use this user object exactly like the recordset in the server. In our example, we accessed the name, email, and company name from this user object.

If you want to access the model registry, you can use the odoo.env object. You can call any model method on the model. Under the hood, the odoorpc library uses jsonrpc so you can't invoke any private model method name that starts with an _. In our example, we accessed the library.book model from the registry. After that, we called the search method with the domain and limit parameters. This will return the IDs of the books. By passing the book IDs to the browse() method, you can generate a recordset for the library.book model. At the end of the program, we created a new book and changed the book state by calling the make_available() method. If you look closely at the syntax of the program, you will see it uses the same syntax as the server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset