How it works...

In this recipe, we performed create, write, and delete operations through XML-RPC. This operation also uses the /xmlrpc/2/object endpoint and the execute_kw method.

From Odoo v12, the create() method supports the creation of multiple records in a single call. In step 2we first created a dictionary with the book's information. Then we used the book's dictionary to create new records of the books through XML-RPC. The XML-RPC call needs two parameters to create new records—the create method name and the book data. This will create the four book records in the library.book model. In ORM, when you create the record, it returns a recordset of created records, but if you create the records RPC, it will return a list of IDs.

The write method works in a similar way to the create method. In the write method, you will need to pass a list of record IDs, and the field values, to be written. In our example, we updated the name of the book created in the first section. This will update the name of the second book from Book 3 to Book 2. Here, we passed only one id of the book, but you can pass a list of IDs if you want to update multiple records in a single call.

In the third section of the program, we deleted two books that we'd created in the first section. You can delete records with the unlink method and list of record IDs.

After the program is executed successfully, you will find two book records in the database.

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

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