![]() |
VOOZH | about |
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.
Accessing and integrating live data from Odoo has never been easier with CData. Customers rely on CData connectivity to:
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.
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.
Install the module:
Install-Module OdooCmdlets
Connect:
$odoo = Connect-Odoo -User "$User" -Password "$Password" -URL "$URL" -Database "$Database"
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'}
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 -Connection $Odoo -Columns @('name','email') -Values @('Myname', 'Myemail') -Table res_users -Id "MyId"
$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()
Add-Odoo -Connection $Odoo -Table res_users -Columns @("name", "email") -Values @("Myname", "Myemail")
$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()
Remove-Odoo -Connection $Odoo -Table "res_users" -Id "MyId"
$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
Download a free trial of the Odoo Data Provider to get started:
Download NowLearn more:
👁 Odoo IconRapidly create and deploy powerful .NET applications that integrate with Odoo ERP data, including Sales Orders, Purchase Orders, Accounts,, and more!