From 2edca69820066d455d129e537ecca39931a32461 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Wed, 1 Jul 2009 11:58:19 +0000 Subject: [PATCH] FR [ 2552834 ] Refactor as.isSkipOrg(...) code https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2552834&group_id=176962 Please help me reviewing this --- base/src/org/compiere/acct/Doc.java | 5 --- base/src/org/compiere/model/MAcctSchema.java | 36 ++++++++++++-------- base/src/org/compiere/model/MInventory.java | 18 ++-------- base/src/org/compiere/model/MInvoice.java | 31 ++++------------- base/src/org/compiere/model/MMatchInv.java | 22 +++--------- base/src/org/compiere/model/MMatchPO.java | 22 +++--------- base/src/org/compiere/model/MOrder.java | 11 ++---- base/src/org/compiere/util/Login.java | 34 ++++++++---------- extend/src/test/AdempiereTestCase.java | 9 +++-- 9 files changed, 64 insertions(+), 124 deletions(-) diff --git a/base/src/org/compiere/acct/Doc.java b/base/src/org/compiere/acct/Doc.java index b1ac5d4df1..d303d60e08 100644 --- a/base/src/org/compiere/acct/Doc.java +++ b/base/src/org/compiere/acct/Doc.java @@ -616,11 +616,6 @@ public abstract class Doc boolean skip = false; if (m_ass[i].getAD_OrgOnly_ID() != 0) { - if (m_ass[i].getOnlyOrgs() == null) - m_ass[i].setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - m_ass[i].getAD_OrgOnly_ID())); - // Header Level Org skip = m_ass[i].isSkipOrg(getAD_Org_ID()); // Line Level Org diff --git a/base/src/org/compiere/model/MAcctSchema.java b/base/src/org/compiere/model/MAcctSchema.java index fa79a7060a..0de1304e07 100644 --- a/base/src/org/compiere/model/MAcctSchema.java +++ b/base/src/org/compiere/model/MAcctSchema.java @@ -21,8 +21,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import org.compiere.report.MReportTree; import org.compiere.util.CCache; -import org.compiere.util.CLogger; import org.compiere.util.KeyNamePair; /** @@ -139,9 +139,6 @@ public class MAcctSchema extends X_C_AcctSchema private static CCache s_schema = new CCache("AD_ClientInfo", 3); // 3 clients /** Cache of AcctSchemas **/ private static CCache s_cache = new CCache("C_AcctSchema", 3); // 3 accounting schemas - - /** Logger */ - private static CLogger s_log = CLogger.getCLogger(MAcctSchema.class); /************************************************************************** @@ -386,26 +383,34 @@ public class MAcctSchema extends X_C_AcctSchema } // getDueFrom_Acct /** - * Set Only Org Childs - * @param orgs + * Set Only Org Childs + * @param orgs + * @deprecated only orgs are now fetched automatically + * @throws IllegalStateException every time when you call it */ public void setOnlyOrgs (Integer[] orgs) { - m_onlyOrgs = orgs; +// m_onlyOrgs = orgs; + throw new IllegalStateException("The OnlyOrgs are now fetched automatically"); } // setOnlyOrgs /** - * Set Only Org Childs - * @return orgs + * Get Only Org Children + * @return array of AD_Org_ID */ public Integer[] getOnlyOrgs() { + if (m_onlyOrgs == null) + { + m_onlyOrgs = MReportTree.getChildIDs(getCtx(), + 0, MAcctSchemaElement.ELEMENTTYPE_Organization, + getAD_OrgOnly_ID()); + } return m_onlyOrgs; } // getOnlyOrgs /** * Skip creating postings for this Org. - * Requires setOnlyOrgs (MReportTree requires MTree in Basis) * @param AD_Org_ID * @return true if to skip */ @@ -421,11 +426,14 @@ public class MAcctSchema extends X_C_AcctSchema // Not Summary Only - i.e. skip it if (!m_onlyOrg.isSummary()) return true; - if (m_onlyOrgs == null) - return false; - for (int i = 0; i < m_onlyOrgs.length; i++) + final Integer[] onlyOrgs = getOnlyOrgs(); + if (onlyOrgs == null) { - if (AD_Org_ID == m_onlyOrgs[i].intValue()) + return false; + } + for (int i = 0; i < onlyOrgs.length; i++) + { + if (AD_Org_ID == onlyOrgs[i].intValue()) return false; } return true; diff --git a/base/src/org/compiere/model/MInventory.java b/base/src/org/compiere/model/MInventory.java index 37d108cf9b..3335cdde6c 100644 --- a/base/src/org/compiere/model/MInventory.java +++ b/base/src/org/compiere/model/MInventory.java @@ -25,7 +25,6 @@ import java.util.Properties; import org.compiere.process.DocAction; import org.compiere.process.DocumentEngine; -import org.compiere.report.MReportTree; import org.compiere.util.CCache; import org.compiere.util.DB; import org.compiere.util.Env; @@ -936,7 +935,7 @@ public class MInventory extends X_M_Inventory implements DocAction * @param Qty * @return */ - private String createCostDetail(MInventoryLine line,int M_AttributeSetInstance_ID, BigDecimal qty) + private String createCostDetail(MInventoryLine line, int M_AttributeSetInstance_ID, BigDecimal qty) { // Get Account Schemas to create MCostDetail MAcctSchema[] acctschemas = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID()); @@ -944,21 +943,10 @@ public class MInventory extends X_M_Inventory implements DocAction { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID()) || as.isSkipOrg(line.getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - - // Header Level Org - skip = as.isSkipOrg(getAD_Org_ID()); - // Line Level Org - skip = as.isSkipOrg(line.getAD_Org_ID()); - } - if (skip) continue; + } ProductCost pc = new ProductCost (Env.getCtx(), line.getM_Product_ID(), M_AttributeSetInstance_ID, line.get_TrxName()); diff --git a/base/src/org/compiere/model/MInvoice.java b/base/src/org/compiere/model/MInvoice.java index 240e86ab64..dd8d52da0d 100644 --- a/base/src/org/compiere/model/MInvoice.java +++ b/base/src/org/compiere/model/MInvoice.java @@ -544,9 +544,9 @@ public class MInvoice extends X_C_Invoice implements DocAction + "WHERE AD_Client_ID=? AND DocBaseType=?" + " AND IsActive='Y' " + "ORDER BY IsDefault DESC"; - int C_DocType_ID = DB.getSQLValue(null, sql, getAD_Client_ID(), DocBaseType); + int C_DocType_ID = DB.getSQLValueEx(null, sql, getAD_Client_ID(), DocBaseType); if (C_DocType_ID <= 0) - log.log(Level.SEVERE, "Not found for AC_Client_ID=" + log.log(Level.SEVERE, "Not found for AD_Client_ID=" + getAD_Client_ID() + " - " + DocBaseType); else { @@ -1834,21 +1834,11 @@ public class MInvoice extends X_C_Invoice implements DocAction { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID()) // Header Level Org + || as.isSkipOrg(m_invoiceLine.getAD_Org_ID()) ) // Line Level Org { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - - // Header Level Org - skip = as.isSkipOrg(getAD_Org_ID()); - // Line Level Org - skip = as.isSkipOrg(m_invoiceLine.getAD_Org_ID()); - } - if (skip) continue; + } BigDecimal LineNetAmt = m_invoiceLine.getLineNetAmt(); BigDecimal multiplier = inv.getQty() @@ -2387,17 +2377,10 @@ public class MInvoice extends X_C_Invoice implements DocAction { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(getAD_Org_ID()); - } - if (skip) continue; + } // update/delete Cost Detail and recalculate Current Cost MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=?", diff --git a/base/src/org/compiere/model/MMatchInv.java b/base/src/org/compiere/model/MMatchInv.java index 3972901840..f873adbfc7 100644 --- a/base/src/org/compiere/model/MMatchInv.java +++ b/base/src/org/compiere/model/MMatchInv.java @@ -425,17 +425,10 @@ public class MMatchInv extends X_M_MatchInv { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(getAD_Org_ID()); - } - if (skip) continue; + } BigDecimal LineNetAmt = invoiceLine.getLineNetAmt(); BigDecimal multiplier = getQty() @@ -505,17 +498,10 @@ public class MMatchInv extends X_M_MatchInv { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(getAD_Org_ID()); - } - if (skip) continue; + } // update/delete Cost Detail and recalculate Current Cost MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=?", diff --git a/base/src/org/compiere/model/MMatchPO.java b/base/src/org/compiere/model/MMatchPO.java index b24728c7d2..76b4edb764 100644 --- a/base/src/org/compiere/model/MMatchPO.java +++ b/base/src/org/compiere/model/MMatchPO.java @@ -866,17 +866,10 @@ public class MMatchPO extends X_M_MatchPO { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(getAD_Org_ID()); - } - if (skip) continue; + } // Purchase Order Line BigDecimal poCost = oLine.getPriceCost(); @@ -958,17 +951,10 @@ public class MMatchPO extends X_M_MatchPO { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(getAD_Org_ID()); - } - if (skip) continue; + } // update/delete Cost Detail and recalculate Current Cost MCostDetail cd = MCostDetail.get (getCtx(), "C_OrderLine_ID=?", diff --git a/base/src/org/compiere/model/MOrder.java b/base/src/org/compiere/model/MOrder.java index e9ed217e8e..f353f3c286 100644 --- a/base/src/org/compiere/model/MOrder.java +++ b/base/src/org/compiere/model/MOrder.java @@ -2342,17 +2342,10 @@ public class MOrder extends X_C_Order implements DocAction { MAcctSchema as = acctschemas[asn]; - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + if (as.isSkipOrg(getAD_Org_ID())) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(getAD_Org_ID()); - } - if (skip) continue; + } // update/delete Cost Detail and recalculate Current Cost MMatchPO[] mPO = MMatchPO.getOrderLine(getCtx(), line.getC_OrderLine_ID(), get_TrxName()); diff --git a/base/src/org/compiere/util/Login.java b/base/src/org/compiere/util/Login.java index 5c825bd139..d7bc5b65f3 100644 --- a/base/src/org/compiere/util/Login.java +++ b/base/src/org/compiere/util/Login.java @@ -821,28 +821,24 @@ public class Login MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(Env.getCtx(), AD_Client_ID); if(ass != null && ass.length > 1) { - for(MAcctSchema as: ass) + for(MAcctSchema as : ass) { - C_AcctSchema_ID = MClientInfo.get(Env.getCtx(), AD_Client_ID).getC_AcctSchema1_ID(); - boolean skip = false; - if (as.getAD_OrgOnly_ID() != 0) + C_AcctSchema_ID = MClientInfo.get(Env.getCtx(), AD_Client_ID).getC_AcctSchema1_ID(); + if (as.getAD_OrgOnly_ID() != 0) + { + if (as.isSkipOrg(AD_Org_ID)) { - if (as.getOnlyOrgs() == null) - as.setOnlyOrgs(MReportTree.getChildIDs(Env.getCtx(), - 0, MAcctSchemaElement.ELEMENTTYPE_Organization, - as.getAD_OrgOnly_ID())); - skip = as.isSkipOrg(AD_Org_ID); - if(skip) - continue; - else - { - C_AcctSchema_ID = as.getC_AcctSchema_ID(); - Env.setContext(m_ctx, "$C_AcctSchema_ID", C_AcctSchema_ID); - Env.setContext(m_ctx, "$C_Currency_ID", as.getC_Currency_ID()); - Env.setContext(m_ctx, "$HasAlias", as.isHasAlias()); - break; - } + continue; } + else + { + C_AcctSchema_ID = as.getC_AcctSchema_ID(); + Env.setContext(m_ctx, "$C_AcctSchema_ID", C_AcctSchema_ID); + Env.setContext(m_ctx, "$C_Currency_ID", as.getC_Currency_ID()); + Env.setContext(m_ctx, "$HasAlias", as.isHasAlias()); + break; + } + } } } diff --git a/extend/src/test/AdempiereTestCase.java b/extend/src/test/AdempiereTestCase.java index 4b39bc57e7..b0b85a3197 100644 --- a/extend/src/test/AdempiereTestCase.java +++ b/extend/src/test/AdempiereTestCase.java @@ -24,6 +24,7 @@ import javax.swing.JFileChooser; import junit.framework.TestCase; import org.compiere.util.CLogMgt; +import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Ini; import org.compiere.util.Trx; @@ -32,8 +33,8 @@ import org.compiere.util.Trx; * ADempiere Base Test Case * @author Teo Sarca */ -public class AdempiereTestCase extends TestCase { - +public class AdempiereTestCase extends TestCase +{ // Test: General protected Properties testProperties = null; protected String testPropertiesFileName = "test.properties"; @@ -65,6 +66,9 @@ public class AdempiereTestCase extends TestCase { public final String LogLevel_Key = "LogLevel"; private String LogLevel_DefaultValue = Level.FINEST.toString(); private Level LogLevel_Value = Level.FINEST; + + /** Logger */ + protected final CLogger log = CLogger.getCLogger(getClass()); /** Trx name */ private String trxName = Trx.createTrxName(getClass().getName()+"_"); @@ -120,6 +124,7 @@ public class AdempiereTestCase extends TestCase { testProperties = new Properties(); File file = new File(testPropertiesFileName); if (!file.isFile()) { + log.warning("File not found - "+file.getAbsolutePath()); JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(null); if(returnVal == JFileChooser.APPROVE_OPTION) {