From 20e49ecefc7a1553e9b448db4f5e984620982749 Mon Sep 17 00:00:00 2001 From: kthiemann Date: Mon, 4 Jun 2007 11:04:10 +0000 Subject: [PATCH] Feature Request [ 1730595 ] Dependant Mandatory Field --- base/src/org/compiere/model/GridField.java | 13 +- base/src/org/compiere/model/GridFieldVO.java | 7 + base/src/org/compiere/model/X_AD_Column.java | 27 ++- .../320-trunk/009_add_MandatoryLogic.sql | 163 ++++++++++++++++++ 4 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 migration/320-trunk/009_add_MandatoryLogic.sql diff --git a/base/src/org/compiere/model/GridField.java b/base/src/org/compiere/model/GridField.java index def80bb471..aecbc50ab5 100644 --- a/base/src/org/compiere/model/GridField.java +++ b/base/src/org/compiere/model/GridField.java @@ -231,6 +231,7 @@ public class GridField // Display Evaluator.parseDepends(list, m_vo.DisplayLogic); Evaluator.parseDepends(list, m_vo.ReadOnlyLogic); + Evaluator.parseDepends(list, m_vo.MandatoryLogic); // Lookup if (m_lookup != null) Evaluator.parseDepends(list, m_lookup.getValidation()); @@ -274,6 +275,15 @@ public class GridField */ public boolean isMandatory (boolean checkContext) { +// Do we have a mandatory rule + if (checkContext && m_vo.MandatoryLogic.length() > 0) + { + boolean retValue = Evaluator.evaluateLogic(this, m_vo.MandatoryLogic); + log.finest(m_vo.ColumnName + " Mandatory(" + m_vo.MandatoryLogic + ") => Mandatory-" + retValue); + if (retValue) + return true; + } + // Not mandatory if (!m_vo.IsMandatory || isVirtualColumn()) return false; @@ -357,6 +367,7 @@ public class GridField if (!retValue) return false; } + // Always editable if Active if (m_vo.ColumnName.equals("Processing") @@ -1556,5 +1567,5 @@ public class GridField public void setVFormat(String strNewFormat){ m_vo.VFormat = strNewFormat; } //setVFormat - + } // MField diff --git a/base/src/org/compiere/model/GridFieldVO.java b/base/src/org/compiere/model/GridFieldVO.java index 6944b08382..7f06716f0c 100644 --- a/base/src/org/compiere/model/GridFieldVO.java +++ b/base/src/org/compiere/model/GridFieldVO.java @@ -139,6 +139,8 @@ public class GridFieldVO implements Serializable vo.AD_Process_ID = rs.getInt (i); else if (columnName.equalsIgnoreCase("ReadOnlyLogic")) vo.ReadOnlyLogic = rs.getString (i); + else if (columnName.equalsIgnoreCase("MandatoryLogic")) + vo.MandatoryLogic = rs.getString (i); else if (columnName.equalsIgnoreCase("ObscureType")) vo.ObscureType = rs.getString (i); // @@ -378,6 +380,8 @@ public class GridFieldVO implements Serializable public String Description = ""; /** Help */ public String Help = ""; + /** Mandatory Logic */ + public String MandatoryLogic = ""; /** Read Only Logic */ public String ReadOnlyLogic = ""; /** Display Obscure */ @@ -429,6 +433,8 @@ public class GridFieldVO implements Serializable Callout = ""; if (ReadOnlyLogic == null) ReadOnlyLogic = ""; + if (MandatoryLogic == null) + MandatoryLogic = ""; // Create Lookup, if not ID @@ -500,6 +506,7 @@ public class GridFieldVO implements Serializable clone.Description = Description; clone.Help = Help; clone.ReadOnlyLogic = ReadOnlyLogic; + clone.MandatoryLogic = MandatoryLogic; clone.ObscureType = ObscureType; // Lookup clone.ValidationCode = ValidationCode; diff --git a/base/src/org/compiere/model/X_AD_Column.java b/base/src/org/compiere/model/X_AD_Column.java index 0ca809fdcc..70ee5d6bc7 100644 --- a/base/src/org/compiere/model/X_AD_Column.java +++ b/base/src/org/compiere/model/X_AD_Column.java @@ -68,13 +68,13 @@ public X_AD_Column (Properties ctx, ResultSet rs, String trxName) { super (ctx, rs, trxName); } -/** AD_Table_ID=101 */ -public static final int Table_ID=MTable.getTable_ID("AD_Column"); - /** TableName=AD_Column */ public static final String Table_Name="AD_Column"; -protected static KeyNamePair Model = new KeyNamePair(Table_ID,"AD_Column"); +/** AD_Table_ID=101 */ +public static final int Table_ID=MTable.getTable_ID(Table_Name); + +protected static KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name); protected BigDecimal accessLevel = BigDecimal.valueOf(4); /** AccessLevel @@ -600,6 +600,25 @@ return false; } /** Column name IsUpdateable */ public static final String COLUMNNAME_IsUpdateable = "IsUpdateable"; +/** Set Mandatory Logic. +@param MandatoryLogic Logic to determine if field is mandatory (applies only when field is not mandatory in general) */ +public void setMandatoryLogic (String MandatoryLogic) +{ +if (MandatoryLogic != null && MandatoryLogic.length() > 2000) +{ +log.warning("Length > 2000 - truncated"); +MandatoryLogic = MandatoryLogic.substring(0,1999); +} +set_Value ("MandatoryLogic", MandatoryLogic); +} +/** Get Mandatory Logic. +@return Logic to determine if field is mandatory (applies only when field is not mandatory in general) */ +public String getMandatoryLogic() +{ +return (String)get_Value("MandatoryLogic"); +} +/** Column name MandatoryLogic */ +public static final String COLUMNNAME_MandatoryLogic = "MandatoryLogic"; /** Set Name. @param Name Alphanumeric identifier of the entity */ public void setName (String Name) diff --git a/migration/320-trunk/009_add_MandatoryLogic.sql b/migration/320-trunk/009_add_MandatoryLogic.sql new file mode 100644 index 0000000000..9de7817207 --- /dev/null +++ b/migration/320-trunk/009_add_MandatoryLogic.sql @@ -0,0 +1,163 @@ +SET DEFINE OFF; + +INSERT INTO ad_element + (ad_element_id, ad_client_id, ad_org_id, isactive, + created, createdby, + updated, updatedby, + columnname, entitytype, NAME, + printname + ) + VALUES (50074, 0, 0, 'Y', + TO_DATE ('02/26/2007 12:30:00', 'MM/DD/YYYY HH24:MI:SS'), 100, + TO_DATE ('02/26/2007 12:30:00', 'MM/DD/YYYY HH24:MI:SS'), 100, + 'MandatoryLogic', 'D', 'Mandatory Logic', + 'Mandatory Logic' + ); + + +INSERT INTO ad_column + (ad_column_id, ad_client_id, ad_org_id, isactive, + created, + updated, createdby, + updatedby, NAME, description, + help, VERSION, + entitytype, columnname, ad_table_id, ad_reference_id, + fieldlength, iskey, isparent, ismandatory, isupdateable, + isidentifier, seqno, istranslated, isencrypted, + isselectioncolumn, ad_element_id, issyncdatabase, + isalwaysupdateable + ) + VALUES (50218, 0, 0, 'Y', + TO_DATE ('02/26/2007 12:30:00', 'MM/DD/YYYY HH24:MI:SS'), + TO_DATE ('02/26/2007 12:30:00', 'MM/DD/YYYY HH24:MI:SS'), 100, + 100, 'Mandatory Logic', 'Logic to determine if field is mandatory (applies only when field is not mandatory in general)', + 'Logic to determine if field is mandatory (applies only when field is not mandatory in general). + format := {expression} [{logic} {expression}]
+ expression := @{context}@{operand}{value} or @{context}@{operand}{value}
+ logic := {|}|{&}
+ context := any global or window context
+ value := strings or numbers
+ logic operators := AND or OR with the previous result from left to right
+ operand := eq{=}, gt{>}, le{<}, not{~^!}
+ Examples:
+ @AD_Table_ID@=14 | @Language@!GERGER
+ @PriceLimit@>10 | @PriceList@>@PriceActual@
+ @Name@>J
+ Strings may be in single quotes (optional)', 1, + 'D', 'MandatoryLogic', 101, 14, + 2000, 'N', 'N', 'N', 'Y', + 'N', 0, 'N', 'N', + 'N', 50074, 'N', + 'N' + ); + +INSERT INTO ad_field + (ad_field_id, ad_client_id, ad_org_id, isactive, + created, createdby, + updated, updatedby, + NAME, description, + help, + iscentrallymaintained, seqno, ad_tab_id, + ad_column_id, isdisplayed, displaylength, isreadonly, + issameline, isheading, isfieldonly, isencrypted, entitytype + ) + VALUES (50187, 0, 0, 'Y', + TO_DATE ('02/26/2007 12:30:00', 'MM/DD/YYYY HH24:MI:SS'), 100, + TO_DATE ('02/26/2007 12:30:00', 'MM/DD/YYYY HH24:MI:SS'), 100, + 'Mandatory Logic', 'Logic to determine if field is mandatory (applies only when field is not mandatory in general)', + 'Logic to determine if field is mandatory (applies only when field is not mandatory in general). + format := {expression} [{logic} {expression}]
+ expression := @{context}@{operand}{value} or @{context}@{operand}{value}
+ logic := {|}|{&}
+ context := any global or window context
+ value := strings or numbers
+ logic operators := AND or OR with the previous result from left to right
+ operand := eq{=}, gt{>}, le{<}, not{~^!}
+ Examples:
+ @AD_Table_ID@=14 | @Language@!GERGER
+ @PriceLimit@>10 | @PriceList@>@PriceActual@
+ @Name@>J
+ Strings may be in single quotes (optional)', + 'Y', 275 ,101, + 50218, 'Y', 60, 'N', + 'N', 'N', 'N', 'N', 'D' + ); + + + +UPDATE ad_sequence + SET currentnextsys = (SELECT MAX (ad_element_id) + 1 + FROM ad_element + WHERE ad_element_id < 1000000) + WHERE NAME = 'AD_Element'; + +UPDATE ad_sequence + SET currentnextsys = (SELECT MAX (ad_column_id) + 1 + FROM ad_column + WHERE ad_column_id < 1000000) + WHERE NAME = 'AD_Column'; + +UPDATE ad_sequence + SET currentnextsys = (SELECT MAX (ad_field_id) + 1 + FROM ad_field + WHERE ad_field_id < 1000000) + WHERE NAME = 'AD_Field'; + + + +ALTER TABLE ad_column ADD MandatoryLogic NVARCHAR2(2000); + + + + CREATE OR REPLACE FORCE VIEW AD_FIELD_V AS + SELECT t.AD_Window_ID, f.AD_Tab_ID, f.AD_Field_ID, tbl.AD_Table_ID, f.AD_Column_ID, + f.Name, f.Description, f.Help, f.IsDisplayed, f.DisplayLogic, f.DisplayLength, + f.SeqNo, f.SortNo, f.IsSameLine, f.IsHeading, f.IsFieldOnly, f.IsReadOnly, + f.IsEncrypted AS IsEncryptedField, f.ObscureType, + c.ColumnName, c.ColumnSQL, c.FieldLength, c.VFormat, c.DefaultValue, c.IsKey, c.IsParent, + COALESCE(f.IsMandatory, c.IsMandatory) AS IsMandatory, + c.IsIdentifier, c.IsTranslated, c.AD_Reference_Value_ID, + c.Callout, COALESCE(f.AD_Reference_ID, c.AD_Reference_ID) AS AD_Reference_ID, + c.AD_Val_Rule_ID, c.AD_Process_ID, c.IsAlwaysUpdateable, + c.ReadOnlyLogic, c.MandatoryLogic, c.IsUpdateable, c.IsEncrypted AS IsEncryptedColumn, + c.IsSelectionColumn, + tbl.TableName, c.ValueMin, c.ValueMax, + fg.Name AS FieldGroup, vr.Code AS ValidationCode +FROM AD_Field f + INNER JOIN AD_Tab t ON (f.AD_Tab_ID = t.AD_Tab_ID) + LEFT OUTER JOIN AD_FieldGroup fg ON (f.AD_FieldGroup_ID = fg.AD_FieldGroup_ID) + LEFT OUTER JOIN AD_Column c ON (f.AD_Column_ID = c.AD_Column_ID) + INNER JOIN AD_Table tbl ON (c.AD_Table_ID = tbl.AD_Table_ID) + INNER JOIN AD_Reference r ON (c.AD_Reference_ID = r.AD_Reference_ID) + LEFT OUTER JOIN AD_Val_Rule vr ON (c.AD_Val_Rule_ID=vr.AD_Val_Rule_ID) +WHERE f.IsActive = 'Y' + AND c.IsActive = 'Y'; + + + CREATE OR REPLACE FORCE VIEW AD_FIELD_VT AS + SELECT trl.AD_Language, t.AD_Window_ID, f.AD_Tab_ID, f.AD_Field_ID, tbl.AD_Table_ID, f.AD_Column_ID, + trl.Name, trl.Description, trl.Help, f.IsDisplayed, f.DisplayLogic, f.DisplayLength, + f.SeqNo, f.SortNo, f.IsSameLine, f.IsHeading, f.IsFieldOnly, f.IsReadOnly, + f.IsEncrypted AS IsEncryptedField, f.ObscureType, + c.ColumnName, c.ColumnSQL, c.FieldLength, c.VFormat, c.DefaultValue, c.IsKey, c.IsParent, + COALESCE(f.IsMandatory, c.IsMandatory) AS IsMandatory, + c.IsIdentifier, c.IsTranslated, c.AD_Reference_Value_ID, + c.Callout, COALESCE(f.AD_Reference_ID, c.AD_Reference_ID) AS AD_Reference_ID, + c.AD_Val_Rule_ID, c.AD_Process_ID, c.IsAlwaysUpdateable, + c.ReadOnlyLogic, c.MandatoryLogic, c.IsUpdateable, c.IsEncrypted AS IsEncryptedColumn, c.IsSelectionColumn, + tbl.TableName, c.ValueMin, c.ValueMax, + fgt.Name AS FieldGroup, vr.Code AS ValidationCode + FROM AD_Field f + INNER JOIN AD_Field_Trl trl ON (f.AD_Field_ID = trl.AD_Field_ID) + INNER JOIN AD_Tab t ON (f.AD_Tab_ID = t.AD_Tab_ID) + LEFT OUTER JOIN AD_FieldGroup_Trl fgt ON + (f.AD_FieldGroup_ID = fgt.AD_FieldGroup_ID AND trl.AD_Language=fgt.AD_Language) + LEFT OUTER JOIN AD_Column c ON (f.AD_Column_ID = c.AD_Column_ID) + INNER JOIN AD_Table tbl ON (c.AD_Table_ID = tbl.AD_Table_ID) + INNER JOIN AD_Reference r ON (c.AD_Reference_ID = r.AD_Reference_ID) + LEFT OUTER JOIN AD_Val_Rule vr ON (c.AD_Val_Rule_ID=vr.AD_Val_Rule_ID) + WHERE f.IsActive = 'Y' + AND c.IsActive = 'Y'; + + +COMMIT ; \ No newline at end of file