IDEMPIERE-5565 Cannot create report with virtual column where reference is table with display column = ID (#1735)
* IDEMPIERE-5565 Cannot create report with virtual column where reference is table with display column = ID * - make it consistent with the actual approach
This commit is contained in:
parent
47987c0314
commit
eab0574dae
|
@ -29,13 +29,11 @@ import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.adempiere.exceptions.AdempiereException;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.adempiere.exceptions.DBException;
|
import org.adempiere.exceptions.DBException;
|
||||||
import org.compiere.db.AdempiereDatabase;
|
import org.compiere.db.AdempiereDatabase;
|
||||||
import org.compiere.db.Database;
|
import org.compiere.db.Database;
|
||||||
import org.compiere.util.CLogger;
|
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
@ -167,9 +165,6 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
|
||||||
/** Cache */
|
/** Cache */
|
||||||
private static ImmutableIntPOCache<Integer,MColumn> s_cache = new ImmutableIntPOCache<Integer,MColumn>(Table_Name, 20);
|
private static ImmutableIntPOCache<Integer,MColumn> s_cache = new ImmutableIntPOCache<Integer,MColumn>(Table_Name, 20);
|
||||||
|
|
||||||
/** Static Logger */
|
|
||||||
private static CLogger s_log = CLogger.getCLogger (MColumn.class);
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Standard Constructor
|
* Standard Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -689,7 +684,6 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
|
||||||
return sb.toString ();
|
return sb.toString ();
|
||||||
} // toString
|
} // toString
|
||||||
|
|
||||||
//begin vpj-cd e-evolution
|
|
||||||
/**
|
/**
|
||||||
* get Column ID
|
* get Column ID
|
||||||
* @param TableName
|
* @param TableName
|
||||||
|
@ -697,37 +691,14 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
|
||||||
* @return int retValue
|
* @return int retValue
|
||||||
*/
|
*/
|
||||||
public static int getColumn_ID(String TableName,String columnName) {
|
public static int getColumn_ID(String TableName,String columnName) {
|
||||||
int m_table_id = MTable.getTable_ID(TableName);
|
MTable table = MTable.get(Env.getCtx(), TableName);
|
||||||
if (m_table_id == 0)
|
if (table == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
MColumn column = table.getColumn(columnName);
|
||||||
int retValue = 0;
|
if (column == null)
|
||||||
String SQL = "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID = ? AND columnname = ?";
|
return 0;
|
||||||
PreparedStatement pstmt = null;
|
return column.getAD_Column_ID();
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(SQL, null);
|
|
||||||
pstmt.setInt(1, m_table_id);
|
|
||||||
pstmt.setString(2, columnName);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
retValue = rs.getInt(1);
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, SQL, e);
|
|
||||||
retValue = -1;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
return retValue;
|
|
||||||
}
|
|
||||||
//end vpj-cd e-evolution
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Table Id for a column
|
* Get Table Id for a column
|
||||||
|
|
|
@ -614,7 +614,7 @@ public class MLookupFactory
|
||||||
* @param AD_Reference_Value_ID reference value
|
* @param AD_Reference_Value_ID reference value
|
||||||
* @return SELECT Name FROM Table
|
* @return SELECT Name FROM Table
|
||||||
*/
|
*/
|
||||||
static public String getLookup_TableEmbed (Language language,
|
public static String getLookup_TableEmbed (Language language,
|
||||||
String BaseColumn, String BaseTable, int AD_Reference_Value_ID)
|
String BaseColumn, String BaseTable, int AD_Reference_Value_ID)
|
||||||
{
|
{
|
||||||
String sql = "SELECT t.TableName,ck.ColumnName AS KeyColumn,"
|
String sql = "SELECT t.TableName,ck.ColumnName AS KeyColumn,"
|
||||||
|
@ -664,8 +664,13 @@ public class MLookupFactory
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Column_ID = MColumn.getColumn_ID(BaseTable, BaseColumn);
|
||||||
|
MColumn column = MColumn.get(Env.getCtx(), Column_ID);
|
||||||
boolean showID = DisplayColumn.equals(TableName+"_ID");
|
boolean showID = DisplayColumn.equals(TableName+"_ID");
|
||||||
if (showID) {
|
if (showID) {
|
||||||
|
if (column.isVirtualColumn())
|
||||||
|
return getLookup_TableDirEmbed(language, DisplayColumn, BaseTable, column.getColumnSQL());
|
||||||
|
else
|
||||||
return getLookup_TableDirEmbed(language, DisplayColumn, BaseTable, BaseColumn);
|
return getLookup_TableDirEmbed(language, DisplayColumn, BaseTable, BaseColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,8 +730,6 @@ public class MLookupFactory
|
||||||
|
|
||||||
embedSQL.append(" WHERE ");
|
embedSQL.append(" WHERE ");
|
||||||
|
|
||||||
int Column_ID = MColumn.getColumn_ID(BaseTable, BaseColumn);
|
|
||||||
MColumn column = MColumn.get(Env.getCtx(), Column_ID);
|
|
||||||
// If is not virtual column - teo_sarca [ 1739530 ]
|
// If is not virtual column - teo_sarca [ 1739530 ]
|
||||||
if (!column.isVirtualColumn())
|
if (!column.isVirtualColumn())
|
||||||
{
|
{
|
||||||
|
@ -735,7 +738,7 @@ public class MLookupFactory
|
||||||
} else if (translated) {
|
} else if (translated) {
|
||||||
embedSQL.append(TableNameAlias).append(".").append(KeyColumn).append("=").append(column.getColumnSQL(true));
|
embedSQL.append(TableNameAlias).append(".").append(KeyColumn).append("=").append(column.getColumnSQL(true));
|
||||||
} else {
|
} else {
|
||||||
embedSQL.append(KeyColumn).append("=").append(column.getColumnSQL(true));
|
embedSQL.append(TableNameAlias).append(".").append(KeyColumn).append("=").append(column.getColumnSQL(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return embedSQL.toString();
|
return embedSQL.toString();
|
||||||
|
@ -1007,8 +1010,7 @@ public class MLookupFactory
|
||||||
// If is not virtual column - teo_sarca [ 1739530 ]
|
// If is not virtual column - teo_sarca [ 1739530 ]
|
||||||
if (! BaseColumn.trim().startsWith("(")) {
|
if (! BaseColumn.trim().startsWith("(")) {
|
||||||
embedSQL.append(BaseTable).append(".").append(BaseColumn);
|
embedSQL.append(BaseTable).append(".").append(BaseColumn);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
embedSQL.append(BaseColumn);
|
embedSQL.append(BaseColumn);
|
||||||
}
|
}
|
||||||
embedSQL.append("=").append(TableName).append(".").append(ColumnName);
|
embedSQL.append("=").append(TableName).append(".").append(ColumnName);
|
||||||
|
|
|
@ -484,16 +484,10 @@ public class DataEngine
|
||||||
|| (AD_Reference_ID == DisplayType.Search && AD_Reference_Value_ID != 0)
|
|| (AD_Reference_ID == DisplayType.Search && AD_Reference_Value_ID != 0)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
String eSql;
|
String eSql = MLookupFactory.getLookup_TableEmbed(m_language, ColumnName, tableName, AD_Reference_Value_ID);
|
||||||
|
|
||||||
if (ColumnSQL.length() > 0)
|
if (ColumnSQL.length() > 0)
|
||||||
{
|
|
||||||
lookupSQL = ColumnSQL;
|
lookupSQL = ColumnSQL;
|
||||||
eSql = MLookupFactory.getLookup_TableEmbed(m_language, ColumnSQL, tableName, AD_Reference_Value_ID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eSql = MLookupFactory.getLookup_TableEmbed(m_language, ColumnName, tableName, AD_Reference_Value_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DisplayColumn
|
// DisplayColumn
|
||||||
String display = ColumnName;
|
String display = ColumnName;
|
||||||
|
|
|
@ -1020,7 +1020,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
|
||||||
boolean haveNotProcess = !haveProcess; // A field is editabile only if is not readonly and theres a process;
|
boolean haveNotProcess = !haveProcess; // A field is editabile only if is not readonly and theres a process;
|
||||||
|
|
||||||
int index = infoColumn.getSelectClause().indexOf(".");
|
int index = infoColumn.getSelectClause().indexOf(".");
|
||||||
if (index == infoColumn.getSelectClause().lastIndexOf("."))
|
if (index >= 0 && index == infoColumn.getSelectClause().lastIndexOf("."))
|
||||||
{
|
{
|
||||||
String synonym = infoColumn.getSelectClause().substring(0, index);
|
String synonym = infoColumn.getSelectClause().substring(0, index);
|
||||||
for(TableInfo tableInfo : tableInfos)
|
for(TableInfo tableInfo : tableInfos)
|
||||||
|
|
|
@ -690,10 +690,15 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
|
||||||
|
|
||||||
MTable table = MTable.get(Env.getCtx(), p_tableName);
|
MTable table = MTable.get(Env.getCtx(), p_tableName);
|
||||||
MColumn column = table.getColumn(columnName);
|
MColumn column = table.getColumn(columnName);
|
||||||
String baseColumn = column.isVirtualColumn() ? columnSql : columnName;
|
String embedded;
|
||||||
|
if (AD_Reference_Value_ID > 0) {
|
||||||
String embedded = AD_Reference_Value_ID > 0 ? MLookupFactory.getLookup_TableEmbed(Env.getLanguage(Env.getCtx()), baseColumn, p_tableName, AD_Reference_Value_ID)
|
embedded = MLookupFactory.getLookup_TableEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, AD_Reference_Value_ID);
|
||||||
: MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, baseColumn);
|
} else {
|
||||||
|
if (column.isVirtualColumn())
|
||||||
|
embedded = MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, column.getColumnSQL());
|
||||||
|
else
|
||||||
|
embedded = MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, columnName);
|
||||||
|
}
|
||||||
embedded = "(" + embedded + ")";
|
embedded = "(" + embedded + ")";
|
||||||
|
|
||||||
if (embedded.contains("@"))
|
if (embedded.contains("@"))
|
||||||
|
|
Loading…
Reference in New Issue