Automate Odoo Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Odoo data from PowerShell? This article demonstrates how to utilize the Odoo Cmdlets for tasks like connecting to Odoo data, automating operations, downloading data, and more.

The CData Cmdlets for Odoo are standard PowerShell cmdlets 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


PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to Odoo, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Odoo data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Odoo. To access Odoo data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Odoo.

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.

PowerShell

  1. Install the module:

    Install-Module OdooCmdlets
  2. Connect:

    $odoo = Connect-Odoo -User "$User" -Password "$Password" -URL "$URL" -Database "$Database"
  3. Search for and retrieve data:

    $id = "1" $res_users = Select-Odoo -Connection $odoo -Table "res_users" -Where "id = `'$id`'" $res_users

    You can also use the Invoke-Odoo cmdlet to execute SQL commands:

    $res_users = Invoke-Odoo -Connection $odoo -Query 'SELECT * FROM res_users WHERE id = @id' -Params @{'@id'='1'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Odoo\lib\System.Data.CData.Odoo.dll")
  2. Connect to Odoo:

    $conn= New-Object System.Data.CData.Odoo.OdooConnection("User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase;") $conn.Open()
  3. 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

PowerShell

Update-Odoo -Connection $Odoo -Columns @('name','email') -Values @('Myname', 'Myemail') -Table res_users -Id "MyId"

ADO.NET

$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

PowerShell

Add-Odoo -Connection $Odoo -Table res_users -Columns @("name", "email") -Values @("Myname", "Myemail")

ADO.NET

$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

PowerShell

Remove-Odoo -Connection $Odoo -Table "res_users" -Id "MyId"

ADO.NET

$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()

Ready to get started?

Download a free trial of the Odoo Data Provider to get started:

 Download Now

Learn more:

Odoo Icon Odoo ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Odoo ERP data, including Sales Orders, Purchase Orders, Accounts,, and more!