Automate Odoo Integration Tasks from PowerShell
The CData ADO.NET Provider for Odoo is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Odoo.
About Odoo Data Integration
Accessing and integrating live data from Odoo has never been easier with CData. Customers rely on CData connectivity to:
- Access live data from both Odoo API 8.0+ and Odoo.sh Cloud ERP.
-
Extend the native Odoo features with intelligent handling of many-to-one, one-to-many, and many-to-many data properties. CData's connectivity solutions also intelligently handle complex data properties within Odoo. In addition to columns with simple values like text and dates, there are also columns that contain multiple values on each row. The driver decodes these kinds of values differently, depending upon the type of column the value comes from:
- Many-to-one columns are references to a single row within another model. Within CData solutions, many-to-one columns are represented as integers, whose value is the ID to which they refer in the other model.
- Many-to-many columns are references to many rows within another model. Within CData solutions, many-to-many columns are represented as text containing a comma-separated list of integers. Each value in that list is the ID of a row that is being referenced.
- One-to-many columns are references to many rows within another model - they are similar to many-to-many columns (comma-separated lists of integers), except that each row in the referenced model must belong to only one in the main model.
- Use SQL stored procedures to call server-side RFCs within Odoo.
Users frequently integrate Odoo with analytics tools such as Power BI and Qlik Sense, and leverage our tools to replicate Odoo data to databases or data warehouses.
Getting Started
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Odoo; this tutorial shows how to use the Provider to create, retrieve, update, and delete Odoo data.
Once you have acquired the necessary connection properties, accessing Odoo data in PowerShell can be enabled in three steps.
To connect, set the Url to a valid Odoo site, User and Password to the connection details of the user you are connecting with, and Database to the Odoo database.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Odoo\lib\System.Data.CData.Odoo.dll") -
Connect to Odoo:
$conn= New-Object System.Data.CData.Odoo.OdooConnection("User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase;") $conn.Open() -
Instantiate the OdooDataAdapter, execute an SQL query, and output the results:
$sql="SELECT name, email from res_users" $da= New-Object System.Data.CData.Odoo.OdooDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.email }
Update Odoo Data
$cmd = New-Object System.Data.CData.Odoo.OdooCommand("UPDATE res_users SET id='1' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Odoo.OdooParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Odoo Data
$cmd = New-Object System.Data.CData.Odoo.OdooCommand("INSERT INTO res_users (id) VALUES (@myid)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Odoo.OdooParameter("@myid","1")))
$cmd.ExecuteNonQuery()
Delete Odoo Data
$cmd = New-Object System.Data.CData.Odoo.OdooCommand("DELETE FROM res_users WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Odoo.OdooParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject