How it works...

execute_kw is used for the create, update, and delete operations. From Odoo version 12, the create method supports creating of multiple records. So we prepared the dictionary with information from the four books. Then we made the JSON-RPC call with library.book as the model name and create as the method name. This will create four book records in the database and return a JSON response with the IDs of these newly-created books. In the next RPC calls, we want to use these IDs to make an RPC call for update and delete operations, so we assign it to the books_ids variable.

Both JSON-RPC and XML-RPC generate an error when you try to create the record without providing values for the required field, so make sure you have added all the required fields in the create values.

In the next RPC call, we used the write method to update the existing records. The write method accepts two positional arguments; the records to update and the values to write. In our example, we have updated the name of the book by using the ID of the second book from a created book's IDs. This will change the name of the second book from Book 3 to Book 2.

Then we  made the last RPC call to delete two book records. To do so, we used the unlink method. The unlink method accepts only one argument, which is the ID of the records you want to delete. This RPC call will delete the last two books.

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

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