OdooRPC is a python module used as an easy way to connect to an Odoo instance. As we know, XML-RPC is officially promoted way to connect to an Odoo instance, but let’s be honest over here. It is difficult to work with and a bit hard for someone who is a beginner. That’s where OdooRPC comes in.
OdooRPC is a project developed under the Odoo Community Association and is publicly hosted as an open-source project on GitHub with an LGPLv3 license. You can try the module by either installing or directly importing it into your python script. In order to install OdooRPC, clone the GitHub repository onto your local machine. And then run the following command inside the cloned directory.
python setup.py install
Or run the following command inside the cloned directory.
pip install .
Once installed, we can use the module by importing it into our python script. Also, you can use the python package without installing the same on your machine. In order to do that, clone or download the repository and run your script just outside of the cloned repository so it will import correctly in your script. Let us look at a sample below.
import odoorpc # Import the python module # Prepare the connection to the server. Replace localhost # with the IP address or domain name of your odoo instance # Replace the port also accordingly odoo = odoorpc.ODOO('localhost', port=8069) # Check available databases. This will list all databases print(odoo.db.list()) # Login # Provide the database which we intends to connect and the # credentials for the same. odoo.login('db_name', 'user', 'password') # Current user user = odoo.env.user print(user.name) # name of the user connected print(user.company_id.name) # the name of user's company # Use all methods of a model if 'sale.order' in odoo.env: Order = odoo.env['sale.order'] order_ids = Order.search() for order in Order.browse(order_ids): print(order.name) products = [line.product_id.name for line in order.order_line] print(products) # Update data through a record user.name = "Brian Jones"
As you can see browse, search methods work with OdooRPC, and it is a great help when we need to connect and do some in the database without directly spawning up a terminal on the instance. There are still some differences when compared to ORM, but it is not a big issue since a beginner of Odoo will be able to easily understand the work.
You can be creative and do lots of things using this module, like data importing, etc. The possibilities are limitless. Using such similar examples, you will improve your whole workflow using this module. Please note that the module has some issues with Python 3.10 and Odoo 15. Fixes for the python issue are already in the pipeline, and the issue with Odoo 15 should be fixed soon. If you need to test the same with Python 3.10 and Odoo 15, you can use this GitHub repository which contains the fixes for the same.
If you plan a new ERP Software implementation and you have heard about Odoo and got attracted by the Odoo ERP platform, decided to use it but don’t have time, resources, or knowledge to manage this yourself, thereby looking for professional assistance, then you have come to a right place. Bassam Infotech has implemented scores of Odoo ERP all around the world. In addition, we have also developed and delivered our own customized Odoo applications with minimal Odoo implementation cost.