The Odoo server supports accessing and manipulating databases through the XML-RPC interface, which enables interaction and integration with other systems.
This article is a simple example of using Java to operate the Odoo database via the Xmlrpc interface. The jar packages referenced in this example include Xmlrpc-common-3.1.3.jar, Xmlrpc-client-3.1.3.jar, and Ws-commons-util-1.0.2.jar, which can be downloaded here if required.
Package Memo.by.weichen;ImportJava.net.URL;Importjava.util.Arrays;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;Importorg.apache.xmlrpc.client.XmlRpcClient;ImportOrg.apache.xmlrpc.client.XmlRpcClientConfigImpl;/** * * through xml-RPC Interface access to Odoo database* [EMAIL protected] 8.0 *by Weichen* */ PublicclassOdoowsdemo {public static final String URL="http://127.0.0.1:8069"; public static final String DB="Demo"; public static final int USERID= 1; public static final String PASS="Demo"; public static void Main (string[] args) throws exception{Xmlrpcclientconfigimpl config=new Xmlrpcclientconfigimpl (); Xmlrpcclient Client=new Xmlrpcclient (); Config.setserverurl (New URL (String.Format ("%s/xmlrpc/2/object", URL))); Client.setconfig (config); //New customer Integer ID=(Integer) Client.execute ("execute_kw", Arrays.aslist (DB, USERID, PASS,"Res.partner","Create", Arrays.aslist (new HashMap () {{put ("name","Suzhou Park Yong Wang Dream City"); Put ("Customer", boolean.true); } }))); //Update Customer Client.execute ("execute_kw", Arrays.aslist (DB, USERID, PASS,"Res.partner","Write", Arrays.aslist (arrays.aslist (ID), new HashMap () {put ("name","Aeon Mall Suzhou Park Store"); }} ) )); //Find a customer List<Object> Partners = Arrays.aslist ((object[]) Client.execute ("execute_kw", Arrays.aslist (DB, USERID, PASS,"Res.partner","Name_get", Arrays.aslist (arrays.aslist (ID)))); if(Partners!=null&&partners.size () >0) {//Partners Format: [[ID, name]] object[] Partner=(object[]) partners.get (0); if(partner.length==2) System.out.println ("Customer Name:"+partner[1]); } //Delete Customer Client.execute ("execute_kw", Arrays.aslist (DB, USERID, PASS,"Res.partner","unlink", Arrays.aslist (arrays.aslist (ID))); //List of Customers<Object> customers =arrays.aslist ((object[]) Client.execute ("execute_kw", Arrays.aslist (DB, USERID, PASS,"Res.partner","Search_read", Arrays.aslist (Arrays.aslist (//Set query CriteriaArrays.aslist ("Is_company","=", True), Arrays.aslist ("Customer","=", True)), new HashMap () {{//Query the Name field to limit the return of up to 100 records put (" Fields", Arrays.aslist ("name")); Put ("Limit", 100); } }))); System.out.println ("********** Customer List **********"); for(int i=0;i<customers.size (); i++) {MAP customer=(MAP) customers.get (i); String name= (String) customer.get ("name"); SYSTEM.OUT.PRINTLN (name); } System.out.println ("****************************"); }}
Odoo (OpenERP) Development Practice: Access Odoo database via XML-RPC interface