The rate for Labor and Burden return Zero when the org have value

The get rate need validate the costing level.
http://sourceforge.net/tracker/?func=detail&atid=879332&aid=2512101&group_id=176962

I made my first test Class :-)
This commit is contained in:
vpj-cd 2009-01-16 01:21:23 +00:00
parent 2cf981578d
commit b34ff63fde
4 changed files with 97 additions and 80 deletions

View File

@ -24,6 +24,7 @@ import org.compiere.model.MAcctSchema;
import org.compiere.model.MCost;
import org.compiere.model.MCostElement;
import org.compiere.model.MProduct;
import org.compiere.model.MRefList;
import org.compiere.model.ProductCost;
import org.compiere.model.Query;
import org.compiere.util.Env;
@ -110,7 +111,7 @@ public class Doc_Cost_Collector extends Doc
setC_Currency_ID (as.getC_Currency_ID());
MProduct product = MProduct.get(getCtx(), m_cc.getM_Product_ID());
if(m_cc.getCostCollectorType().equals(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt))
if(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt.equals(m_cc.getCostCollectorType()))
{
//Finish good
MAccount debit = m_line.getAccount(ProductCost.ACCTTYPE_P_Asset, as);
@ -175,7 +176,7 @@ public class Doc_Cost_Collector extends Doc
createLines(MCostElement.COSTELEMENTTYPE_OutsideProcessing, as, fact, product, debit, credit, cost, m_cc.getScrappedQty());
}
}
else if (m_cc.getCostCollectorType().equals(MPPCostCollector.COSTCOLLECTORTYPE_ComponentIssue))
else if (MPPCostCollector.COSTCOLLECTORTYPE_ComponentIssue.equals(m_cc.getCostCollectorType()))
{
MAccount debit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as);
@ -223,11 +224,11 @@ public class Doc_Cost_Collector extends Doc
}
else if (m_cc.getCostCollectorType().equals(MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl))
else if (MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl.equals(m_cc.getCostCollectorType()))
{
MPPOrderNode activity = (MPPOrderNode) m_cc.getPP_Order_Node();
MWFNode node = (MWFNode) activity.getAD_WF_Node();
if(activity.getDocAction().equals(MPPOrderNode.DOCSTATUS_Completed))
if(MPPOrderNode.DOCSTATUS_Completed.equals(activity.getDocAction()))
{
//Labor Rate
MAccount debit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as);
@ -262,7 +263,8 @@ public class Doc_Cost_Collector extends Doc
{
dr = fact.createLine(m_line, debit , as.getC_Currency_ID(), cost, null);
dr.setQty(qty);
dr.addDescription(Msg.translate(m_cc.getCtx(), CostElementType));
String desc = MRefList.getListName(getCtx(), MCostElement.COSTELEMENTTYPE_AD_Reference_ID, CostElementType);
dr.addDescription(Msg.translate(m_cc.getCtx(), desc));
dr.setC_Project_ID(m_cc.getC_Project_ID());
dr.setC_Activity_ID(m_cc.getC_Activity_ID());
dr.setC_Campaign_ID(m_cc.getC_Campaign_ID());
@ -270,7 +272,7 @@ public class Doc_Cost_Collector extends Doc
cr = fact.createLine(m_line, credit,as.getC_Currency_ID(), null, cost);
cr.setQty(qty);
cr.addDescription(Msg.translate(m_cc.getCtx(), CostElementType));
cr.addDescription(Msg.translate(m_cc.getCtx(), desc));
cr.setC_Project_ID(m_cc.getC_Project_ID());
cr.setC_Activity_ID(m_cc.getC_Activity_ID());
cr.setC_Campaign_ID(m_cc.getC_Campaign_ID());

View File

@ -172,6 +172,14 @@ public class MResource extends X_S_Resource
*/
public double getResouceRate(int C_AcctSchema_ID,int M_CostType_ID, String CostElementType , int AD_Org_ID)
{
MAcctSchema as = MAcctSchema.get(getCtx(), C_AcctSchema_ID);
MProduct product = getProduct();
if(MAcctSchema.COSTINGLEVEL_Client.equals(product.getCostingLevel(as)))
{
AD_Org_ID = 0;
}
final String sql = "SELECT SUM(c."+MCost.COLUMNNAME_CurrentCostPrice+")"
+" FROM M_Cost c, M_CostElement ce, M_Product p"
+" WHERE c.AD_Client_ID=? AND c.AD_Org_ID=?"

View File

@ -993,78 +993,4 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
}
return false;
}
/**
* Test
* @param args ignored
* @throws IOException
* @throws FileNotFoundException
*
public static void main (String[] args) throws FileNotFoundException, IOException
{
// Test: General
//Properties testProperties = null;
// Test Context
Properties m_Ctx = null;
// IsClient
String isClient_Key = "isClient";
String isClient_DefaultValue = "Y";
boolean isClient_Value = true;
// AD_User
final String AD_User_ID_Key = "AD_User_ID";
String AD_User_ID_DefaultValue = "100"; //SuperUser
int AD_User_ID_Value = 0;
// AD_Client
final String AD_Client_ID_Key = "AD_Client_ID";
String AD_Client_ID_DefaultValue = "11"; //GardenWorld
int AD_Client_ID_Value = 11;
// LogLevel:
final String LogLevel_Key = "LogLevel";
String LogLevel_DefaultValue = Level.FINEST.toString();
Level LogLevel_Value = Level.FINEST;
// Trx name
String trxName = "test";
Ini.setClient (isClient_Value);
Adempiere.startup(isClient_Value);
m_Ctx = Env.getCtx();
m_Ctx.setProperty("#AD_User_ID", new Integer(AD_User_ID_Value).toString());
m_Ctx.setProperty("#AD_Client_ID", new Integer(AD_Client_ID_Value).toString());
// if (fileName_Value.length() < 1) {
// throw new AdempiereException("Please specify path to Adempiere.properties file!");
// }
//
// System.setProperty("PropertyFile", fileName_Value);
//CLogMgt.setLevel(LogLevel_Value);
CLogMgt.setLevel(Level.ALL);
List <MPPCostCollector> ccs =new Query(m_Ctx, MPPCostCollector.Table_Name, "", null ).list();
for (MPPCostCollector cc : ccs)
{
System.out.println("Cost Collector" + cc.getDocumentNo());
MAcctSchema[] m_ass = MAcctSchema.getClientAcctSchema(Env.getCtx(), 11);
Doc doc = Doc.get (m_ass, MPPCostCollector.Table_ID, cc.get_ID(), null);
if (doc == null)
{
throw new AdempiereException("Documento no creado");
}
else
{
String error = doc.post(true, true); // post no force/repost
}
}
}
/**/
} // MPPCostCollector

View File

@ -0,0 +1,81 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
*****************************************************************************/
package test.functional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import org.compiere.acct.Doc;
import org.compiere.model.MAcctSchema;
import org.compiere.model.Query;
import org.compiere.util.CLogMgt;
import org.compiere.util.Env;
import org.eevolution.model.MPPCostCollector;
import org.jfree.util.Log;
import test.AdempiereTestCase;
/**
* Test MPPCostCollectorPostTest
* @author victor.perez@e-evolution.com, http://e-evolution.com
*/
public class MPPCostCollectorPostTest extends AdempiereTestCase {
int PP_Cost_Collector_ID=1000010;
protected void setUp() throws Exception {
super.setUp();
assertEquals("Client is not GardenWorld", 11, Env.getAD_Client_ID(getCtx()));
}
public MPPCostCollectorPostTest()
{
}
public void testPosting() throws Exception
{
//CLogMgt.setLevel(LogLevel_Value);
CLogMgt.setLevel(Level.ALL);
String whereClause = "";
ArrayList params = new ArrayList();
if(PP_Cost_Collector_ID > 0)
{
whereClause = whereClause + MPPCostCollector.COLUMNNAME_PP_Cost_Collector_ID + "=?";
params.add(PP_Cost_Collector_ID);
}
Collection <MPPCostCollector> ccs =new Query(getCtx(), MPPCostCollector.Table_Name, whereClause, null )
.setParameters(params)
.list();
for (MPPCostCollector cc : ccs)
{
Log.info("Cost Collector" + cc.getDocumentNo());
MAcctSchema[] m_ass = MAcctSchema.getClientAcctSchema(Env.getCtx(), 11);
Doc doc = Doc.get (m_ass, MPPCostCollector.Table_ID, cc.get_ID(), null);
if (doc == null)
{
fail("Should show a Exception");
}
else
{
String error = doc.post(true, true); // post no force/repost
assertNull(null, error);
}
}
}
}