简体   繁体   中英

Insert record in odoo PostgreSQL database from c# and see record in Odoo

I'm trying to insert a new client record in Odoo8 PostrgreSQL database using c#.

To connect with PostgreSQL database from c# , i use npgsql .

here is my Insert command

cmd.CommandText = "INSERT INTO res_partner (name,email,notify_email ,active) VALUES ('user name','username@yahoo.fr','username@yahoo.fr'," + true + ")";

I'm able to see the new insert record in res_partner table using pgAdmin, but using Odoo , i'm not able to see the new client.

Odoo has a Web Service api which is better to use to interact with external application. With a little research, I found that interesting wrapper: OdooRpcWrapper . I used it in my application and everything works fine. I'm now able to see new added client from c# in Odoo8.

Code to add new client:

OdooConnectionCredentials creds = new OdooConnectionCredentials("http://localhost:8069", "your_bd", "admin", "admin");
OdooAPI api = new OdooAPI(creds);
//Define what model you want to use
OdooModel partnerModel = api.GetModel("res.partner");
//Create new objects by calling the model. New objects need to be saved.
OdooRecord record = partnerModel.CreateNew();
record.SetValue("name", "Abdelaziz test");
record.Save();

Step to use it in asp.net Webforms application:

  1. Download OdooRpcWrapper from github
  2. add it to your project: right click on solution => add => existing project and select the wrapper
  3. add it as reference in your asp project: right click on reference => add reference => under solution tab, select OdooRpcWrapper project you added earlier
  4. use the code to add new client

Logically you can see changes in db in Odoo UI without using Odoo Web API

When you insert records in PostgreSQl db of odoo using webservice or manual from PgAdmin, you must insert values in all columns that not accept null to be reflected in odoo UI.

From pgadmin you can right click on a table, select properties to see which columns don't accept null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM