IDEMPIERE-3975: Virtual column can't be used for search, empty result returned

This commit is contained in:
Deepak Pansheriya 2019-05-17 19:18:40 +05:30
parent cf0d10a3e6
commit a9fbf53acf
2 changed files with 6 additions and 5 deletions

View File

@ -1126,7 +1126,7 @@ class Restriction implements Serializable
String colSQL = col.getColumnSQL(true); String colSQL = col.getColumnSQL(true);
if (colSQL != null && colSQL.contains("@")) if (colSQL != null && colSQL.contains("@"))
colSQL = Env.parseContext(Env.getCtx(), -1, colSQL, false, true); colSQL = Env.parseContext(Env.getCtx(), -1, colSQL, false, true);
if (ColumnName.equals(colSQL)) { if (colSQL != null && ColumnName.equals(colSQL.trim())) {
virtualColumn = true; virtualColumn = true;
break; break;
} }

View File

@ -1699,7 +1699,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (!(parsedValue instanceof Integer)) { if (!(parsedValue instanceof Integer)) {
continue; continue;
} }
m_query.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets); m_query.addRestriction(getSubCategoryWhereClause(field, ((Integer) parsedValue).intValue()), and, openBrackets);
} }
else else
m_query.addRestriction(ColumnSQL, Operator, parsedValue, m_query.addRestriction(ColumnSQL, Operator, parsedValue,
@ -1865,7 +1865,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
m_query.addRestriction(ColumnSQL.toString(), MQuery.LIKE, value, ColumnName, wed.getDisplay()); m_query.addRestriction(ColumnSQL.toString(), MQuery.LIKE, value, ColumnName, wed.getDisplay());
appendCode(code, ColumnName, MQuery.LIKE, value.toString(), "", "AND", "", ""); appendCode(code, ColumnName, MQuery.LIKE, value.toString(), "", "AND", "", "");
} else if (isProductCategoryField && value instanceof Integer) { } else if (isProductCategoryField && value instanceof Integer) {
m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue())); m_query.addRestriction(getSubCategoryWhereClause(field, ((Integer) value).intValue()));
appendCode(code, ColumnName, MQuery.EQUAL, value.toString(), "", "AND", "", ""); appendCode(code, ColumnName, MQuery.EQUAL, value.toString(), "", "AND", "", "");
} else { } else {
String oper = MQuery.EQUAL; String oper = MQuery.EQUAL;
@ -2319,13 +2319,14 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
/** /**
* Returns a sql where string with the given category id and all of its subcategory ids. * Returns a sql where string with the given category id and all of its subcategory ids.
* It is used as restriction in MQuery. * It is used as restriction in MQuery.
* @param field
* @param productCategoryId * @param productCategoryId
* @return * @return
**/ **/
private String getSubCategoryWhereClause(int productCategoryId) { private String getSubCategoryWhereClause(GridField field, int productCategoryId) {
//if a node with this id is found later in the search we have a loop in the tree //if a node with this id is found later in the search we have a loop in the tree
int subTreeRootParentId = 0; int subTreeRootParentId = 0;
StringBuilder retString = new StringBuilder(" M_Product_Category_ID IN ("); StringBuilder retString = new StringBuilder(field.getColumnSQL(false)).append(" IN (");
String sql = "SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category WHERE AD_Client_ID=? AND IsActive='Y'"; String sql = "SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category WHERE AD_Client_ID=? AND IsActive='Y'";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100); final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;