Giter Club home page Giter Club logo

odooconnect-android's Introduction

OdooConnect is a helper to access Odoo 10 servers from Android devices.

You can modify it and add extra functionality, if needed for your apps.

This class is based on OpenErpConnect (for old version of Odoo) which uses the android-xmlrpc connector. In this case I use the aXMLRPC connector which is more easy to implement.

To connect from Android to Odoo you will need to use android AsyncTask. In my case, I have not achieved it in any other way. Here is an app example.

Here are some features:

(For more information see the source and its comments)

Test Connection

Try connection to server. Return true if the connection is successful.

try {

    Boolean ocT = OdooConnect.testConnection("url_server", port,
            "name_database", "user_name", "password");

} catch (Exception ex) {
    System.out.println("Error: " + ex);
}

Search / Read

In this case returns a name/phone list from model res.partner where contacts are Customer but not Company. In case there was any field related to another model we could also obtain such data.

try {
    OdooConnect oc = OdooConnect.connect("url", port, "db", "username", "password");

    Object[] param = {new Object[]{
                    new Object[]{"customer", "=", true},
                    new Object[]{"is_company", "=", false}}};

    List<HashMap<String, Object>> data = oc.search_read("res.partner", param, "name", "phone");

    String msgResult = "";
    for (int i = 0; i < data.size(); ++i) {
        msgResult += "\n" + data.get(i).get("name");
    }
    System.out.println(msgResult);

} catch (Exception ex) {
    System.out.println("Error: " + ex);
}

Search Count

Returns the total number of contacts.

try {
    OdooConnect oc = OdooConnect.connect("url", port, "db", "username", "password");

    Object[] param = {new Object[0]{}};
    Integer ids = oc.search_count("res.partner", param);
    System.out.println("Num. of customers: " + ids.toString() + "\n");

} catch (Exception ex) {
    System.out.println("Error: " + ex);
}

Create

Creates a new record for the model res.partner. In this case create a new Company and returns his id.

try {
    OdooConnect oc = OdooConnect.connect("url", port, "db", "username", "password");

    @SuppressWarnings("unchecked")
    Integer idC = oc.create("res.partner", new HashMap() {{
        put("name", "name_company");
        put("phone", "contact_phone");
        put("is_company", True);
    }});
    msgResult = idC.toString();
    System.out.println(idC.toString());

} catch (Exception ex) {
    System.out.println("Error: " + ex);

}

Write

Modify an existing record. Returns true if the action is successful.

try {

    OdooConnect oc = OdooConnect.connect("url", port, "db", "username", "password");

    Boolean idW = oc.write("res.partner", new Object[]{ id_record },
      new HashMap() {{
          put("mail", "new_mail");
          put("phone", "new_phone");
      }});

} catch (Exception ex) {
    System.out.println("Error: " + ex);
}

Unlink

Delete an existing record. Return true if the record is deleted.

try {

    OdooConnect oc = OdooConnect.connect("url", port, "db", "username", "password");

    Boolean idW = oc.write("res.partner", new Object[]{ id_record });

} catch (Exception ex) {
    System.out.println("Error: " + ex);
}

Call

This is a generic method to call any action.

try {

    OdooConnect oc = OdooConnect.connect("url", port, "db", "username", "password");

    Object[] param = {new Object[]{
                    new Object[]{"customer", "=", false}};
    Object[] fields = {new Object[]{"name", "mail", "phone"};

    Object[] idW = oc.call("res.partner", "search", 0, 15, param, fields);

} catch (Exception ex) {
    System.out.println("Error: " + ex);
}

odooconnect-android's People

Contributors

edu095 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

odooconnect-android's Issues

I can't connect to my odoo local from the android emulator.

Greetings. I have odoo installed in my laptop and also Android Studio. I'm able to open odoo instalation from the browser inside the emulator, so it's conected. I'm trying to use this library to connect an app with an odoo server. The problem is that when the login method gets to this sentence client.call("authenticate", list); I get a "false" response, instead of an integer, so after that it throws an error. Can you tell me why is that happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.