Class OdooClient

java.lang.Object
ch.helvethink.odoo.xmlrpc.OdooClient

public class OdooClient extends Object
Abstraction of Odoo's XML-RPC API
  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
      Simple logger
  • Constructor Details

    • OdooClient

      public OdooClient(String instanceUrl, String dbName, String username, String password) throws MalformedURLException, org.apache.xmlrpc.XmlRpcException
      Constructor with direct connection
      Parameters:
      instanceUrl - The odoo Instance URL
      dbName - The odoo DB Name
      username - The Odoo username when authenticating
      password - The Odoo password when authenticating
      Throws:
      MalformedURLException - when URI is not valid
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • OdooClient

      public OdooClient(String instanceUrl, String dbName, String username, String password, boolean mustConnect) throws MalformedURLException, org.apache.xmlrpc.XmlRpcException
      Constructor that initializes the Common API XML-RPC client
      Parameters:
      instanceUrl - The odoo Instance URL
      dbName - The odoo DB Name
      username - The Odoo username when authenticating
      password - The Odoo password when authenticating
      mustConnect - - describes if we must try to connect or not
      Throws:
      MalformedURLException - when URI is not valid
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • OdooClient

      public OdooClient(org.apache.xmlrpc.client.XmlRpcClient commonClient, String instanceUrl, String dbName, String username, String password, boolean mustConnect) throws MalformedURLException, org.apache.xmlrpc.XmlRpcException
      Parameters:
      commonClient - - The common XML-RPC API client
      instanceUrl - The odoo Instance URL
      dbName - The odoo DB Name
      username - The Odoo username when authenticating
      password - The Odoo password when authenticating
      mustConnect - - describes if we must try to connect or not
      Throws:
      MalformedURLException - when URI is not valid
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
  • Method Details

    • getVersion

      public String getVersion() throws org.apache.xmlrpc.XmlRpcException
      Retrieve Version from the Odoo Server
      Returns:
      Version like "17.0"
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • getAllModels

      public List<Map<String,Object>> getAllModels(String packageName) throws org.apache.xmlrpc.XmlRpcException
      Retrieve all Odoo models of the Odoo instance we're connected to
      Parameters:
      packageName - - allows to filter the names of models we want to retrieve
      Returns:
      List of Odoo models with fields like "description", "name", "access_ids", ...
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • getFields

      public Map<String,Map<String,Object>> getFields(String modelName) throws org.apache.xmlrpc.XmlRpcException
      Get fields From Odoo, for a given model
      Parameters:
      modelName - The model we want to inspect
      Returns:
      The list of fields as a Map containing the following information: string, help, type, and relation
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • fetchRelationShips

      public boolean fetchRelationShips(Object o, List<Class<? extends OdooObj>> classesToFetch)
      Fetch relationships from an Odoo object, without recursion
      Parameters:
      o - The object to fetch
      classesToFetch - The list of types we want to fetch, If empty everything will be fetched
      Returns:
      true when succeeded
    • fetchRecursivelyRelationShips

      public boolean fetchRecursivelyRelationShips(Object o, int depth, List<Class<? extends OdooObj>> classesToFetch)
      The same as fetchRelationShips(Object, List) but recursively Warn! Since there are a lot of relationships, this increases number of calls and might be less performant Ideally when using depth, indicate the classes you want to fetch to avoid wasting time
      Parameters:
      o - The initial object we want to fetch relationships for
      depth - The depth to which we want to fetch Objects
      classesToFetch - The list of types we want to fetch
      Returns:
      true if operation is a success
    • findByCriteria

      public <T extends OdooObj> List<T> findByCriteria(int limit, Class<T> classToConvert, String... criteria) throws org.apache.xmlrpc.XmlRpcException
      Find an Odoo object using criteria. If no criteria, will send all the objects (id >=0 )
      Type Parameters:
      T - The target type
      Parameters:
      limit - Number of objects we want to retrieve
      classToConvert - Type of the target object
      criteria - The search criteria
      Returns:
      List of corresponding objects
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • fetchObjectById

      public <T extends OdooObj> T fetchObjectById(String modelName, OdooId idToFetch, Class<T> classToConvert) throws org.apache.xmlrpc.XmlRpcException
      Fetch an object by its id
      Type Parameters:
      T - The type of the target Object
      Parameters:
      modelName - The Odoo model name
      idToFetch - The id of the object we want to fetch
      classToConvert - The type of the target Object
      Returns:
      The object fetched
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • fetchListByIdsInt

      public <T extends OdooObj> List<T> fetchListByIdsInt(String modelName, List<Integer> idsToFetch, Class<T> classToConvert)
      Type Parameters:
      T - The type of the target objects If an exception occured, will send back an empty list
      Parameters:
      modelName - The Odoo model name
      idsToFetch - The ids of objects we want to fetch
      classToConvert - The type of the target objects
      Returns:
      List of built objects
    • fetchListByIds

      public <T extends OdooObj> List<T> fetchListByIds(String modelName, List<OdooId> idsToFetch, Class<T> classToConvert) throws org.apache.xmlrpc.XmlRpcException
      Same as above but with Odoo Ids, and no catch of the exception
      Type Parameters:
      T - The type of the target objects
      Parameters:
      modelName - The Odoo model name
      idsToFetch - The ids of objects we want to fetch under the form of OdooId
      classToConvert - The type of the target objects
      Returns:
      List of built objects
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API