Odoo (OpenERP) Development Practice: Access Odoo database via XML-RPC interface

Source: Internet
Author: User

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;import Java.net.url;import java.util.arrays;import java.util.hashmap;import java.util.List; Import Java.util.map;import Org.apache.xmlrpc.client.xmlrpcclient;import  org.apache.xmlrpc.client.xmlrpcclientconfigimpl;/** * * Access Odoo database via XML-RPC interface * [email protected] 8.0 * by WeiChen * */public class Odoowsdemo {public static final string URL = "http://127.0.0.1:8069";p ublic static final String DB = "Demo ";p ublic static final int USERID = 1;public static final String PASS =" Demo ";p ublic static void Main (string[] args) throw S 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 Aeon Mall ");p ut (" 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 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.as (ID)));//Customer list list<object> customers = Arrays.aslist ((object[]) client.execute ("execute_kw", Arrays.aslist (DB, USERID, PASS, "Res.partner", "Search_read", Arrays.aslist (Arrays.aslist (//Set query condition//Arrays.aslist (" Is_company "," = ", True), Arrays.aslist (" customer "," = ", True)), new HashMap () {{///Query Name field, limit return 100 records put (" Fields ", ArRays.aslist ("name"));p ut ("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 ("****************************");}}
Resources:

[1] https://www.odoo.com/documentation/8.0/api_integration.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Odoo (OpenERP) Development Practice: Access Odoo database via XML-RPC interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.