IDEMPIERE-3146 CSV Import issues with resolveForeign when key is duplicated on foreign table / restore previous behavior to resolve foreign, first check on client then on system (not at the same time)
This commit is contained in:
parent
0d78b00ce2
commit
e6bc9b7cf2
|
@ -1464,30 +1464,33 @@ public class GridTabCSVImporter implements IGridTabImporter
|
||||||
systemAccess = true;
|
systemAccess = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int thisClientId = Env.getAD_Client_ID(Env.getCtx());
|
||||||
|
|
||||||
String trxName = (trx!=null?trx.getTrxName():null);
|
String trxName = (trx!=null?trx.getTrxName():null);
|
||||||
|
|
||||||
StringBuilder postSelect = new StringBuilder(" FROM ")
|
StringBuilder postSelect = new StringBuilder(" FROM ")
|
||||||
.append(foreignTable).append(" WHERE ")
|
.append(foreignTable).append(" WHERE ")
|
||||||
.append(foreignColumn).append("=? AND IsActive='Y' AND AD_Client_ID");
|
.append(foreignColumn).append("=? AND IsActive='Y' AND AD_Client_ID=?");
|
||||||
if (systemAccess) {
|
|
||||||
postSelect.append(" IN (0,?)");
|
|
||||||
} else {
|
|
||||||
postSelect.append("=?");
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder selectCount = new StringBuilder("SELECT COUNT(*)").append(postSelect);
|
StringBuilder selectCount = new StringBuilder("SELECT COUNT(*)").append(postSelect);
|
||||||
int count = DB.getSQLValueEx(trxName, selectCount.toString(), value, Env.getAD_Client_ID(Env.getCtx()));
|
StringBuilder selectId = new StringBuilder("SELECT ").append(foreignTable).append("_ID").append(postSelect);
|
||||||
|
int count = DB.getSQLValueEx(trxName, selectCount.toString(), value, thisClientId);
|
||||||
if (count == 1) { // single value found, OK
|
if (count == 1) { // single value found, OK
|
||||||
StringBuilder selectId = new StringBuilder("SELECT ").append(foreignTable).append("_ID").append(postSelect);
|
return DB.getSQLValueEx(trxName, selectId.toString(), value, thisClientId);
|
||||||
id = DB.getSQLValueEx(trxName, selectId.toString(), value, Env.getAD_Client_ID(Env.getCtx()));
|
|
||||||
} else if (count > 1) { // multiple values found, error ForeignMultipleResolved
|
} else if (count > 1) { // multiple values found, error ForeignMultipleResolved
|
||||||
id = -2;
|
return -2;
|
||||||
} else if (count == 0) { // no values found, error ForeignNotResolved
|
} else if (count == 0) { // no values found, error ForeignNotResolved
|
||||||
id = -3;
|
if (systemAccess && thisClientId != 0) {
|
||||||
|
// not found in client, try with System
|
||||||
|
count = DB.getSQLValueEx(trxName, selectCount.toString(), value, 0 /* System */);
|
||||||
|
if (count == 1) { // single value found, OK
|
||||||
|
return DB.getSQLValueEx(trxName, selectId.toString(), value, 0 /* System */);
|
||||||
|
} else if (count > 1) { // multiple values found, error ForeignMultipleResolved
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return -3; // no values found, error ForeignNotResolved
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copy from GridTable
|
//Copy from GridTable
|
||||||
|
|
Loading…
Reference in New Issue