IDEMPIERE-4881 CSS style anomaly - display logic (#782)
Fix equal evaluation for numeric expression
This commit is contained in:
parent
c72d4609b1
commit
6169d09924
|
@ -134,32 +134,20 @@ public class EvaluationVisitor extends SimpleBooleanBaseVisitor<Object> {
|
|||
return Pattern.matches(right, left);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private Boolean isEqual(SimpleBooleanParser.ComparatorExpressionContext ctx) {
|
||||
Object left = this.visit(ctx.left);
|
||||
Object right = this.visit(ctx.right);
|
||||
Comparable left = asComparable(ctx.left);
|
||||
Comparable right = asComparable(ctx.right);
|
||||
if (left == null || right == null)
|
||||
return Boolean.FALSE;
|
||||
if (left instanceof String && right instanceof String && !(ctx.right.getText().startsWith("'") && !(ctx.right.getText().startsWith("\"")))) {
|
||||
String rightText = (String) right;
|
||||
if (rightText.indexOf(",") > 0) {
|
||||
return isIn((String)left, rightText);
|
||||
}
|
||||
}
|
||||
if (left instanceof BigDecimal && right instanceof BigDecimal) {
|
||||
return ((BigDecimal)left).compareTo((BigDecimal) right) == 0;
|
||||
} else {
|
||||
String leftStr = left.toString();
|
||||
if (left instanceof BigDecimal) {
|
||||
if (((BigDecimal)left).stripTrailingZeros().scale() <= 0) {
|
||||
leftStr = Integer.toString(((BigDecimal)left).intValue());
|
||||
}
|
||||
}
|
||||
String rightStr = right.toString();
|
||||
if (right instanceof BigDecimal) {
|
||||
if (((BigDecimal)right).stripTrailingZeros().scale() <= 0) {
|
||||
rightStr = Integer.toString(((BigDecimal)right).intValue());
|
||||
}
|
||||
}
|
||||
return leftStr.equals(rightStr);
|
||||
}
|
||||
|
||||
return left.compareTo(right) == 0;
|
||||
}
|
||||
|
||||
private Boolean isIn(String left, String rightText) {
|
||||
|
|
|
@ -520,6 +520,29 @@ public class LogicExpressionTest extends AbstractTestCase {
|
|||
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumericExpression() {
|
||||
String expr = "@QtyReserved@=0";
|
||||
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", (String)null);
|
||||
assertFalse(LegacyLogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", 1);
|
||||
assertFalse(LegacyLogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", 0);
|
||||
assertTrue(LegacyLogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", "0.00");
|
||||
assertTrue(LegacyLogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", (String)null);
|
||||
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", 1);
|
||||
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", 0);
|
||||
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
Env.setContext(Env.getCtx(), "QtyReserved", "0.00");
|
||||
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
|
||||
}
|
||||
|
||||
private static class ContextEvaluatee implements Evaluatee {
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue