It is not rolling up correctly the lower level costs

http://sourceforge.net/tracker2/?func=detail&aid=2530003&group_id=176962&atid=879332


Cleanup after revision 8228:
* MCost: refactored getByCostType methods
* organized imports
* fixed indentation
This commit is contained in:
teo_sarca 2009-01-29 07:24:17 +00:00
parent d8e27088c0
commit c9eb93eacb
4 changed files with 59 additions and 95 deletions

View File

@ -52,54 +52,24 @@ public class MCost extends X_M_Cost
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Get the the Total Cost for this Cost Element Type and Costing Method * Get the the Total Cost for Cost Type and Cost Element Type
* @param product Product * @param product Product
* @param as Account Schema * @param as Account Schema
* @param AD_Org_ID Organization ID * @param AD_Org_ID Organization ID
* @param M_AttributeSetInstance_ID Attribute Set Instance ID * @param M_AttributeSetInstance_ID Attribute Set Instance ID
* @param C_CostType_ID TODO * @param M_CostType_ID cost type
* @param CostElementType Cost Element Type * @param CostElementType Cost Element Type
* @param Qty Quantity * @param Qty Quantity
* @return Get the the Total Cost for this Cost Element Type and Costing Method * @return Total Costs for Cost Type and Cost Element Type
*/ */
public static BigDecimal getCostByCostType (MProduct product, MAcctSchema as, public static BigDecimal getCostByCostType (MProduct product, MAcctSchema as,
int AD_Org_ID, int M_AttributeSetInstance_ID, int AD_Org_ID, int M_AttributeSetInstance_ID,
int C_CostType_ID, String CostElementType, int M_CostType_ID, String CostElementType,
BigDecimal Qty) BigDecimal Qty)
{ {
//Set the Costing Level Collection<MCost> costs = getByCostType(product, as, M_CostType_ID, AD_Org_ID, M_AttributeSetInstance_ID,
String CostingLevel = product.getCostingLevel(as); CostElementType);
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{
AD_Org_ID = 0;
M_AttributeSetInstance_ID = 0;
}
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
M_AttributeSetInstance_ID = 0;
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
AD_Org_ID = 0;
Collection<MCost> costs = null;
BigDecimal m_cost = Env.ZERO; BigDecimal m_cost = Env.ZERO;
String whereClause = "AD_Client_ID=? AND AD_Org_ID=?"
+ " AND M_Product_ID=?"
+ " AND M_AttributeSetInstance_ID=?"
+ " AND C_AcctSchema_ID=?"
+ " AND EXISTS ( SELECT 1 FROM M_CostElement ce "
+ " WHERE ce.M_CostElement_ID=M_Cost.M_CostElement_ID "
+ " AND ce.CostElementType=?)";
costs = new Query(product.getCtx(), MCost.Table_Name, whereClause, product.get_TrxName())
.setParameters(new Object[]{
product.getAD_Client_ID(),
AD_Org_ID,
product.getM_Product_ID(),
M_AttributeSetInstance_ID,
as.getC_AcctSchema_ID(),
CostElementType})
.setOnlyActiveRecords(true)
.list();
for(MCost cost : costs) for(MCost cost : costs)
{ {
m_cost = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL()); m_cost = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
@ -109,7 +79,7 @@ public class MCost extends X_M_Cost
} // get } // get
/** /**
* Get MCost for Cost Type and Cost Element Type * Get MCosts for Cost Type and Cost Element Type
* @param product Product * @param product Product
* @param as Account Schema * @param as Account Schema
* @param AD_Org_ID Organization ID * @param AD_Org_ID Organization ID
@ -117,13 +87,8 @@ public class MCost extends X_M_Cost
* @param CostElementType Cost Element Type * @param CostElementType Cost Element Type
* @return Get MCost Collection for Cost Type and Cost Element Type * @return Get MCost Collection for Cost Type and Cost Element Type
*/ */
public static Collection<MCost> getByCostType ( public static Collection<MCost> getByCostType (MProduct product, MAcctSchema as,
MProduct product, int M_CostType_ID, int AD_Org_ID, int M_AttributeSetInstance_ID, String CostElementType)
MAcctSchema as,
int M_CostType_ID ,
int AD_Org_ID,
int M_AttributeSetInstance_ID ,
String CostElementType)
{ {
//Set the Costing Level //Set the Costing Level
String CostingLevel = product.getCostingLevel(as); String CostingLevel = product.getCostingLevel(as);
@ -133,15 +98,19 @@ public class MCost extends X_M_Cost
M_AttributeSetInstance_ID = 0; M_AttributeSetInstance_ID = 0;
} }
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
{
M_AttributeSetInstance_ID = 0; M_AttributeSetInstance_ID = 0;
}
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel)) else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
{
AD_Org_ID = 0; AD_Org_ID = 0;
}
String whereClause = "AD_Client_ID=? AND AD_Org_ID=?" String whereClause = "AD_Client_ID=? AND AD_Org_ID=?"
+ " AND M_Product_ID=?" + " AND "+COLUMNNAME_M_Product_ID+"=?"
+ " AND M_AttributeSetInstance_ID=?" + " AND "+COLUMNNAME_M_AttributeSetInstance_ID+"=?"
+ " AND C_AcctSchema_ID=?" + " AND "+COLUMNNAME_C_AcctSchema_ID+"=?"
+ " AND M_CostType_ID=?" + " AND "+COLUMNNAME_M_CostType_ID+"=?"
+ " AND EXISTS (SELECT 1 FROM M_CostElement ce " + " AND EXISTS (SELECT 1 FROM M_CostElement ce "
+ " WHERE ce.M_CostElement_ID=M_Cost.M_CostElement_ID "; + " WHERE ce.M_CostElement_ID=M_Cost.M_CostElement_ID ";
@ -154,8 +123,8 @@ public class MCost extends X_M_Cost
params.add(M_CostType_ID); params.add(M_CostType_ID);
if(CostElementType != null) if(CostElementType != null)
{ {
params.add(CostElementType);
whereClause += "AND ce.CostElementType=?"; whereClause += "AND ce.CostElementType=?";
params.add(CostElementType);
} }
whereClause += ")"; whereClause += ")";
@ -167,7 +136,7 @@ public class MCost extends X_M_Cost
} // get } // get
/** /**
* Get MCost for for Cost Type * Get MCosts for for Cost Type
* @param product Product * @param product Product
* @param as Account Schema * @param as Account Schema
* @param M_CostType_ID Cost Type * @param M_CostType_ID Cost Type
@ -790,7 +759,7 @@ public class MCost extends X_M_Cost
/** /**
* Create standard Costing records for Product * Create standard Costing records for Product
* @param product product * @param product product
**/ */
protected static void create (MProduct product) protected static void create (MProduct product)
{ {
s_log.config(product.getName()); s_log.config(product.getName());

View File

@ -312,7 +312,7 @@ public class MCostElement extends X_M_CostElement
* @param ctx context * @param ctx context
* @param trxName transaction * @param trxName transaction
* @return array cost elements * @return array cost elements
**/ */
public static MCostElement[] getElements (Properties ctx, String trxName) public static MCostElement[] getElements (Properties ctx, String trxName)
{ {
int AD_Client_ID = Env.getAD_Client_ID(ctx); int AD_Client_ID = Env.getAD_Client_ID(ctx);
@ -333,7 +333,7 @@ public class MCostElement extends X_M_CostElement
* @param trxName transaction * @param trxName transaction
* @return array cost elements * @return array cost elements
**/ **/
public static Collection getByCostingMethod (Properties ctx, String CostingMethod) public static Collection<MCostElement> getByCostingMethod (Properties ctx, String CostingMethod)
{ {
final String whereClause = "CostingMethod=?"; final String whereClause = "CostingMethod=?";
return new Query(ctx, Table_Name, whereClause, null) return new Query(ctx, Table_Name, whereClause, null)

View File

@ -31,11 +31,9 @@ import org.adempiere.exceptions.DocTypeNotFoundException;
import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchema;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MCost; import org.compiere.model.MCost;
import org.compiere.model.MCostElement;
import org.compiere.model.MDocType; import org.compiere.model.MDocType;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
import org.compiere.model.MProject; import org.compiere.model.MProject;
import org.compiere.model.MRefList;
import org.compiere.model.MResource; import org.compiere.model.MResource;
import org.compiere.model.MStorage; import org.compiere.model.MStorage;
import org.compiere.model.MTable; import org.compiere.model.MTable;
@ -57,10 +55,7 @@ import org.compiere.wf.MWFNodeNext;
import org.compiere.wf.MWorkflow; import org.compiere.wf.MWorkflow;
/** /**
* Order Model. * PP Order Model.
* Please do not set DocStatus and C_DocType_ID directly.
* They are set in the process() method.
* Use DocAction and C_DocTypeTarget_ID instead.
* *
* @author Victor Perez www.e-evolution.com * @author Victor Perez www.e-evolution.com
* @author Teo Sarca, www.arhipac.ro * @author Teo Sarca, www.arhipac.ro
@ -153,7 +148,6 @@ public class MPPOrder extends X_PP_Order implements DocAction
if (resoruce == null) if (resoruce == null)
throw new IllegalStateException("Resource is mandatory."); throw new IllegalStateException("Resource is mandatory.");
setS_Resource_ID(resoruce.getS_Resource_ID()); setS_Resource_ID(resoruce.getS_Resource_ID());
} // MOrder } // MOrder
/** /**
@ -703,13 +697,15 @@ public class MPPOrder extends X_PP_Order implements DocAction
if (m_processMsg != null) if (m_processMsg != null)
return false; return false;
// TODO: not implemented
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID); m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID);
if (m_processMsg != null) if (m_processMsg != null)
return false; return false;
setProcessed(true); // setProcessed(true);
setDocAction(DOCACTION_None); // setDocAction(DOCACTION_None);
return true; return false;
} // voidIt } // voidIt
public boolean closeIt() public boolean closeIt()
@ -906,12 +902,18 @@ public class MPPOrder extends X_PP_Order implements DocAction
.firstOnly(); .firstOnly();
} }
private MPPOrderWorkflow m_PP_Order_Workflow = null;
public MPPOrderWorkflow getMPPOrderWorkflow() public MPPOrderWorkflow getMPPOrderWorkflow()
{ {
if (m_PP_Order_Workflow != null)
{
return m_PP_Order_Workflow;
}
final String whereClause = MPPOrderWorkflow.COLUMNNAME_PP_Order_ID+"=?"; final String whereClause = MPPOrderWorkflow.COLUMNNAME_PP_Order_ID+"=?";
return new Query(getCtx(), MPPOrderWorkflow.Table_Name, whereClause, get_TrxName()) m_PP_Order_Workflow = new Query(getCtx(), MPPOrderWorkflow.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getPP_Order_ID()}) .setParameters(new Object[]{getPP_Order_ID()})
.firstOnly(); .firstOnly();
return m_PP_Order_Workflow;
} }
/** /**
@ -1055,7 +1057,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, //Production "+" MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, //Production "+"
movementDate, //MovementDate movementDate, //MovementDate
qtyToDeliver, qtyScrap, qtyReject, //qty,scrap,reject qtyToDeliver, qtyScrap, qtyReject, //qty,scrap,reject
0,0, 0,0, //durationSetup,duration
trxName); trxName);
} }

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchema;
import org.compiere.model.MClient;
import org.compiere.model.MCost; import org.compiere.model.MCost;
import org.compiere.model.MCostElement; import org.compiere.model.MCostElement;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
@ -63,9 +62,6 @@ public class RollupWorkflow extends SvrProcess
private MAcctSchema m_as = null; private MAcctSchema m_as = null;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare() protected void prepare()
{ {
for (ProcessInfoParameter para : getParameter()) for (ProcessInfoParameter para : getParameter())
@ -94,11 +90,6 @@ public class RollupWorkflow extends SvrProcess
} }
} // prepare } // prepare
/**
* Perform process.
* @return Message (text with variables)
* @throws Exception if not successful
*/
protected String doIt() throws Exception protected String doIt() throws Exception
{ {
List<Object> params = new ArrayList<Object>(); List<Object> params = new ArrayList<Object>();
@ -129,6 +120,7 @@ public class RollupWorkflow extends SvrProcess
for (MProduct product : products) for (MProduct product : products)
{ {
log.info("Product: "+product);
MPPProductPlanning pp = MPPProductPlanning.find( getCtx(), p_AD_Org_ID , 0, 0, product.get_ID(), get_TrxName()); MPPProductPlanning pp = MPPProductPlanning.find( getCtx(), p_AD_Org_ID , 0, 0, product.get_ID(), get_TrxName());
int AD_Workflow_ID = 0; int AD_Workflow_ID = 0;
if (pp != null) if (pp != null)
@ -145,6 +137,7 @@ public class RollupWorkflow extends SvrProcess
} }
MWorkflow workflow = MWorkflow.get(getCtx(), AD_Workflow_ID); MWorkflow workflow = MWorkflow.get(getCtx(), AD_Workflow_ID);
log.info("Workflow: "+workflow);
workflow.setCost(Env.ZERO); workflow.setCost(Env.ZERO);
MWFNode[] nodes = workflow.getNodes(false, getAD_Client_ID()); MWFNode[] nodes = workflow.getNodes(false, getAD_Client_ID());
@ -178,18 +171,20 @@ public class RollupWorkflow extends SvrProcess
{ {
nodeCost = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_Resource ,p_C_AcctSchema_ID, p_M_CostType_ID, p_AD_Org_ID, node.getSetupTime(), node.getDuration()); nodeCost = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_Resource ,p_C_AcctSchema_ID, p_M_CostType_ID, p_AD_Org_ID, node.getSetupTime(), node.getDuration());
labor = labor.add(nodeCost); labor = labor.add(nodeCost);
log.info("Node="+node+" : Labor : nodeCost="+nodeCost+" => Cost="+labor);
} }
else if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(element.getCostElementType())) else if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(element.getCostElementType()))
{ {
nodeCost = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_BurdenMOverhead ,p_C_AcctSchema_ID, p_M_CostType_ID, p_AD_Org_ID, node.getSetupTime(), node.getDuration()); nodeCost = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_BurdenMOverhead ,p_C_AcctSchema_ID, p_M_CostType_ID, p_AD_Org_ID, node.getSetupTime(), node.getDuration());
burden = burden.add(nodeCost); burden = burden.add(nodeCost);
log.info("Node="+node+" : Burden : nodeCost="+nodeCost+" => Cost="+burden);
} }
if(nodeCost.signum() != 0) if(nodeCost.signum() != 0)
{ {
node.setCost(node.getCost().add(nodeCost)); node.setCost(node.getCost().add(nodeCost));
node.saveEx(); node.saveEx();
} }
} // Node }
// check if element cost is of type Labor // check if element cost is of type Labor
if (MCostElement.COSTELEMENTTYPE_Resource.equals(element.getCostElementType())) if (MCostElement.COSTELEMENTTYPE_Resource.equals(element.getCostElementType()))
{ {
@ -212,6 +207,4 @@ public class RollupWorkflow extends SvrProcess
} }
return "@OK@"; return "@OK@";
} }
} }