From feebea8691e053d05f88d17ff903d3019fb0dc6e Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 1 Dec 2021 02:46:53 +0100 Subject: [PATCH] IDEMPIERE-5052 Date Min/Max Validation wrong with 5 digit years (#1016) * IDEMPIERE-5052 Date Min/Max Validation wrong with 5 digit years * IDEMPIERE-5052 Date Min/Max Validation wrong with 5 digit years / enable for Cost+Price and String --- .../oracle/202111301716_IDEMPIERE-5052.sql | 15 +++++ .../202111301716_IDEMPIERE-5052.sql | 12 ++++ .../src/org/compiere/model/POInfo.java | 15 +++++ .../src/org/compiere/model/POInfoColumn.java | 55 +++++++++++++------ 4 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 migration/i8.2z/oracle/202111301716_IDEMPIERE-5052.sql create mode 100644 migration/i8.2z/postgresql/202111301716_IDEMPIERE-5052.sql diff --git a/migration/i8.2z/oracle/202111301716_IDEMPIERE-5052.sql b/migration/i8.2z/oracle/202111301716_IDEMPIERE-5052.sql new file mode 100644 index 0000000000..5be550df0a --- /dev/null +++ b/migration/i8.2z/oracle/202111301716_IDEMPIERE-5052.sql @@ -0,0 +1,15 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-5052 Date Min/Max Validation wrong with 5 digit years +-- Nov 30, 2021, 5:14:36 PM CET +UPDATE AD_Field SET DisplayLogic='@AD_Reference_ID@=11 | @AD_Reference_ID@=12 | @AD_Reference_ID@=15 | @AD_Reference_ID@=22 | @AD_Reference_ID@=29 | @AD_Reference_ID@=37 | @AD_Reference_ID@=10', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-11-30 17:14:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=2574 +; + +-- Nov 30, 2021, 5:14:41 PM CET +UPDATE AD_Field SET DisplayLogic='@AD_Reference_ID@=11 | @AD_Reference_ID@=12 | @AD_Reference_ID@=15 | @AD_Reference_ID@=22 | @AD_Reference_ID@=29 | @AD_Reference_ID@=37 | @AD_Reference_ID@=10', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-11-30 17:14:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=2573 +; + +SELECT register_migration_script('202111301716_IDEMPIERE-5052.sql') FROM dual +; + diff --git a/migration/i8.2z/postgresql/202111301716_IDEMPIERE-5052.sql b/migration/i8.2z/postgresql/202111301716_IDEMPIERE-5052.sql new file mode 100644 index 0000000000..295fac4d03 --- /dev/null +++ b/migration/i8.2z/postgresql/202111301716_IDEMPIERE-5052.sql @@ -0,0 +1,12 @@ +-- IDEMPIERE-5052 Date Min/Max Validation wrong with 5 digit years +-- Nov 30, 2021, 5:14:36 PM CET +UPDATE AD_Field SET DisplayLogic='@AD_Reference_ID@=11 | @AD_Reference_ID@=12 | @AD_Reference_ID@=15 | @AD_Reference_ID@=22 | @AD_Reference_ID@=29 | @AD_Reference_ID@=37 | @AD_Reference_ID@=10', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-11-30 17:14:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=2574 +; + +-- Nov 30, 2021, 5:14:41 PM CET +UPDATE AD_Field SET DisplayLogic='@AD_Reference_ID@=11 | @AD_Reference_ID@=12 | @AD_Reference_ID@=15 | @AD_Reference_ID@=22 | @AD_Reference_ID@=29 | @AD_Reference_ID@=37 | @AD_Reference_ID@=10', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-11-30 17:14:41','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=2573 +; + +SELECT register_migration_script('202111301716_IDEMPIERE-5052.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/POInfo.java b/org.adempiere.base/src/org/compiere/model/POInfo.java index 5c49eb1f9d..6c2ba3bfed 100644 --- a/org.adempiere.base/src/org/compiere/model/POInfo.java +++ b/org.adempiere.base/src/org/compiere/model/POInfo.java @@ -23,6 +23,7 @@ import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -747,6 +748,13 @@ public class POInfo implements Serializable return "LessThanMinValue"+";"+m_columns[index].ValueMin_BD.toPlainString(); } } + else if (value instanceof Timestamp && m_columns[index].ValueMin_TS != null) // Date + { + if (((Timestamp) value).before(m_columns[index].ValueMin_TS)) + { + return "LessThanMinValue"+";"+m_columns[index].ValueMin; + } + } else // String { int comp = m_columns[index].ValueMin.compareTo(value.toString()); @@ -774,6 +782,13 @@ public class POInfo implements Serializable return "MoreThanMaxValue"+";"+m_columns[index].ValueMax_BD.toPlainString(); } } + else if (value instanceof Timestamp && m_columns[index].ValueMax_TS != null) // Date + { + if (((Timestamp) value).after(m_columns[index].ValueMax_TS)) + { + return "MoreThanMaxValue"+";"+m_columns[index].ValueMax; + } + } else // String { int comp = m_columns[index].ValueMax.compareTo(value.toString()); diff --git a/org.adempiere.base/src/org/compiere/model/POInfoColumn.java b/org.adempiere.base/src/org/compiere/model/POInfoColumn.java index 7123c132a5..b50707cd72 100644 --- a/org.adempiere.base/src/org/compiere/model/POInfoColumn.java +++ b/org.adempiere.base/src/org/compiere/model/POInfoColumn.java @@ -18,9 +18,12 @@ package org.compiere.model; import java.io.Serializable; import java.math.BigDecimal; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.logging.Level; import org.compiere.util.CLogger; +import org.compiere.util.Util; /** * PO Info Column Info Value Object @@ -33,7 +36,7 @@ public class POInfoColumn implements Serializable /** * */ - private static final long serialVersionUID = 3882249785085847367L; + private static final long serialVersionUID = -6550300505836470875L; /** Used by Remote FinReport */ /** @@ -106,24 +109,38 @@ public class POInfoColumn implements Serializable // FieldLength = fieldLength; ValueMin = valueMin; - try - { - if (valueMin != null && valueMin.length() > 0) - ValueMin_BD = new BigDecimal(valueMin); - } - catch (Exception ex) - { - CLogger.get().log(Level.SEVERE, "ValueMin=" + valueMin, ex); + if (!Util.isEmpty(ValueMin)) { + try { + ValueMin_BD = new BigDecimal(ValueMin); + } catch (Exception ex) { + ValueMin_BD = null; + } + try { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + ValueMin_TS = new java.sql.Timestamp(dateFormat.parse(ValueMin).getTime()); + } catch (Exception ex) { + ValueMin_TS = null; + } + if (ValueMin_BD == null && ValueMin_TS == null) { + CLogger.get().log(Level.SEVERE, "ValueMin cannot be parsed to a number or date = " + ValueMin); + } } ValueMax = valueMax; - try - { - if (valueMax != null && valueMax.length() > 0) - ValueMax_BD = new BigDecimal(valueMax); - } - catch (Exception ex) - { - CLogger.get().log(Level.SEVERE, "ValueMax=" + valueMax, ex); + if (!Util.isEmpty(ValueMax)) { + try { + ValueMax_BD = new BigDecimal(ValueMax); + } catch (Exception ex) { + ValueMax_BD = null; + } + try { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + ValueMax_TS = new java.sql.Timestamp(dateFormat.parse(ValueMax).getTime()); + } catch (Exception ex) { + ValueMax_TS = null; + } + if (ValueMax_BD == null && ValueMax_TS == null) { + CLogger.get().log(Level.SEVERE, "ValueMax cannot be parsed to a number or date = " + ValueMax); + } } IsTranslated = isTranslated; IsEncrypted = isEncrypted; @@ -179,6 +196,10 @@ public class POInfoColumn implements Serializable public BigDecimal ValueMin_BD = null; /** Max Value */ public BigDecimal ValueMax_BD = null; + /** Min Value */ + public Timestamp ValueMin_TS = null; + /** Max Value */ + public Timestamp ValueMax_TS = null; /** * String representation