From 1bc5370dbb4e611df5d0d3c1aa8d60aeb3f8b61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:40:09 +0100 Subject: [PATCH] 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 --- .../src/org/compiere/print/DataEngine.java | 57 ++++++++++++------- .../org/compiere/print/PrintDataColumn.java | 9 +++ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/DataEngine.java b/org.adempiere.base/src/org/compiere/print/DataEngine.java index e69ade27ba..ebdcb509ca 100644 --- a/org.adempiere.base/src/org/compiere/print/DataEngine.java +++ b/org.adempiere.base/src/org/compiere/print/DataEngine.java @@ -294,7 +294,7 @@ public class DataEngine .append("c.ColumnSQL, COALESCE(pfi.FormatPattern, c.FormatPattern) ") // 24, 25 //BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153 /** 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 .append("FROM AD_PrintFormat pf") .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 printFormatType = rs.getString(30); + //BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153 boolean isDesc = "Y".equals(rs.getString(26)); //END @@ -682,6 +684,7 @@ public class DataEngine // pdc.setFormatPattern(formatPattern); + pdc.setPrintFormatType(printFormatType); columns.add(pdc); } // for all Fields in Tab } @@ -1043,8 +1046,9 @@ public class DataEngine // Display and Value Column if (pdc.hasAlias()) { + int displayIndex = counter++; // DisplayColumn first - String display = rs.getString(counter++); + String display = rs.getString(displayIndex); if (pdc.getColumnName().endsWith("_ID")) { int id = rs.getInt(counter++); @@ -1061,24 +1065,22 @@ public class DataEngine { /** START DEVCOFFEE: script column **/ int displayType = pdc.getDisplayType(); - if (display.startsWith("@SCRIPT")) { - display = display.replace("@SCRIPT", ""); - Object value = parseVariable(display, pdc, pd); - Interpreter bsh = new Interpreter (); - try { - value = bsh.eval(value.toString()); + if(MPrintFormatItem.PRINTFORMATTYPE_Script.equalsIgnoreCase(pdc.getPrintFormatType())) { // ScriptColumn + Object value = rs.getObject(displayIndex); + displayType = getDisplayType(value); + + if (display.startsWith("@SCRIPT")) { + display = display.replace("@SCRIPT", ""); + value = parseVariable(display, pdc, pd); + Interpreter bsh = new Interpreter (); + try { + value = bsh.eval(value.toString()); + } + catch (EvalError e) { + log.severe(e.getMessage()); + } + displayType = getDisplayType(value); } - catch (EvalError e) { - log.severe(e.getMessage()); - } - if (value instanceof Number) - 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()); } else { ValueNamePair pp = new ValueNamePair(id, display); @@ -1310,6 +1312,22 @@ public class DataEngine } // two lines } // 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 * @param expression @@ -1385,6 +1403,7 @@ public class DataEngine return outStr.toString(); } + /************************************************************************* * Test * @param args args diff --git a/org.adempiere.base/src/org/compiere/print/PrintDataColumn.java b/org.adempiere.base/src/org/compiere/print/PrintDataColumn.java index ef75c54898..822bc26448 100644 --- a/org.adempiere.base/src/org/compiere/print/PrintDataColumn.java +++ b/org.adempiere.base/src/org/compiere/print/PrintDataColumn.java @@ -69,6 +69,7 @@ public class PrintDataColumn private String m_alias; private boolean m_pageBreak; private String m_FormatPattern; + private String m_PrintFormatType; /*************************************************************************/ @@ -174,4 +175,12 @@ public class PrintDataColumn return m_FormatPattern; } + public String getPrintFormatType() { + return m_PrintFormatType; + } + + public void setPrintFormatType(String m_PrintFormatType) { + this.m_PrintFormatType = m_PrintFormatType; + } + } // PrintDataColumn