Transferring data from one instance to another using XML-RPC involves connecting both instances through their respective XML-RPC endpoints and performing data migration tasks. And XML-RPC is actually a protocol that helps remote procedure calls over HTTP using XML to encode the request and response. This method is used to transfer data between two separate Odoo instances.
To facilitate communication between different systems or applications, Odoo (formerly known as OpenERP) utilizes the XML-RPC (Remote Procedure Call) protocol. This protocol allows remote execution of methods and data retrieval from an Odoo instance, with XML serving as the transport format.
Through the web service API provided by XML-RPC, an external system can interact with an Odoo server. This API empowers users to execute various operations, including record creation or updates, data queries, execution of business logic, and more.
Here is an example for transferring crm lead records from Odoo 16 to Odoo 17 using XML-RPC. For that, we can create a new python file for adding the scripts.
There are different steps to follow.
Step 1: Install Required Python Libraries
Ensure you have Python and the xmlrpc.client module (built-in for Python 3). Use the following import:
import xmlrpc.client
Step 2: Define Connection Settings
Set up connection details for both Odoo 16 and Odoo 17 servers:
url_db1 = "http://127.0.0.1:8016"
db_1 = 'odoo16_db'
username_db_1 = 'admin'
password_db_1 = 'admin'
common_1 = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url_db1))
models_1 = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url_db1))
version_db1 = common_1.version()
url_db2 = "http://localhost:8027"
db_2 = 'odoo17_db'
username_db_2 = 'admin'
password_db_2 = 'admin'
common_2 = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url_db2))
models_2 = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url_db2))
version_db2 = common_2.version()
common_1: Connects to the common endpoint of the XML-RPC API, which is used for authentication and general information about the database.
models_1: Connects to the object endpoint of the XML-RPC API, which is used for interacting with models (CRUD operations).
common_2: This proxy connects to the common endpoint of the second Odoo database (url_db2) for authentication and general metadata.
models_2: This proxy connects to the object endpoint of the second Odoo database (url_db2) for performing CRUD operations.
Step 3: Authenticate
Authenticate to both Odoo 16 and Odoo 17 instances
uid_db1 = common_1.authenticate(db_1, username_db_1, password_db_1, {})
uid_db2 = common_2.authenticate(db_2, username_db_2, password_db_2, {})
Step 4: Fetch Data From Odoo 16
Fetch data from Odoo 16 for the model you want to transfer. For example, transferring crm leads:
db_1_leads = models_1.execute_kw(db_1, uid_db1, password_db_1, 'crm.lead', 'search_read', [[]], {'fields': ['id', 'name', 'email_from']})
Step 5: Insert Data Into Odoo 17
Insert the fetched data into Odoo 17. Ensure that field mappings are correct:
new_lead = models_2.execute_kw(db_2, uid_db2, password_db_2, 'crm.lead', 'create', [db_1_leads])
The Odoo 17 CRM lead page is empty before transferring the data.
Odoo 16 CRM lead page to transfer
python3 -m data_transfer -> Use this command to run the python script. data_transfer is the python file that includes the above scripts.
After running the python script go to the Odoo 17 CRM lead page then we can see all leads from the Odoo 16 will be transferred to Odoo 17.
This is the method commonly used to transfer the data from Odoo 16 to Odoo 17 using XML-RPC.
To read more about How to Transfer Data From Odoo 15 to Odoo 16 Using XML-RPC, refer to our blog How to Transfer Data From Odoo 15 to Odoo 16 Using XML-RPC.