Skip to content

Commit b5d33ab

Browse files
committed
Update the write object for server version 8
1 parent 37050b3 commit b5d33ab

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

src/main/java/com/odoojava/api/ObjectAdapter.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public ObjectAdapter(Session session, String modelName) throws XmlRpcException,
9595
* synchronized to make use of a global (static) list of model names to
9696
* increase speed
9797
*
98-
* @param command Command object to use
9998
* @throws OdooApiException If the model could not be validated
10099
*/
101100
@SuppressWarnings("unchecked")
@@ -848,14 +847,14 @@ public Boolean[] writeObject(final RowCollection rows, final boolean changesOnly
848847
*
849848
* @param row Row to be committed
850849
* @param changesOnly Only changed values will be submitted to the database.
851-
* @return If the update was successful
850+
* @return true if the update was successful
852851
* @throws OdooApiException
853852
* @throws XmlRpcException
854853
*/
855854
public boolean writeObject(final Row row, boolean changesOnly) throws OdooApiException {
856855

857856
Object idObj = row.get("id");
858-
857+
boolean success = false;
859858
if (idObj == null || Integer.parseInt(idObj.toString()) <= 0) {
860859
throw new OdooApiException("Please set the id field with the database ID of the object");
861860
}
@@ -869,12 +868,33 @@ public boolean writeObject(final Row row, boolean changesOnly) throws OdooApiExc
869868
}
870869

871870
try {
871+
if (this.serverVersion.getMajor() == 8) {
872+
Object result = command.writeObject(modelName, id, valueList);
873+
Object[] resultTemp = (Object[]) result;
874+
Object[] resultTemp2 = (Object[]) resultTemp[0];
875+
876+
if (resultTemp2[0] instanceof Boolean) {
877+
success = ((Boolean) resultTemp2[0]).booleanValue();
878+
879+
if (success) {
880+
row.changesApplied();
881+
}
882+
883+
return success;
884+
} else {
885+
return false;
886+
}
887+
888+
} else {
889+
success = (Boolean) command.writeObject(modelName, id, valueList);
872890

873-
boolean success = command.writeObject(modelName, id, valueList);
874-
if (success) {
875-
row.changesApplied();
891+
if (success) {
892+
row.changesApplied();
893+
}
894+
895+
return success;
876896
}
877-
return success;
897+
878898

879899
} catch (XmlRpcException e) {
880900
throw new OdooApiException(e);

src/main/java/com/odoojava/api/OdooCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ public Object[] readObject(String objectName, Object[] ids, String[] fields) thr
144144
* @param objectName Name of the object to update
145145
* @param id Database ID number of the object to update
146146
* @param valueList Field/Value pairs to update on the object
147-
* @return True if the update was successful
147+
* @return An Object value with the result of write operation
148148
* @throws XmlRpcException
149149
*/
150-
public boolean writeObject(String objectName, int id, Map<String, Object> valueList) throws XmlRpcException {
150+
public Object writeObject(String objectName, int id, Map<String, Object> valueList) throws XmlRpcException {
151151
if (this.session.getServerVersion().getMajor() < 10) {
152152
//Prior to the v10, each version have to be adapted if needed
153153
//Some methods on certains class from v8 to v9 don't respect the syntax
154-
return (Boolean) session.executeCommand(objectName, "write", new Object[]{id, valueList});
154+
return session.executeCommand(objectName, "write", new Object[]{id, valueList});
155155
} else {
156156
//Work perfectly for the v10, please keep this check
157-
return (Boolean) session.executeCommandWithContext(objectName, "write", new Object[]{id, valueList});
157+
return session.executeCommandWithContext(objectName, "write", new Object[]{id, valueList});
158158
}
159159

160160
}

src/test/java/com/odoojava/api/OdooCommandTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public void testWriteObject() throws Exception {
136136
Map<String, Object> valueList = null;
137137
OdooCommand instance = null;
138138
boolean expResult = false;
139-
boolean result = instance.writeObject(objectName, id, valueList);
139+
boolean result = ((Boolean) ((Object[]) ((Object[])instance.writeObject(objectName, id, valueList))[0])[0]).booleanValue();
140+
140141
assertEquals(expResult, result);
141142
// TODO review the generated test code and remove the default call to fail.
142143
fail("The test case is a prototype.");

0 commit comments

Comments
 (0)