Skip to content

Commit f646325

Browse files
committed
Deal with the context in main functions regarding to the Odoo version
1 parent 3c944f5 commit f646325

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/main/java/com/debortoliwines/odoo/api/OdooCommand.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public OdooCommand(Session session) {
5050
* @param objectName The object name to do a search for
5151
* @param filter A filter array that contains a list of filters to be
5252
* applied.
53-
* @return Response that need to be parsed from the calling method to check
53+
* @return Response that need to be parsed from the calling method to check
5454
* if successful and then adapt the result as an array.
5555
*/
5656
public Response searchObject(String objectName, Object[] filter) {
@@ -69,7 +69,8 @@ public Response searchObject(String objectName, Object[] filter) {
6969
* @param order Field name to order on
7070
* @param count If the count should be returned, in stead of the IDs
7171
* @return If count = true, a integer is returned, otherwise a Response is
72-
* returned and could be parsed as Object[] of IDs if response is successfull
72+
* returned and could be parsed as Object[] of IDs if response is
73+
* successfull
7374
*/
7475
public Response searchObject(String objectName, Object[] filter, int offset, int limit, String order, boolean count) {
7576
Object offsetParam = offset < 0 ? false : offset;
@@ -95,8 +96,16 @@ public Response searchObject(String objectName, Object[] filter, int offset, int
9596
*/
9697
@SuppressWarnings("unchecked")
9798
public Map<String, Object> getFields(String objectName, String[] filterFields) throws XmlRpcException {
98-
return (Map<String, Object>) session.executeCommand(objectName, "fields_get",
99-
new Object[]{filterFields, session.getContext()});
99+
Map<String, Object> fieldsArray;
100+
if (this.session.getServerVersion().getMajor() >= 10 ) {
101+
fieldsArray = (Map<String, Object>) session.executeCommand(objectName, "fields_get",
102+
new Object[]{filterFields});
103+
} else {
104+
fieldsArray = (Map<String, Object>) session.executeCommand(objectName, "fields_get",
105+
new Object[]{filterFields, session.getContext()});
106+
}
107+
108+
return fieldsArray;
100109
}
101110

102111
/**
@@ -110,7 +119,14 @@ public Map<String, Object> getFields(String objectName, String[] filterFields) t
110119
* @throws XmlRpcException
111120
*/
112121
public Object[] readObject(String objectName, Object[] ids, String[] fields) throws XmlRpcException {
113-
return (Object[]) session.executeCommand(objectName, "read", new Object[]{ids, fields, session.getContext()});
122+
Object[] readResult ;
123+
if (this.session.getServerVersion().getMajor() >= 10 ) {
124+
readResult = (Object[]) session.executeCommand(objectName, "read", new Object[]{ids, fields});
125+
} else {
126+
readResult = (Object[]) session.executeCommand(objectName, "read", new Object[]{ids, fields, session.getContext()});
127+
}
128+
129+
return readResult;
114130
}
115131

116132
/**
@@ -139,6 +155,7 @@ public boolean writeObject(String objectName, int id, Map<String, Object> valueL
139155
* @throws XmlRpcException
140156
*/
141157
public Object[] importData(String objectName, String[] fieldList, Object[][] rows) throws XmlRpcException {
158+
//TODO : deal with v10 version and context
142159
return (Object[]) session.executeCommand(objectName, "import_data", new Object[]{fieldList, rows, "init", "", false, session.getContext()});
143160
}
144161

@@ -182,7 +199,16 @@ public boolean unlinkObject(String objectName, Object[] ids) throws XmlRpcExcept
182199
* @throws XmlRpcException
183200
*/
184201
public Object createObject(String objectName, Map<String, Object> values) throws XmlRpcException {
185-
return session.executeCommand(objectName, "create", new Object[]{values, session.getContext()});
202+
Object readResult ;
203+
if (this.session.getServerVersion().getMajor() >= 10 ) {
204+
readResult = (Object) session.executeCommand(objectName, "create", new Object[]{values});
205+
} else {
206+
readResult = (Object) session.executeCommand(objectName, "create", new Object[]{values, session.getContext()});
207+
}
208+
209+
return readResult;
210+
211+
186212
}
187213

188214
/**

0 commit comments

Comments
 (0)