IDEMPIERE-5111 Data type improvements to Print Format Item Script (#1063)

This commit is contained in:
Tony Snook 2021-12-19 17:19:30 +11:00 committed by GitHub
parent 80ec1f9419
commit 1d67dbae97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 14 deletions

View File

@ -25,6 +25,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -1043,22 +1044,26 @@ public class DataEngine
{ {
/** START DEVCOFFEE: script column **/ /** START DEVCOFFEE: script column **/
int displayType = pdc.getDisplayType(); int displayType = pdc.getDisplayType();
if (display.startsWith("@SCRIPT")) if (display.startsWith("@SCRIPT")) {
{
displayType = DisplayType.Number;
display = display.replace("@SCRIPT", ""); display = display.replace("@SCRIPT", "");
Object value = parseVariable(display, pdc, pd); Object 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());
} catch (EvalError e) }
{ catch (EvalError e) {
log.severe(e.getMessage()); 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()); 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);
pde = new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(), pp, displayType, pdc.getFormatPattern()); pde = new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(), pp, displayType, pdc.getFormatPattern());
} }
@ -1317,11 +1322,13 @@ public class DataEngine
token = inStr.substring(0, j); token = inStr.substring(0, j);
if (token.startsWith("ACCUMULATE/")) { if (token.startsWith("ACCUMULATE/"))
{
token = token.replace("ACCUMULATE/", ""); token = token.replace("ACCUMULATE/", "");
Object tokenPDE = pd.getNode(token);
BigDecimal value = (BigDecimal) ((PrintDataElement)pd.getNode(token)).getValue(); if (tokenPDE == null)
return "\"Item not found: " + token + "\"";
BigDecimal value = (BigDecimal) ((PrintDataElement)tokenPDE).getValue();
if (m_summarized.containsKey(pdc)) if (m_summarized.containsKey(pdc))
{ {
@ -1336,7 +1343,10 @@ public class DataEngine
else if (token.startsWith("COL/")) else if (token.startsWith("COL/"))
{ {
token = token.replace("COL/", ""); token = token.replace("COL/", "");
BigDecimal value = (BigDecimal) ((PrintDataElement)pd.getNode(token)).getValue(); Object tokenPDE = pd.getNode(token);
if (tokenPDE == null)
return "\"Item not found: " + token + "\"";
Object value = ((PrintDataElement)tokenPDE).getValue();
outStr.append(value); outStr.append(value);
} }