Skip to content

Commit

Permalink
[IMP] onetomany record create and update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dharmang Soni committed Jun 16, 2014
1 parent dc47aad commit 29a108f
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/com/odoo/orm/OEDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ public int update(OEValues values, String where, String[] whereArgs) {
}
}
}
if (res.containsKey("o2mObjects")) {
@SuppressWarnings("unchecked")
List<HashMap<String, Object>> objectList = (List<HashMap<String, Object>>) res
.get("o2mObjects");
for (HashMap<String, Object> obj : objectList) {
OEDatabase o2mDb = (OEDatabase) obj.get("o2mObject");
OEColumn o2mCol = (OEColumn) obj.get("o2mCol");
OEO2MIds ids = (OEO2MIds) obj.get("o2mRecordsObj");
OEOneToMany o2m = (OEOneToMany) o2mCol.getType();
OEValues vals = new OEValues();
vals.put(o2m.getColumnName(), values.get("id"));
for (int id : ids.getIds()) {
o2mDb.update(vals, id);
}
}
}
return count;

}
Expand Down Expand Up @@ -207,6 +223,22 @@ public long create(OEValues values) {
obj.get("m2mRecordsObj"));
}
}
if (res.containsKey("o2mObjects")) {
@SuppressWarnings("unchecked")
List<HashMap<String, Object>> objectList = (List<HashMap<String, Object>>) res
.get("o2mObjects");
for (HashMap<String, Object> obj : objectList) {
OEDatabase o2mDb = (OEDatabase) obj.get("o2mObject");
OEColumn o2mCol = (OEColumn) obj.get("o2mCol");
OEO2MIds ids = (OEO2MIds) obj.get("o2mRecordsObj");
OEOneToMany o2m = (OEOneToMany) o2mCol.getType();
OEValues vals = new OEValues();
vals.put(o2m.getColumnName(), newId);
for (int id : ids.getIds()) {
o2mDb.update(vals, id);
}
}
}
return newId;
}

Expand All @@ -229,15 +261,19 @@ private HashMap<String, Object> getContentValues(OEValues values) {
m2mObjectList.add(m2mObjects);
continue;
}
// FIXME
if (values.get(key) instanceof OEO2MIds) {
HashMap<String, Object> o2mObjects = new HashMap<String, Object>();
OEDBHelper o2mDb = findFieldModel(key);
o2mObjects.put("o2mObject", o2mDb);
o2mObjects.put("o2mCol", col);
o2mObjects.put("o2mRecordsObj", values.get(key));
o2mObjectList.add(o2mObjects);
continue;
}
if (col.getType() instanceof OEOneToMany) {
continue;
}

cValues.put(key, values.get(key).toString());
}
/**
Expand Down Expand Up @@ -505,8 +541,13 @@ private Object createRowData(OEColumn col, Cursor cr) {
String value = cr.getString(cr.getColumnIndex(col.getName()));
if (col.getType() instanceof OETimestamp
|| col.getType() instanceof OEDateTime) {
String date_format = OEDate.DEFAULT_FORMAT;
if (col.getType() instanceof OEDateTime) {
OEDateTime dttime = (OEDateTime) col.getType();
date_format = dttime.getPattern();
}
value = OEDate.getDate(mContext, value, TimeZone.getDefault()
.getID(), OEDate.DEFAULT_FORMAT);
.getID(), date_format);
}
return value;
}
Expand Down

0 comments on commit 29a108f

Please sign in to comment.