Package ch.helvethink.odoo.xmlrpc
Class OdooClient
java.lang.Object
ch.helvethink.odoo.xmlrpc.OdooClient
Abstraction of Odoo's XML-RPC API
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOdooClient(String instanceUrl, String dbName, String username, String password) Constructor with direct connectionOdooClient(String instanceUrl, String dbName, String username, String password, boolean mustConnect) Constructor that initializes the Common API XML-RPC clientOdooClient(org.apache.xmlrpc.client.XmlRpcClient commonClient, String instanceUrl, String dbName, String username, String password, boolean mustConnect) -
Method Summary
Modifier and TypeMethodDescriptionfetchListByIds(String modelName, List<OdooId> idsToFetch, Class<T> classToConvert) Same as above but with Odoo Ids, and no catch of the exceptionfetchListByIdsInt(String modelName, List<Integer> idsToFetch, Class<T> classToConvert) Same asfetchObjectById(String, OdooId, Class)but with a List<T extends OdooObj>
TfetchObjectById(String modelName, OdooId idToFetch, Class<T> classToConvert) Fetch an object by its idbooleanfetchRecursivelyRelationShips(Object o, int depth, List<Class<? extends OdooObj>> classesToFetch) The same asfetchRelationShips(Object, List)but recursively Warn!booleanfetchRelationShips(Object o, List<Class<? extends OdooObj>> classesToFetch) Fetch relationships from an Odoo object, without recursionfindByCriteria(int limit, Class<T> classToConvert, String... criteria) Find an Odoo object using criteria.getAllModels(String packageName) Retrieve all Odoo models of the Odoo instance we're connected toGet fields From Odoo, for a given modelRetrieve Version from the Odoo Server
-
Field Details
-
LOG
public static final org.slf4j.Logger LOGSimple 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 URLdbName- The odoo DB Nameusername- The Odoo username when authenticatingpassword- The Odoo password when authenticating- Throws:
MalformedURLException- when URI is not validorg.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 URLdbName- The odoo DB Nameusername- The Odoo username when authenticatingpassword- The Odoo password when authenticatingmustConnect- - describes if we must try to connect or not- Throws:
MalformedURLException- when URI is not validorg.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 clientinstanceUrl- The odoo Instance URLdbName- The odoo DB Nameusername- The Odoo username when authenticatingpassword- The Odoo password when authenticatingmustConnect- - describes if we must try to connect or not- Throws:
MalformedURLException- when URI is not validorg.apache.xmlrpc.XmlRpcException- when an error occurs with the XML-RPC API
-
-
Method Details
-
getVersion
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, getFieldsObject>> (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
Fetch relationships from an Odoo object, without recursion- Parameters:
o- The object to fetchclassesToFetch- 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 asfetchRelationShips(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 fordepth- The depth to which we want to fetch ObjectsclassesToFetch- 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 retrieveclassToConvert- Type of the target objectcriteria- 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 nameidToFetch- The id of the object we want to fetchclassToConvert- 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) Same asfetchObjectById(String, OdooId, Class)but with a List- Type Parameters:
T- The type of the target objects If an exception occured, will send back an empty list- Parameters:
modelName- The Odoo model nameidsToFetch- The ids of objects we want to fetchclassToConvert- 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 nameidsToFetch- The ids of objects we want to fetch under the form ofOdooIdclassToConvert- 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
-