FR [ 2552834 ] Refactor as.isSkipOrg(...) code

https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2552834&group_id=176962

Please help me reviewing this
This commit is contained in:
teo_sarca 2009-07-01 11:58:19 +00:00
parent 1b4c0e3e8e
commit 2edca69820
9 changed files with 64 additions and 124 deletions

View File

@ -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

View File

@ -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;
/**
@ -140,9 +140,6 @@ public class MAcctSchema extends X_C_AcctSchema
/** Cache of AcctSchemas **/
private static CCache<Integer,MAcctSchema> s_cache = new CCache<Integer,MAcctSchema>("C_AcctSchema", 3); // 3 accounting schemas
/** Logger */
private static CLogger s_log = CLogger.getCLogger(MAcctSchema.class);
/**************************************************************************
* Standard Constructor
@ -388,24 +385,32 @@ public class MAcctSchema extends X_C_AcctSchema
/**
* 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;

View File

@ -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;
@ -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());

View File

@ -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=?",

View File

@ -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=?",

View File

@ -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=?",

View File

@ -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());

View File

@ -824,16 +824,12 @@ public class Login
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)
{
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)
if (as.isSkipOrg(AD_Org_ID))
{
continue;
}
else
{
C_AcctSchema_ID = as.getC_AcctSchema_ID();

View File

@ -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";
@ -66,6 +67,9 @@ public class AdempiereTestCase extends TestCase {
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) {