IDEMPIERE-5618 - Print Format Script Column does not show Data in correct Data Types (#1712)

* IDEMPIERE-5618 - Print Format Script Column does not show Data in correct Data Types

* IDEMPIERE-5618 - optimised and simplified the code

- get PrintFormatType from PrintDataColumn pdc
- getDisplayType(value) method to unify and simplify getting the display type
This commit is contained in:
Peter Takács 2023-03-13 14:40:09 +01:00 committed by GitHub
parent e4b7c9e17d
commit 1bc5370dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 19 deletions

View File

@ -294,7 +294,7 @@ public class DataEngine
.append("c.ColumnSQL, COALESCE(pfi.FormatPattern, c.FormatPattern) ") // 24, 25 .append("c.ColumnSQL, COALESCE(pfi.FormatPattern, c.FormatPattern) ") // 24, 25
//BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153 //BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153
/** START DEVCOFFEE: script column **/ /** START DEVCOFFEE: script column **/
.append(" , pfi.isDesc, pfi.Script, pfi.Name, pfi.AD_PrintFormatItem_ID ") // 26..29 .append(" , pfi.isDesc, pfi.Script, pfi.Name, pfi.AD_PrintFormatItem_ID, pfi.PrintFormatType ") // 26..30
//END //END
.append("FROM AD_PrintFormat pf") .append("FROM AD_PrintFormat pf")
.append(" INNER JOIN AD_PrintFormatItem pfi ON (pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID)") .append(" INNER JOIN AD_PrintFormatItem pfi ON (pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID)")
@ -394,6 +394,8 @@ public class DataEngine
String formatPattern = rs.getString(25); String formatPattern = rs.getString(25);
String printFormatType = rs.getString(30);
//BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153 //BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153
boolean isDesc = "Y".equals(rs.getString(26)); boolean isDesc = "Y".equals(rs.getString(26));
//END //END
@ -682,6 +684,7 @@ public class DataEngine
// //
pdc.setFormatPattern(formatPattern); pdc.setFormatPattern(formatPattern);
pdc.setPrintFormatType(printFormatType);
columns.add(pdc); columns.add(pdc);
} // for all Fields in Tab } // for all Fields in Tab
} }
@ -1043,8 +1046,9 @@ public class DataEngine
// Display and Value Column // Display and Value Column
if (pdc.hasAlias()) if (pdc.hasAlias())
{ {
int displayIndex = counter++;
// DisplayColumn first // DisplayColumn first
String display = rs.getString(counter++); String display = rs.getString(displayIndex);
if (pdc.getColumnName().endsWith("_ID")) if (pdc.getColumnName().endsWith("_ID"))
{ {
int id = rs.getInt(counter++); int id = rs.getInt(counter++);
@ -1061,9 +1065,13 @@ public class DataEngine
{ {
/** START DEVCOFFEE: script column **/ /** START DEVCOFFEE: script column **/
int displayType = pdc.getDisplayType(); int displayType = pdc.getDisplayType();
if(MPrintFormatItem.PRINTFORMATTYPE_Script.equalsIgnoreCase(pdc.getPrintFormatType())) { // ScriptColumn
Object value = rs.getObject(displayIndex);
displayType = getDisplayType(value);
if (display.startsWith("@SCRIPT")) { if (display.startsWith("@SCRIPT")) {
display = display.replace("@SCRIPT", ""); display = display.replace("@SCRIPT", "");
Object value = parseVariable(display, pdc, pd); value = parseVariable(display, pdc, pd);
Interpreter bsh = new Interpreter (); Interpreter bsh = new Interpreter ();
try { try {
value = bsh.eval(value.toString()); value = bsh.eval(value.toString());
@ -1071,14 +1079,8 @@ public class DataEngine
catch (EvalError e) { catch (EvalError e) {
log.severe(e.getMessage()); log.severe(e.getMessage());
} }
if (value instanceof Number) displayType = getDisplayType(value);
displayType = DisplayType.Number; }
else if (value instanceof Boolean)
displayType = DisplayType.YesNo;
else if (value instanceof Date)
displayType = DisplayType.Date;
else
displayType = DisplayType.Text;
pde = new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(), (Serializable) value, displayType, pdc.getFormatPattern()); pde = new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(), (Serializable) value, displayType, pdc.getFormatPattern());
} else { } else {
ValueNamePair pp = new ValueNamePair(id, display); ValueNamePair pp = new ValueNamePair(id, display);
@ -1310,6 +1312,22 @@ public class DataEngine
} // two lines } // two lines
} // printRunningTotal } // printRunningTotal
/**
* Get Display Type of value
* @param value
* @return int Display Type
*/
private int getDisplayType(Object value) {
if (value instanceof Number)
return DisplayType.Number;
else if (value instanceof Boolean)
return DisplayType.YesNo;
else if (value instanceof Date)
return DisplayType.Date;
else
return DisplayType.Text;
}
/** /**
* Parse expression, replaces @tag@ with pdc values and/or execute functions * Parse expression, replaces @tag@ with pdc values and/or execute functions
* @param expression * @param expression
@ -1385,6 +1403,7 @@ public class DataEngine
return outStr.toString(); return outStr.toString();
} }
/************************************************************************* /*************************************************************************
* Test * Test
* @param args args * @param args args

View File

@ -69,6 +69,7 @@ public class PrintDataColumn
private String m_alias; private String m_alias;
private boolean m_pageBreak; private boolean m_pageBreak;
private String m_FormatPattern; private String m_FormatPattern;
private String m_PrintFormatType;
/*************************************************************************/ /*************************************************************************/
@ -174,4 +175,12 @@ public class PrintDataColumn
return m_FormatPattern; return m_FormatPattern;
} }
public String getPrintFormatType() {
return m_PrintFormatType;
}
public void setPrintFormatType(String m_PrintFormatType) {
this.m_PrintFormatType = m_PrintFormatType;
}
} // PrintDataColumn } // PrintDataColumn