* BF [ 1795817 ] Acct Schema Elements "Account" and "Org" should be mandatory

* fix javadoc
* use COLUMNNAME_* instead of strings
This commit is contained in:
teo_sarca 2007-09-16 17:01:17 +00:00
parent fd8bd2431d
commit be8de7826f
1 changed files with 120 additions and 96 deletions

View File

@ -26,13 +26,16 @@ import org.compiere.util.*;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MAcctSchemaElement.java,v 1.4 2006/08/10 01:00:44 jjanke Exp $ * @version $Id: MAcctSchemaElement.java,v 1.4 2006/08/10 01:00:44 jjanke Exp $
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1795817 ] Acct Schema Elements "Account" and "Org" should be mandatory
*/ */
public final class MAcctSchemaElement extends X_C_AcctSchema_Element public final class MAcctSchemaElement extends X_C_AcctSchema_Element
{ {
/** /**
* Factory: Return ArrayList of Account Schema Elements * Factory: Return ArrayList of Account Schema Elements
* @param as Accounting Schema * @param as Accounting Schema
* @return ArrayList with Elements * @return ArrayList with Elements
*/ */
public static MAcctSchemaElement[] getAcctSchemaElements (MAcctSchema as) public static MAcctSchemaElement[] getAcctSchemaElements (MAcctSchema as)
{ {
@ -76,50 +79,50 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // getAcctSchemaElements } // getAcctSchemaElements
/** /**
* Get Column Name of ELEMENTTYPE * Get Column Name of ELEMENTTYPE
* @param elementType ELEMENTTYPE * @param elementType ELEMENTTYPE
* @return column name * @return column name or "" if not found
*/ */
public static String getColumnName(String elementType) public static String getColumnName(String elementType)
{ {
if (elementType.equals(ELEMENTTYPE_Organization)) if (elementType.equals(ELEMENTTYPE_Organization))
return "AD_Org_ID"; return "AD_Org_ID";
else if (elementType.equals(ELEMENTTYPE_Account)) else if (elementType.equals(ELEMENTTYPE_Account))
return "Account_ID"; return I_C_ValidCombination.COLUMNNAME_Account_ID;
else if (elementType.equals(ELEMENTTYPE_BPartner)) else if (elementType.equals(ELEMENTTYPE_BPartner))
return "C_BPartner_ID"; return I_C_ValidCombination.COLUMNNAME_C_BPartner_ID;
else if (elementType.equals(ELEMENTTYPE_Product)) else if (elementType.equals(ELEMENTTYPE_Product))
return "M_Product_ID"; return I_C_ValidCombination.COLUMNNAME_M_Product_ID;
else if (elementType.equals(ELEMENTTYPE_Activity)) else if (elementType.equals(ELEMENTTYPE_Activity))
return "C_Activity_ID"; return I_C_ValidCombination.COLUMNNAME_C_Activity_ID;
else if (elementType.equals(ELEMENTTYPE_LocationFrom)) else if (elementType.equals(ELEMENTTYPE_LocationFrom))
return "C_LocFrom_ID"; return I_C_ValidCombination.COLUMNNAME_C_LocFrom_ID;
else if (elementType.equals(ELEMENTTYPE_LocationTo)) else if (elementType.equals(ELEMENTTYPE_LocationTo))
return "C_LocTo_ID"; return I_C_ValidCombination.COLUMNNAME_C_LocTo_ID;
else if (elementType.equals(ELEMENTTYPE_Campaign)) else if (elementType.equals(ELEMENTTYPE_Campaign))
return "C_Campaign_ID"; return I_C_ValidCombination.COLUMNNAME_C_Campaign_ID;
else if (elementType.equals(ELEMENTTYPE_OrgTrx)) else if (elementType.equals(ELEMENTTYPE_OrgTrx))
return "AD_OrgTrx_ID"; return I_C_ValidCombination.COLUMNNAME_AD_OrgTrx_ID;
else if (elementType.equals(ELEMENTTYPE_Project)) else if (elementType.equals(ELEMENTTYPE_Project))
return "C_Project_ID"; return I_C_ValidCombination.COLUMNNAME_C_Project_ID;
else if (elementType.equals(ELEMENTTYPE_SalesRegion)) else if (elementType.equals(ELEMENTTYPE_SalesRegion))
return "C_SalesRegion_ID"; return I_C_ValidCombination.COLUMNNAME_C_SalesRegion_ID;
else if (elementType.equals(ELEMENTTYPE_UserList1)) else if (elementType.equals(ELEMENTTYPE_UserList1))
return "User1_ID"; return I_C_ValidCombination.COLUMNNAME_User1_ID;
else if (elementType.equals(ELEMENTTYPE_UserList2)) else if (elementType.equals(ELEMENTTYPE_UserList2))
return "User2_ID"; return I_C_ValidCombination.COLUMNNAME_User2_ID;
else if (elementType.equals(ELEMENTTYPE_UserElement1)) else if (elementType.equals(ELEMENTTYPE_UserElement1))
return "UserElement1_ID"; return I_C_ValidCombination.COLUMNNAME_UserElement1_ID;
else if (elementType.equals(ELEMENTTYPE_UserElement2)) else if (elementType.equals(ELEMENTTYPE_UserElement2))
return "UserElement2_ID"; return I_C_ValidCombination.COLUMNNAME_UserElement2_ID;
// //
return ""; return "";
} // getColumnName } // getColumnName
/** /**
* Get Value Query for ELEMENTTYPE Type * Get Value Query for ELEMENTTYPE Type
* @param elementType ELEMENTTYPE type * @param elementType ELEMENTTYPE type
* @return query "SELECT Value,Name FROM Table WHERE ID=" * @return query "SELECT Value,Name FROM Table WHERE ID=" or "" if not found
*/ */
public static String getValueQuery (String elementType) public static String getValueQuery (String elementType)
{ {
@ -168,10 +171,10 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
/************************************************************************* /*************************************************************************
* Standard Constructor * Standard Constructor
* @param ctx context * @param ctx context
* @param C_AcctSchema_Element_ID id * @param C_AcctSchema_Element_ID id
* @param trxName transaction * @param trxName transaction
*/ */
public MAcctSchemaElement (Properties ctx, int C_AcctSchema_Element_ID, String trxName) public MAcctSchemaElement (Properties ctx, int C_AcctSchema_Element_ID, String trxName)
{ {
@ -191,10 +194,10 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // MAcctSchemaElement } // MAcctSchemaElement
/** /**
* Load Constructor * Load Constructor
* @param ctx context * @param ctx context
* @param rs result set * @param rs result set
* @param trxName transaction * @param trxName transaction
*/ */
public MAcctSchemaElement (Properties ctx, ResultSet rs, String trxName) public MAcctSchemaElement (Properties ctx, ResultSet rs, String trxName)
{ {
@ -202,8 +205,8 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // MAcctSchemaElement } // MAcctSchemaElement
/** /**
* Parent Constructor * Parent Constructor
* @param as accounting schema * @param as accounting schema
*/ */
public MAcctSchemaElement (MAcctSchema as) public MAcctSchemaElement (MAcctSchema as)
{ {
@ -222,10 +225,10 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
private String m_ColumnName = null; private String m_ColumnName = null;
/** /**
* Set Organization Type * Set Organization Type
* @param SeqNo sequence * @param SeqNo sequence
* @param Name name * @param Name name
* @param Org_ID id * @param Org_ID id
*/ */
public void setTypeOrg (int SeqNo, String Name, int Org_ID) public void setTypeOrg (int SeqNo, String Name, int Org_ID)
{ {
@ -236,11 +239,11 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // setTypeOrg } // setTypeOrg
/** /**
* Set Type Account * Set Type Account
* @param SeqNo squence * @param SeqNo squence
* @param Name name * @param Name name
* @param C_Element_ID element * @param C_Element_ID element
* @param C_ElementValue_ID element value * @param C_ElementValue_ID element value
*/ */
public void setTypeAccount (int SeqNo, String Name, int C_Element_ID, int C_ElementValue_ID) public void setTypeAccount (int SeqNo, String Name, int C_Element_ID, int C_ElementValue_ID)
{ {
@ -252,10 +255,10 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // setTypeAccount } // setTypeAccount
/** /**
* Set Type BPartner * Set Type BPartner
* @param SeqNo sequence * @param SeqNo sequence
* @param Name name * @param Name name
* @param C_BPartner_ID id * @param C_BPartner_ID id
*/ */
public void setTypeBPartner (int SeqNo, String Name, int C_BPartner_ID) public void setTypeBPartner (int SeqNo, String Name, int C_BPartner_ID)
{ {
@ -266,10 +269,10 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // setTypeBPartner } // setTypeBPartner
/** /**
* Set Type Product * Set Type Product
* @param SeqNo sequence * @param SeqNo sequence
* @param Name name * @param Name name
* @param M_Product_ID id * @param M_Product_ID id
*/ */
public void setTypeProduct (int SeqNo, String Name, int M_Product_ID) public void setTypeProduct (int SeqNo, String Name, int M_Product_ID)
{ {
@ -280,10 +283,10 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // setTypeProduct } // setTypeProduct
/** /**
* Set Type Project * Set Type Project
* @param SeqNo sequence * @param SeqNo sequence
* @param Name name * @param Name name
* @param C_Project_ID id * @param C_Project_ID id
*/ */
public void setTypeProject (int SeqNo, String Name, int C_Project_ID) public void setTypeProject (int SeqNo, String Name, int C_Project_ID)
{ {
@ -294,9 +297,9 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // setTypeProject } // setTypeProject
/** /**
* Is Element Type * Is Element Type
* @param elementType type * @param elementType type
* @return ELEMENTTYPE type * @return ELEMENTTYPE type
*/ */
public boolean isElementType (String elementType) public boolean isElementType (String elementType)
{ {
@ -306,8 +309,8 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // isElementType } // isElementType
/** /**
* Get Default element value * Get Default element value
* @return default * @return default
*/ */
public int getDefaultValue() public int getDefaultValue()
{ {
@ -348,8 +351,8 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
/** /**
* Get Acct Fact ColumnName * Get Acct Fact ColumnName
* @return column name * @return column name
*/ */
public String getColumnName() public String getColumnName()
{ {
@ -358,8 +361,8 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // getColumnName } // getColumnName
/** /**
* Get Display ColumnName * Get Display ColumnName
* @return column name * @return column name
*/ */
public String getDisplayColumnName() public String getDisplayColumnName()
{ {
@ -375,8 +378,8 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
/** /**
* String representation * String representation
* @return info * @return info
*/ */
public String toString() public String toString()
{ {
@ -389,10 +392,11 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
/** /**
* Before Save * Before Save
* @param newRecord new * @param newRecord new
* @return true if it can be saved * @return true if it can be saved
*/ */
@Override
protected boolean beforeSave (boolean newRecord) protected boolean beforeSave (boolean newRecord)
{ {
if (getAD_Org_ID() != 0) if (getAD_Org_ID() != 0)
@ -402,31 +406,39 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
(ELEMENTTYPE_UserList1.equals(et) || ELEMENTTYPE_UserList2.equals(et) (ELEMENTTYPE_UserList1.equals(et) || ELEMENTTYPE_UserList2.equals(et)
|| ELEMENTTYPE_UserElement1.equals(et) || ELEMENTTYPE_UserElement2.equals(et))) || ELEMENTTYPE_UserElement1.equals(et) || ELEMENTTYPE_UserElement2.equals(et)))
setIsMandatory(false); setIsMandatory(false);
// Acct Schema Elements "Account" and "Org" should be mandatory - teo_sarca BF [ 1795817 ]
if (ELEMENTTYPE_Account.equals(et) || ELEMENTTYPE_Organization.equals(et)) {
if (!isMandatory())
setIsMandatory(true);
if (!isActive())
setIsActive(true);
}
//
else if (isMandatory()) else if (isMandatory())
{ {
String errorField = null; String errorField = null;
if (ELEMENTTYPE_Account.equals(et) && getC_ElementValue_ID() == 0) if (ELEMENTTYPE_Account.equals(et) && getC_ElementValue_ID() == 0)
errorField = "C_ElementValue_ID"; errorField = COLUMNNAME_C_ElementValue_ID;
else if (ELEMENTTYPE_Activity.equals(et) && getC_Activity_ID() == 0) else if (ELEMENTTYPE_Activity.equals(et) && getC_Activity_ID() == 0)
errorField = "C_Activity_ID"; errorField = COLUMNNAME_C_Activity_ID;
else if (ELEMENTTYPE_BPartner.equals(et) && getC_BPartner_ID() == 0) else if (ELEMENTTYPE_BPartner.equals(et) && getC_BPartner_ID() == 0)
errorField = "C_BPartner_ID"; errorField = COLUMNNAME_C_BPartner_ID;
else if (ELEMENTTYPE_Campaign.equals(et) && getC_Campaign_ID() == 0) else if (ELEMENTTYPE_Campaign.equals(et) && getC_Campaign_ID() == 0)
errorField = "C_Campaign_ID"; errorField = COLUMNNAME_C_Campaign_ID;
else if (ELEMENTTYPE_LocationFrom.equals(et) && getC_Location_ID() == 0) else if (ELEMENTTYPE_LocationFrom.equals(et) && getC_Location_ID() == 0)
errorField = "C_Location_ID"; errorField = COLUMNNAME_C_Location_ID;
else if (ELEMENTTYPE_LocationTo.equals(et) && getC_Location_ID() == 0) else if (ELEMENTTYPE_LocationTo.equals(et) && getC_Location_ID() == 0)
errorField = "C_Location_ID"; errorField = COLUMNNAME_C_Location_ID;
else if (ELEMENTTYPE_Organization.equals(et) && getOrg_ID() == 0) else if (ELEMENTTYPE_Organization.equals(et) && getOrg_ID() == 0)
errorField = "Org_ID"; errorField = COLUMNNAME_Org_ID;
else if (ELEMENTTYPE_OrgTrx.equals(et) && getOrg_ID() == 0) else if (ELEMENTTYPE_OrgTrx.equals(et) && getOrg_ID() == 0)
errorField = "Org_ID"; errorField = COLUMNNAME_Org_ID;
else if (ELEMENTTYPE_Product.equals(et) && getM_Product_ID() == 0) else if (ELEMENTTYPE_Product.equals(et) && getM_Product_ID() == 0)
errorField = "M_Product_ID"; errorField = COLUMNNAME_M_Product_ID;
else if (ELEMENTTYPE_Project.equals(et) && getC_Project_ID() == 0) else if (ELEMENTTYPE_Project.equals(et) && getC_Project_ID() == 0)
errorField = "C_Project_ID"; errorField = COLUMNNAME_C_Project_ID;
else if (ELEMENTTYPE_SalesRegion.equals(et) && getC_SalesRegion_ID() == 0) else if (ELEMENTTYPE_SalesRegion.equals(et) && getC_SalesRegion_ID() == 0)
errorField = "C_SalesRegion_ID"; errorField = COLUMNNAME_C_SalesRegion_ID;
if (errorField != null) if (errorField != null)
{ {
log.saveError("Error", Msg.parseTranslation(getCtx(), "@IsMandatory@: @" + errorField + "@")); log.saveError("Error", Msg.parseTranslation(getCtx(), "@IsMandatory@: @" + errorField + "@"));
@ -444,27 +456,28 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // beforeSave } // beforeSave
/** /**
* After Save * After Save
* @param newRecord new * @param newRecord new
* @param success success * @param success success
* @return success * @return success
*/ */
@Override
protected boolean afterSave (boolean newRecord, boolean success) protected boolean afterSave (boolean newRecord, boolean success)
{ {
// Default Value // Default Value
if (isMandatory() && is_ValueChanged("IsMandatory")) if (isMandatory() && is_ValueChanged(COLUMNNAME_IsMandatory))
{ {
if (ELEMENTTYPE_Activity.equals(getElementType())) if (ELEMENTTYPE_Activity.equals(getElementType()))
updateData ("C_Activity_ID", getC_Activity_ID()); updateData (COLUMNNAME_C_Activity_ID, getC_Activity_ID());
else if (ELEMENTTYPE_BPartner.equals(getElementType())) else if (ELEMENTTYPE_BPartner.equals(getElementType()))
updateData ("C_BPartner_ID", getC_BPartner_ID()); updateData (COLUMNNAME_C_BPartner_ID, getC_BPartner_ID());
else if (ELEMENTTYPE_Product.equals(getElementType())) else if (ELEMENTTYPE_Product.equals(getElementType()))
updateData ("M_Product_ID", getM_Product_ID()); updateData (COLUMNNAME_M_Product_ID, getM_Product_ID());
else if (ELEMENTTYPE_Project.equals(getElementType())) else if (ELEMENTTYPE_Project.equals(getElementType()))
updateData ("C_Project_ID", getC_Project_ID()); updateData (COLUMNNAME_C_Project_ID, getC_Project_ID());
} }
// Resequence // Resequence
if (newRecord || is_ValueChanged("SeqNo")) if (newRecord || is_ValueChanged(COLUMNNAME_SeqNo))
MAccount.updateValueDescription(getCtx(), MAccount.updateValueDescription(getCtx(),
"AD_Client_ID=" + getAD_Client_ID(), get_TrxName()); "AD_Client_ID=" + getAD_Client_ID(), get_TrxName());
// Clear Cache // Clear Cache
@ -473,9 +486,9 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
} // afterSave } // afterSave
/** /**
* Update ValidCombination and Fact with mandatory value * Update ValidCombination and Fact with mandatory value
* @param element element * @param element element
* @param id new default * @param id new default
*/ */
private void updateData (String element, int id) private void updateData (String element, int id)
{ {
@ -493,13 +506,24 @@ public final class MAcctSchemaElement extends X_C_AcctSchema_Element
log.fine("ValidCombination=" + noC + ", Fact=" + noF); log.fine("ValidCombination=" + noC + ", Fact=" + noF);
} // updateData } // updateData
@Override
protected boolean beforeDelete ()
{
String et = getElementType();
// Acct Schema Elements "Account" and "Org" should be mandatory - teo_sarca BF [ 1795817 ]
if (ELEMENTTYPE_Account.equals(et) || ELEMENTTYPE_Organization.equals(et)) {
log.saveError("Error", Msg.parseTranslation(getCtx(), "@DeleteError@ @IsMandatory@"));
return false;
}
return true;
}
/** /**
* After Delete * After Delete
* @param success success * @param success success
* @return success * @return success
*/ */
@Override
protected boolean afterDelete (boolean success) protected boolean afterDelete (boolean success)
{ {
// Update Account Info // Update Account Info