IDEMPIERE-908 Cannot report on window Product Costs / Team work between Richard, Juan and Carlos

This commit is contained in:
Richard Morales 2013-05-31 17:55:26 -05:00
parent a61ba2846c
commit 6d7fb18ed2
4 changed files with 69 additions and 17 deletions

View File

@ -238,7 +238,7 @@ public class AccessSqlParser
index = from.indexOf(ON); index = from.indexOf(ON);
while (index != -1) while (index != -1)
{ {
int indexClose = from.indexOf(')'); // does not catch "IN (1,2)" in ON int indexClose = getIndexClose(from); // does not catch "IN (1,2)" in ON
int indexNextOn = from.indexOf(ON, index+4); int indexNextOn = from.indexOf(ON, index+4);
if (indexNextOn != -1) if (indexNextOn != -1)
indexClose = from.lastIndexOf(')', indexNextOn); indexClose = from.lastIndexOf(')', indexNextOn);
@ -383,6 +383,33 @@ public class AccessSqlParser
} }
return ""; return "";
} // getMainSql } // getMainSql
/**
* Get index of ')'
* @return index of ')'
*/
public int getIndexClose(String from)
{
int parenthesisLevel = 0;
int indexOpen=from.indexOf('(');
int index=-1;
while(indexOpen!=-1)
{
parenthesisLevel++;
int indexNextOpen = from.indexOf('(', indexOpen+1);
int indexClose = from.indexOf(')',indexOpen+1);
if (indexNextOpen==-1 || indexClose<indexNextOpen){
break;
}
indexOpen=from.indexOf('(',indexNextOpen);
}
while(parenthesisLevel>0)
{
index = from.indexOf(')',index+1);
parenthesisLevel--;
}
return index;
}
/** /**
* Table Info VO * Table Info VO

View File

@ -111,7 +111,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
/** /**
* *
*/ */
private static final long serialVersionUID = -1638364577972806113L; private static final long serialVersionUID = -4022944302529684348L;
public static final String DEFAULT_STATUS_MESSAGE = "NavigateOrUpdate"; public static final String DEFAULT_STATUS_MESSAGE = "NavigateOrUpdate";
@ -785,20 +785,20 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
if (query.getRestrictionCount() != 1) if (query.getRestrictionCount() != 1)
{ {
if (log.isLoggable(Level.FINE)) log.fine("Ignored(More than 1 Restriction): " + query); if (log.isLoggable(Level.FINE)) log.fine("Ignored(More than 1 Restriction): " + query);
return query.getWhereClause(); return query.getWhereClause(true);
} }
String colName = query.getColumnName(0); String colName = query.getColumnName(0);
if (colName == null) if (colName == null)
{ {
if (log.isLoggable(Level.FINE)) log.fine("Ignored(No Column): " + query); if (log.isLoggable(Level.FINE)) log.fine("Ignored(No Column): " + query);
return query.getWhereClause(); return query.getWhereClause(true);
} }
// a '(' in the name = function - don't try to resolve // a '(' in the name = function - don't try to resolve
if (colName.indexOf('(') != -1) if (colName.indexOf('(') != -1)
{ {
if (log.isLoggable(Level.FINE)) log.fine("Ignored(Function): " + colName); if (log.isLoggable(Level.FINE)) log.fine("Ignored(Function): " + colName);
return query.getWhereClause(); return query.getWhereClause(true);
} }
// OK - Query is valid // OK - Query is valid
@ -806,7 +806,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
if (getField(colName) != null) if (getField(colName) != null)
{ {
if (log.isLoggable(Level.FINE)) log.fine("Field Found: " + colName); if (log.isLoggable(Level.FINE)) log.fine("Field Found: " + colName);
return query.getWhereClause(); return query.getWhereClause(true);
} }
String refColName = null; String refColName = null;
@ -845,7 +845,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
if (getField(refColName) != null) if (getField(refColName) != null)
{ {
if (log.isLoggable(Level.FINE)) log.fine("Column " + colName + " replaced with " + refColName); if (log.isLoggable(Level.FINE)) log.fine("Column " + colName + " replaced with " + refColName);
return query.getWhereClause(); return query.getWhereClause(true);
} }
colName = refColName; colName = refColName;
} }
@ -897,7 +897,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
if (log.isLoggable(Level.INFO)) log.info ("Not successfull - Column=" if (log.isLoggable(Level.INFO)) log.info ("Not successfull - Column="
+ colName + ", Key=" + tabKeyColumn + colName + ", Key=" + tabKeyColumn
+ ", Query=" + query); + ", Query=" + query);
return query.getWhereClause(); return query.getWhereClause(true);
} }
query.setTableName("xx"); query.setTableName("xx");

View File

@ -100,7 +100,7 @@ public class GridTable extends AbstractTableModel
/** /**
* *
*/ */
private static final long serialVersionUID = 5782826500266625861L; private static final long serialVersionUID = -2181155164268688340L;
public static final String DATA_REFRESH_MESSAGE = "Refreshed"; public static final String DATA_REFRESH_MESSAGE = "Refreshed";
@ -2270,6 +2270,7 @@ public class GridTable extends AbstractTableModel
int size = m_fields.size(); int size = m_fields.size();
StringBuffer singleRowWHERE = null; StringBuffer singleRowWHERE = null;
StringBuffer multiRowWHERE = null; StringBuffer multiRowWHERE = null;
String tableName = getTableName();
for (int col = 0; col < size; col++) for (int col = 0; col < size; col++)
{ {
GridField field = (GridField)m_fields.get (col); GridField field = (GridField)m_fields.get (col);
@ -2283,10 +2284,10 @@ public class GridTable extends AbstractTableModel
return null; return null;
} }
if (columnName.endsWith ("_ID")) if (columnName.endsWith ("_ID"))
singleRowWHERE = new StringBuffer(columnName) singleRowWHERE = new StringBuffer(tableName).append(".").append(columnName)
.append ("=").append (value); .append ("=").append (value);
else else
singleRowWHERE = new StringBuffer(columnName) singleRowWHERE = new StringBuffer(tableName).append(".").append(columnName)
.append ("=").append (DB.TO_STRING(value.toString())); .append ("=").append (DB.TO_STRING(value.toString()));
} }
else if (field.isParentColumn()) else if (field.isParentColumn())
@ -2303,10 +2304,10 @@ public class GridTable extends AbstractTableModel
else else
multiRowWHERE.append(" AND "); multiRowWHERE.append(" AND ");
if (columnName.endsWith ("_ID")) if (columnName.endsWith ("_ID"))
multiRowWHERE.append (columnName) multiRowWHERE.append (tableName).append(".").append(columnName)
.append ("=").append (value); .append ("=").append (value);
else else
multiRowWHERE.append (columnName) multiRowWHERE.append (tableName).append(".").append(columnName)
.append ("=").append (DB.TO_STRING(value.toString())); .append ("=").append (DB.TO_STRING(value.toString()));
} }
} // for all columns } // for all columns
@ -2889,13 +2890,13 @@ public class GridTable extends AbstractTableModel
close(false); close(false);
if (retainedWhere != null) if (retainedWhere != null)
{ {
String whereClause = m_whereClause; // String whereClause = m_whereClause;
if (m_whereClause != null && m_whereClause.trim().length() > 0) if (m_whereClause != null && m_whereClause.trim().length() > 0)
{ {
m_whereClause = "((" + m_whereClause + ") OR (" + retainedWhere + ")) "; m_whereClause = "((" + m_whereClause + ") OR (" + retainedWhere + ")) ";
} }
open(m_maxRows); open(m_maxRows);
m_whereClause = whereClause; // m_whereClause = whereClause;
} }
else else
{ {

View File

@ -247,21 +247,45 @@ public class ReportAction implements EventListener<Event>
int Record_ID = 0; int Record_ID = 0;
int[] RecordIDs = null; int[] RecordIDs = null;
MQuery query = new MQuery(gridTab.getTableName()); MQuery query = new MQuery(gridTab.getTableName());
String whereClause;
if (currentRowOnly) if (currentRowOnly)
{ {
Record_ID = gridTab.getRecord_ID(); Record_ID = gridTab.getRecord_ID();
query.addRestriction(query.getTableName() + "_ID", MQuery.EQUAL, Record_ID); whereClause = gridTab.getTableModel().getWhereClause(gridTab.getCurrentRow());
if (whereClause==null)
whereClause = gridTab.getTableModel().getSelectWhereClause();
} }
else else
{ {
whereClause = gridTab.getTableModel().getSelectWhereClause();
RecordIDs = new int[gridTab.getRowCount()]; RecordIDs = new int[gridTab.getRowCount()];
for(int i = 0; i < gridTab.getRowCount(); i++) for(int i = 0; i < gridTab.getRowCount(); i++)
{ {
RecordIDs[i] = gridTab.getKeyID(i); RecordIDs[i] = gridTab.getKeyID(i);
query.addRestriction(query.getTableName() + "." + query.getTableName() + "_ID" + MQuery.EQUAL + RecordIDs[i], false, 0); }
}
if (whereClause!=null && whereClause.length() > 0)
{
if (whereClause.indexOf('@') != -1) //replace variables in context
{
String context = Env.parseContext(Env.getCtx(), panel.getWindowNo(), whereClause, false);
if(context != null && context.trim().length() > 0)
{
whereClause = context;
}
else
{
log.log(Level.WARNING, "Failed to parse where clause. whereClause= "+whereClause);
whereClause = ("1 = 2");
}
} }
} }
query.addRestriction(whereClause);
PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID); PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
info.setDescription(query.getInfo()); info.setDescription(query.getInfo());