Calling methods using XML-RPC
With Odoo, the RPC API is not limited to CRUD operations; you can also invoke business methods. In this recipe, we will call the make_available
method to change the room’s state.
Getting ready
We will create the Python program to call make_available
on the hostel.room
model. Make sure that you have installed the my_hostel
module and that the server is running on http://localhost:8017
.
How to do it...
Perform the following steps to create, write, and update a room’s information through RPC:
- Add the
rooms_method.py
file. You can place this file anywhere you want because the RPC program will work independently. - Add the following code to the file:
from xmlrpc import client server_url = 'http://localhost:8017' db_name = 'cookbook_17e' username = 'admin' password = 'admin' common = client.ServerProxy('%s/xmlrpc/2/common' % server_url) user_id = common.authenticate(db_name...