Fix issue with Make to Kit

Refactor static method to right class
complete functionality for close the milestone activities or the Manufacturing Order close
This commit is contained in:
vpj-cd 2009-01-19 04:59:51 +00:00
parent 56fe52c525
commit 87c1fd51bf
7 changed files with 256 additions and 225 deletions

View File

@ -182,10 +182,11 @@ public class LiberoValidator implements ModelValidator
if(inout.isSOTrx()) if(inout.isSOTrx())
{ {
final String whereClause = "C_OrderLine_ID IS NOT NULL" final String whereClause = "C_OrderLine_ID IS NOT NULL"
+" AND EXISTS (SELECT 1 FROM C_OrderLine ol , M_InOutLine iol" +" AND EXISTS (SELECT 1 FROM M_InOutLine iol"
+" WHERE ol.C_OrderLine_ID=iol.C_OrderLine_ID AND iol.M_InOut_ID=? )"; +" WHERE iol.M_InOut_ID=? AND PP_Order.C_OrderLine_ID = iol.C_OrderLine_ID) AND "
+ MPPOrder.COLUMNNAME_DocStatus + " = ?";
Collection<MPPOrder> orders = new Query(po.getCtx(), MPPOrder.Table_Name, whereClause, po.get_TrxName()) Collection<MPPOrder> orders = new Query(po.getCtx(), MPPOrder.Table_Name, whereClause, po.get_TrxName())
.setParameters(new Object[]{inout.getM_InOut_ID()}) .setParameters(new Object[]{inout.getM_InOut_ID(), MPPOrder.DOCSTATUS_InProgress})
.list(); .list();
for(MPPOrder order : orders) for(MPPOrder order : orders)
{ {
@ -199,6 +200,7 @@ public class LiberoValidator implements ModelValidator
order.setDocStatus(MPPOrder.DOCACTION_Close); order.setDocStatus(MPPOrder.DOCACTION_Close);
order.setDocAction(MPPOrder.DOCACTION_None); order.setDocAction(MPPOrder.DOCACTION_None);
order.saveEx(); order.saveEx();
} }
} }
} }

View File

@ -69,6 +69,88 @@ import org.eevolution.exceptions.ActivityProcessedException;
public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
* Create & Complete Cost Collector
* @param pp_order
* @param M_Product_ID
* @param M_Locator_ID
* @param M_AttributeSetInstance_ID
* @param S_Resource_ID
* @param PP_Order_BOMLine_ID
* @param PP_Order_Node_ID
* @param C_DocType_ID
* @param CostCollectorType
* @param movementdate
* @param qty
* @param scrap
* @param reject
* @param durationSetup
* @param duration
* @param trxName
* @return completed cost collector
*/
public static MPPCostCollector createCollector (MPPOrder pp_order,
int M_Product_ID,
int M_Locator_ID,
int M_AttributeSetInstance_ID,
int S_Resource_ID,
int PP_Order_BOMLine_ID,
int PP_Order_Node_ID,
int C_DocType_ID,
String CostCollectorType,
Timestamp movementdate,
BigDecimal qty,
BigDecimal scrap,
BigDecimal reject,
int durationSetup,
int duration,
String trxName
)
{
MPPCostCollector cc = new MPPCostCollector(pp_order.getCtx(), 0, trxName);
cc.setPP_Order_ID(pp_order.getPP_Order_ID());
cc.setPP_Order_BOMLine_ID(PP_Order_BOMLine_ID);
cc.setPP_Order_Workflow_ID(pp_order.getMPPOrderWorkflow().getPP_Order_Workflow_ID());
cc.setPP_Order_Node_ID(PP_Order_Node_ID);
cc.setAD_OrgTrx_ID(pp_order.getAD_OrgTrx_ID());
cc.setC_Activity_ID(pp_order.getC_Activity_ID());
cc.setC_Campaign_ID(pp_order.getC_Campaign_ID());
cc.setC_DocType_ID(C_DocType_ID);
cc.setC_DocTypeTarget_ID(C_DocType_ID);
cc.setCostCollectorType(CostCollectorType);
cc.setC_Project_ID(pp_order.getC_Project_ID());
cc.setDescription(pp_order.getDescription());
cc.setDocAction(MPPCostCollector.ACTION_Complete);
cc.setDocStatus(MPPCostCollector.DOCSTATUS_Drafted);
cc.setIsActive(true);
cc.setM_Warehouse_ID(pp_order.getM_Warehouse_ID());
cc.setM_Locator_ID(M_Locator_ID);
cc.setM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
cc.setS_Resource_ID(S_Resource_ID);
cc.setMovementDate(movementdate);
cc.setDateAcct(movementdate);
cc.setMovementQty(qty);
cc.setScrappedQty(scrap);
cc.setQtyReject(reject);
cc.setSetupTimeReal(new BigDecimal(durationSetup));
cc.setDurationReal(new BigDecimal(duration));
cc.setPosted(false);
cc.setProcessed(false);
cc.setProcessing(false);
cc.setUser1_ID(pp_order.getUser1_ID());
cc.setUser2_ID(pp_order.getUser2_ID());
cc.setM_Product_ID(M_Product_ID);
cc.saveEx();
if (!cc.processIt(MPPCostCollector.DOCACTION_Complete))
{
throw new AdempiereException(cc.getProcessMsg());
}
cc.saveEx();
return cc;
}
/** /**
* Standard Constructor * Standard Constructor
@ -230,20 +312,11 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
activity.setSetupTimeReal(activity.getSetupTimeReal()+getSetupTimeReal().intValue()); activity.setSetupTimeReal(activity.getSetupTimeReal()+getSetupTimeReal().intValue());
activity.saveEx(); activity.saveEx();
if (MPPOrderNode.isLastNode(getCtx(), getPP_Order_Node_ID(), get_TrxName())) // report all activity previews to milestone activity
if(activity.isMilestone())
{ {
final String whereClause ="PP_Order_ID=? AND PP_Order_Node_ID<>?" MPPOrderWorkflow order_workflow = activity.getMPPOrderWorkflow();
+" AND NOT EXISTS (SELECT 1 FROM PP_Cost_Collector cc " order_workflow.closeActivities(activity, getMovementDate(), true);
+" WHERE cc.PP_Order_ID=PP_Order_Node.PP_Order_ID"
+" AND cc.PP_Order_Node_ID=PP_Order_Node.PP_Order_Node_ID)";
List<MPPOrderNode> nodes = new Query(getCtx(), MPPOrderNode.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getPP_Order_ID(),getPP_Order_Node_ID()})
.setOnlyActiveRecords(true)
.list();
for (MPPOrderNode node : nodes)
{
createNewNode(node);
}
} }
} }
@ -447,9 +520,10 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
return DocStatus; return DocStatus;
} }
setProcessed(true); setProcessed(true);
setDocAction(DOCACTION_Close); setDocAction(MPPOrderNode.DOCACTION_Close);
setDocStatus(DOCSTATUS_Completed); setDocStatus(MPPOrderNode.DOCSTATUS_Completed);
activity.setDocStatus(DOCSTATUS_Completed); activity.setDocStatus(MPPOrderNode.DOCSTATUS_Completed);
activity.setAction(MPPOrderNode.DOCACTION_None);
activity.saveEx(); activity.saveEx();
m_processMsg = Msg.translate(getCtx(), "PP_Order_ID") m_processMsg = Msg.translate(getCtx(), "PP_Order_ID")
+":"+ getPP_Order().getDocumentNo() +":"+ getPP_Order().getDocumentNo()
@ -461,7 +535,8 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
{ {
if(activity.getQtyDelivered().compareTo(activity.getQtyRequiered()) >= 0) if(activity.getQtyDelivered().compareTo(activity.getQtyRequiered()) >= 0)
{ {
activity.setDocStatus(DOCSTATUS_Completed); activity.setDocStatus(MPPOrderNode.DOCSTATUS_Completed);
activity.setAction(MPPOrderNode.DOCACTION_None);
activity.saveEx(); activity.saveEx();
} }
} }
@ -484,45 +559,6 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
public boolean closeIt() public boolean closeIt()
{ {
log.info("closeIt - " + toString()); log.info("closeIt - " + toString());
// Close Not delivered Qty
// fjviejo e-evolution operation activity
// last node translates to => I complete node
if(!MPPOrderNode.isLastNode(getCtx(), getPP_Order_Node_ID(), get_TrxName()))
{
MPPOrderNode onodeact = new MPPOrderNode(Env.getCtx(),getPP_Order_Node_ID(),get_TrxName());
onodeact.setDocStatus(DOCSTATUS_Closed);
// onodeact.setAction(DOCACTION_None);
onodeact.saveEx();
final String whereClause = COLUMNNAME_PP_Order_ID+"=? AND "+COLUMNNAME_PP_Order_Node_ID+"=?";
List<MPPCostCollector> list = new Query(getCtx(), Table_Name, whereClause, get_TrxName())
.setOnlyActiveRecords(true)
.setParameters(new Object[]{getPP_Order_ID(), getPP_Order_Node_ID()})
.list();
for (MPPCostCollector cc : list)
{
cc.setDocStatus(DOCSTATUS_Closed);
cc.setDocAction(DOCACTION_None);
cc.saveEx();
}
}
else
{
final String whereClause = MPPOrderNode.COLUMNNAME_PP_Order_ID+"=?"
+" AND ("+MPPOrderNode.COLUMNNAME_DocStatus+" IS NULL OR "+MPPOrderNode.COLUMNNAME_DocStatus+"<>?)";
List<MPPOrderNode> list = new Query(getCtx(), MPPOrderNode.Table_Name, whereClause, get_TrxName())
.setOnlyActiveRecords(true)
.setParameters(new Object[]{getPP_Order_ID(), MPPOrderNode.DOCSTATUS_Closed})
.list();
for (MPPOrderNode onode : list)
{
onode.setDocStatus(DOCSTATUS_Closed);
onode.saveEx();
}
closeNew(getPP_Order_ID(), getPP_Order_Node_ID());
}
// fjviejo e-evolution operation activity end
setDocAction(DOCACTION_None); setDocAction(DOCACTION_None);
return true; return true;
} // closeIt } // closeIt
@ -611,43 +647,6 @@ public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
return dt.getName() + " " + getDocumentNo(); return dt.getName() + " " + getDocumentNo();
} // getDocumentInfo } // getDocumentInfo
private void createNewNode(MPPOrderNode node)
{
String whereClause = COLUMNNAME_PP_Order_ID+"=? AND "+COLUMNNAME_PP_Order_Node_ID+"=?";
boolean exists = new Query(getCtx(), Table_Name, whereClause, get_TrxName())
.setOnlyActiveRecords(true)
.setParameters(new Object[]{getPP_Order_ID(), node.getPP_Order_Node_ID()})
.match();
if (!exists)
{
MPPCostCollector costnew = new MPPCostCollector(getCtx(), 0, get_TrxName());
costnew.setPP_Order_ID(getPP_Order_ID());
costnew.setC_DocTypeTarget_ID(getC_DocTypeTarget_ID());
costnew.setC_DocType_ID(getC_DocType_ID());
costnew.setS_Resource_ID(getS_Resource_ID());
costnew.setM_Warehouse_ID(getM_Warehouse_ID());
costnew.setM_Locator_ID(getM_Locator_ID());
costnew.setM_Product_ID(getM_Product_ID());
costnew.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID());
costnew.setPP_Order_Workflow_ID(getPP_Order_Workflow_ID());
costnew.setAD_User_ID(getAD_User_ID());
costnew.setMovementDate(getMovementDate());
costnew.setDateAcct(getDateAcct());
costnew.setMovementQty(getMovementQty());
//costnew.setDurationUnit(getDurationUnit());
costnew.setCostCollectorType(getCostCollectorType());
costnew.setPP_Order_Node_ID(node.getPP_Order_Node_ID());
costnew.setDurationReal(new BigDecimal(node.getDuration()));
costnew.saveEx();
// costnew.completeIt();
}
else
{
log.warning("***** NODE already exists");
}
//completenew(getPP_Order_ID(),node);
}
@Override @Override
protected boolean beforeSave(boolean newRecord) protected boolean beforeSave(boolean newRecord)

View File

@ -22,6 +22,7 @@ import java.math.RoundingMode;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -50,7 +51,6 @@ import org.compiere.process.DocumentEngine;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.wf.MWFNode; import org.compiere.wf.MWFNode;
import org.compiere.wf.MWFNodeNext; import org.compiere.wf.MWFNodeNext;
import org.compiere.wf.MWorkflow; import org.compiere.wf.MWorkflow;
@ -659,12 +659,13 @@ public class MPPOrder extends X_PP_Order implements DocAction
MPPOrder.createReceipt( MPPOrder.createReceipt(
this, this,
today , today ,
this.getQtyDelivered(), getQtyDelivered(),
this.getQtyOpen(), getQtyOpen(),
this.getQtyScrap(), getQtyScrap(),
this.getQtyReject(), getQtyReject(),
this.getM_Locator_ID(), getM_Locator_ID(),
this.getM_AttributeSetInstance_ID(), false, get_TrxName()); getM_AttributeSetInstance_ID(), false, get_TrxName());
setQtyDelivered(getQtyOpen());
return DOCSTATUS_Closed; return DOCSTATUS_Closed;
} }
@ -713,19 +714,28 @@ public class MPPOrder extends X_PP_Order implements DocAction
public boolean closeIt() public boolean closeIt()
{ {
log.info(toString()); log.info(toString());
// Before Close
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_CLOSE);
if (m_processMsg != null)
return false;
if(MPPOrder.DOCSTATUS_Closed.equals(getDocStatus())) if(MPPOrder.DOCSTATUS_Closed.equals(getDocStatus()))
return true; return true;
if(!MPPOrder.DOCSTATUS_Completed.equals(this.getDocStatus())) if(!MPPOrder.DOCSTATUS_Completed.equals(getDocStatus()))
{ {
String DocStatus = completeIt(); String DocStatus = completeIt();
setDocStatus(DocStatus); setDocStatus(DocStatus);
setDocAction(MPPOrder.ACTION_None); setDocAction(MPPOrder.ACTION_None);
} }
// Before Close
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_CLOSE); BigDecimal qtyReported = getQtyDelivered().add(getQtyReject().add(getQtyScrap()));
if (m_processMsg != null) if(qtyReported.signum() > 0)
return false; {
//Close all the activity do not reported
MPPOrderWorkflow m_order_wf = getMPPOrderWorkflow();
m_order_wf.closeActivities(m_order_wf.getLastNode(getAD_Client_ID()), getUpdated(),false);
}
orderStock(); // Clear Ordered Quantities orderStock(); // Clear Ordered Quantities
reserveStock(getLines()); // Clear Reservations reserveStock(getLines()); // Clear Reservations
@ -1007,7 +1017,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
/** /**
* Create Receipt Finish Good * Create Receipt Finish Good
* @param pp_order * @param order
* @param movementDate * @param movementDate
* @param qtyDelivered * @param qtyDelivered
* @param qtyToDeliver * @param qtyToDeliver
@ -1018,7 +1028,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
* @param IsCloseDocument * @param IsCloseDocument
* @param trxName * @param trxName
*/ */
static public void createReceipt(MPPOrder pp_order, static public void createReceipt(MPPOrder order,
Timestamp movementDate, Timestamp movementDate,
BigDecimal qtyDelivered, BigDecimal qtyDelivered,
BigDecimal qtyToDeliver, BigDecimal qtyToDeliver,
@ -1032,28 +1042,33 @@ public class MPPOrder extends X_PP_Order implements DocAction
if (qtyToDeliver.signum() != 0 || qtyScrap.signum() != 0 || qtyReject.signum() != 0) if (qtyToDeliver.signum() != 0 || qtyScrap.signum() != 0 || qtyReject.signum() != 0)
{ {
createCollector(pp_order, pp_order.getM_Product_ID(), MPPCostCollector.createCollector(
M_Locator_ID, order, //MPPOrder
M_AttributeSetInstance_ID, order.getM_Product_ID(), //M_Product_ID
movementDate, M_Locator_ID, //M_Locator_ID
qtyToDeliver, qtyScrap, qtyReject, M_AttributeSetInstance_ID, //M_AttributeSetInstance_ID
MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), order.getS_Resource_ID(), //S_Resource_ID
0, // PP_Order_BOMLine_ID 0, //PP_Order_BOMLine_ID
MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, 0, //PP_Order_Node_ID
MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), //C_DocType_ID
MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, //Production "+"
movementDate, //MovementDate
qtyToDeliver, qtyScrap, qtyReject, //qty,scrap,reject
0,0,
trxName); trxName);
} }
if (IsCloseDocument) if (IsCloseDocument)
{ {
pp_order.setDateFinish(movementDate); order.setDateFinish(movementDate);
pp_order.closeIt(); order.closeIt();
pp_order.saveEx(); order.saveEx();
} }
pp_order.setDateDelivered(movementDate); order.setDateDelivered(movementDate);
if (pp_order.getDateStart() == null) if (order.getDateStart() == null)
{ {
pp_order.setDateStart(movementDate); order.setDateStart(movementDate);
} }
BigDecimal DQ = qtyDelivered; BigDecimal DQ = qtyDelivered;
@ -1061,10 +1076,10 @@ public class MPPOrder extends X_PP_Order implements DocAction
BigDecimal OQ = qtyToDeliver; BigDecimal OQ = qtyToDeliver;
if (DQ.add(SQ).compareTo(OQ) >= 0) if (DQ.add(SQ).compareTo(OQ) >= 0)
{ {
pp_order.setDateFinish(movementDate); order.setDateFinish(movementDate);
} }
pp_order.saveEx(trxName); order.saveEx(trxName);
} }
@ -1077,7 +1092,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
* @param qtyReject * @param qtyReject
* @param storages * @param storages
*/ */
public static void createIssue(MPPOrder pp_order, int PP_OrderBOMLine_ID, public static void createIssue(MPPOrder order, int PP_OrderBOMLine_ID,
Timestamp movementdate, Timestamp movementdate,
BigDecimal qty, BigDecimal qtyScrap, BigDecimal qtyReject, BigDecimal qty, BigDecimal qtyScrap, BigDecimal qtyReject,
MStorage[] storages, MStorage[] storages,
@ -1096,7 +1111,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
BigDecimal qtyIssue = toIssue.min(storage.getQtyOnHand()); BigDecimal qtyIssue = toIssue.min(storage.getQtyOnHand());
//log.fine("ToIssue: " + issue); //log.fine("ToIssue: " + issue);
MPPOrderBOMLine PP_orderbomLine = new MPPOrderBOMLine(pp_order.getCtx(), PP_OrderBOMLine_ID, trxName); MPPOrderBOMLine PP_orderbomLine = new MPPOrderBOMLine(order.getCtx(), PP_OrderBOMLine_ID, trxName);
//create record for negative and positive transaction //create record for negative and positive transaction
if (qtyIssue.signum() != 0 || qtyScrap.signum() != 0 || qtyReject.signum() != 0) if (qtyIssue.signum() != 0 || qtyScrap.signum() != 0 || qtyReject.signum() != 0)
{ {
@ -1108,16 +1123,20 @@ public class MPPOrder extends X_PP_Order implements DocAction
CostCollectorType = MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance; CostCollectorType = MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance;
} }
// //
createCollector (pp_order, MPPCostCollector.createCollector (
PP_orderbomLine.getM_Product_ID(), order, //MPPOrder
storage.getM_Locator_ID(), PP_orderbomLine.getM_Product_ID(), //M_Product_ID
storage.getM_AttributeSetInstance_ID(), storage.getM_Locator_ID(), //M_Locator_ID
movementdate, storage.getM_AttributeSetInstance_ID(), //M_AttributeSetInstance_ID
qtyIssue, qtyScrap, qtyReject, order.getS_Resource_ID(), //S_Resource_ID
MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), PP_OrderBOMLine_ID, //PP_Order_BOMLine_ID
PP_OrderBOMLine_ID, 0, //PP_Order_Node_ID
CostCollectorType, // Production "-" MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), //C_DocType_ID,
trxName CostCollectorType, //Production "-"
movementdate, //MovementDate
qtyIssue, qtyScrap, qtyReject, //qty,scrap,reject
0,0, //durationSetup,duration
trxName //trxName
); );
} }
@ -1133,75 +1152,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
throw new AdempiereException("Should not happen toIssue="+toIssue); throw new AdempiereException("Should not happen toIssue="+toIssue);
} }
} }
/**
* Create & Complete Cost Collector
* @param pp_order
* @param M_Product_ID
* @param M_Locator_ID
* @param M_AttributeSetInstance_ID
* @param movementdate
* @param qty
* @param scrap
* @param reject
* @param C_DocType_ID
* @param PP_Order_BOMLine_ID
* @param CostCollectorType
* @param trxName
* @return completed cost collector
*/
private static MPPCostCollector createCollector (MPPOrder pp_order,
int M_Product_ID,
int M_Locator_ID,
int M_AttributeSetInstance_ID,
Timestamp movementdate,
BigDecimal qty,
BigDecimal scrap,
BigDecimal reject,
int C_DocType_ID,
int PP_Order_BOMLine_ID,
String CostCollectorType,
String trxName
)
{
MPPCostCollector cc = new MPPCostCollector(pp_order.getCtx(), 0, trxName);
cc.setPP_Order_ID(pp_order.getPP_Order_ID());
cc.setPP_Order_BOMLine_ID(PP_Order_BOMLine_ID);
cc.setAD_OrgTrx_ID(pp_order.getAD_OrgTrx_ID());
cc.setC_Activity_ID(pp_order.getC_Activity_ID());
cc.setC_Campaign_ID(pp_order.getC_Campaign_ID());
cc.setC_DocType_ID(C_DocType_ID);
cc.setC_DocTypeTarget_ID(C_DocType_ID);
cc.setCostCollectorType(CostCollectorType);
cc.setC_Project_ID(pp_order.getC_Project_ID());
cc.setDescription(pp_order.getDescription());
cc.setDocAction(MPPCostCollector.ACTION_Complete);
cc.setDocStatus(MPPCostCollector.DOCSTATUS_Drafted);
cc.setIsActive(true);
cc.setM_Warehouse_ID(pp_order.getM_Warehouse_ID());
cc.setM_Locator_ID(M_Locator_ID);
cc.setM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
cc.setS_Resource_ID(pp_order.getS_Resource_ID());
cc.setMovementDate(movementdate);
cc.setDateAcct(movementdate);
cc.setMovementQty(qty);
cc.setScrappedQty(scrap);
cc.setQtyReject(reject);
cc.setPosted(false);
cc.setProcessed(false);
cc.setProcessing(false);
cc.setUser1_ID(pp_order.getUser1_ID());
cc.setUser2_ID(pp_order.getUser2_ID());
cc.setM_Product_ID(M_Product_ID);
cc.saveEx();
if (!cc.processIt(MPPCostCollector.DOCACTION_Complete))
{
throw new AdempiereException(cc.getProcessMsg());
}
cc.saveEx();
return cc;
}
public static boolean isAvailableQty(MPPOrder order, I_PP_Order_BOMLine line) public static boolean isAvailableQty(MPPOrder order, I_PP_Order_BOMLine line)
{ {
MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID()); MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID());
@ -1333,7 +1284,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
/** /**
* @return Default Locator for current Warehouse * @return Default Locator for current Warehouse
*/ */
private int getM_Locator_ID() public int getM_Locator_ID()
{ {
MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID()); MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID());
return wh.getDefaultLocator().getM_Locator_ID(); return wh.getDefaultLocator().getM_Locator_ID();

View File

@ -74,7 +74,8 @@ public class MPPOrderNode extends X_PP_Order_Node
/** Cache */ /** Cache */
private static CCache<Integer,MPPOrderNode> s_cache = new CCache<Integer,MPPOrderNode> (Table_Name, 50); private static CCache<Integer,MPPOrderNode> s_cache = new CCache<Integer,MPPOrderNode> (Table_Name, 50);
/** MPPOrderWorkflow */
MPPOrderWorkflow m_order_wf = null;
/************************************************************************** /**************************************************************************
* Standard Constructor - save to cache * Standard Constructor - save to cache
@ -203,6 +204,8 @@ public class MPPOrderNode extends X_PP_Order_Node
private List<MPPOrderNodeNext> m_next = new ArrayList<MPPOrderNodeNext>(); private List<MPPOrderNodeNext> m_next = new ArrayList<MPPOrderNodeNext>();
/** Duration Base MS */ /** Duration Base MS */
private long m_durationBaseMS = -1; private long m_durationBaseMS = -1;
/** Workflow Order */
private MPPOrder m_workflow = null;
/** /**
* Load Next * Load Next
@ -271,7 +274,7 @@ public class MPPOrderNode extends X_PP_Order_Node
if (duration == 0) if (duration == 0)
return 0; return 0;
if (m_durationBaseMS == -1) if (m_durationBaseMS == -1)
m_durationBaseMS = getPPOrderWorkflow().getDurationBaseSec() * 1000; m_durationBaseMS = getMPPOrderWorkflow().getDurationBaseSec() * 1000;
return duration * m_durationBaseMS; return duration * m_durationBaseMS;
} // getDurationMS } // getDurationMS
@ -285,7 +288,7 @@ public class MPPOrderNode extends X_PP_Order_Node
if (limit == 0) if (limit == 0)
return 0; return 0;
if (m_durationBaseMS == -1) if (m_durationBaseMS == -1)
m_durationBaseMS = getPPOrderWorkflow().getDurationBaseSec() * 1000; m_durationBaseMS = getMPPOrderWorkflow().getDurationBaseSec() * 1000;
return limit * m_durationBaseMS; return limit * m_durationBaseMS;
} // getLimitMS } // getLimitMS
@ -295,18 +298,9 @@ public class MPPOrderNode extends X_PP_Order_Node
*/ */
public int getDurationCalendarField() public int getDurationCalendarField()
{ {
return getPPOrderWorkflow().getDurationCalendarField(); return getMPPOrderWorkflow().getDurationCalendarField();
} // getDurationCalendarField } // getDurationCalendarField
/**
* Get Workflow (NoTrx)
* @return workflow
*/
public MPPOrderWorkflow getPPOrderWorkflow()
{
return MPPOrderWorkflow.get(getCtx(), getPP_Order_Workflow_ID());
} // getWorkflow
/** /**
* String Representation * String Representation
* @return info * @return info
@ -335,7 +329,7 @@ public class MPPOrderNode extends X_PP_Order_Node
{ {
MResource resource = (MResource) getS_Resource(); MResource resource = (MResource) getS_Resource();
//get the rate for this cost type element (Rsource, Burden) //get the rate for this cost type element (Rsource, Burden)
MPPOrderWorkflow workflow = getPPOrderWorkflow(); MPPOrderWorkflow workflow = getMPPOrderWorkflow();
double rate = resource.getResouceRate(C_AcctSchema_ID, M_CostType_ID,CostElementType, AD_Org_ID); double rate = resource.getResouceRate(C_AcctSchema_ID, M_CostType_ID,CostElementType, AD_Org_ID);
BigDecimal cost = Env.ZERO; BigDecimal cost = Env.ZERO;
if (rate == 0) if (rate == 0)
@ -359,4 +353,15 @@ public class MPPOrderNode extends X_PP_Order_Node
} }
return cost; return cost;
} }
/**
* Get Parent
* @return MPPOrderWorkflow
*/
public MPPOrderWorkflow getMPPOrderWorkflow()
{
if (m_order_wf == null)
m_order_wf = new MPPOrderWorkflow(getCtx(), getPP_Order_Workflow_ID(), get_TrxName());
return m_order_wf;
} // getParent
} }

View File

@ -17,6 +17,7 @@
package org.eevolution.model; package org.eevolution.model;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@ -24,6 +25,8 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MDocType;
import org.compiere.model.MOrder;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -149,6 +152,8 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
/** WF Nodes */ /** WF Nodes */
private List<MPPOrderNode> m_nodes = null; private List<MPPOrderNode> m_nodes = null;
/** Manufacturing Order */
private MPPOrder m_order = null;
/** /**
* Load All Nodes * Load All Nodes
@ -411,7 +416,7 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
* @param AD_Client_ID for client * @param AD_Client_ID for client
* @return next PP_Order_Node_ID or 0 * @return next PP_Order_Node_ID or 0
*/ */
public int getLast (int AD_Client_ID) public int getNodeLastID (int AD_Client_ID)
{ {
MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID);
if (nodes.length > 0) if (nodes.length > 0)
@ -420,6 +425,21 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
} }
return 0; return 0;
} // getLast } // getLast
/**
* Get very Last Node
* @param AD_Client_ID for client
* @return next PP_Order_Node_ID or 0
*/
public MPPOrderNode getLastNode (int AD_Client_ID)
{
MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID);
if (nodes.length > 0)
{
return nodes[nodes.length-1];
}
return null;
} // getLast
/** /**
* Is this the first Node * Is this the first Node
@ -516,4 +536,58 @@ public class MPPOrderWorkflow extends X_PP_Order_Workflow
return Calendar.YEAR; return Calendar.YEAR;
return Calendar.MINUTE; return Calendar.MINUTE;
} // getDurationCalendarField } // getDurationCalendarField
/**
* Complete Activities
* @param activity
* @param movementdate
*/
public void closeActivities(MPPOrderNode activity, Timestamp movementdate, boolean milestone)
{
MPPOrderWorkflow order_workflow = activity.getMPPOrderWorkflow();
MPPOrder order = order_workflow.getMPPOrder();
int nodeId = activity.get_ID();
while(nodeId != 0)
{
MPPOrderNode node = MPPOrderNode.get(getCtx(), nodeId);
//break the cycle
if(node.isMilestone() && milestone)
return;
if(!MPPOrderNode.DOCSTATUS_Closed.equals(node.getDocStatus()))
{
MPPCostCollector.createCollector (
order, //MPPOrder
order.getM_Product_ID(), //M_Product_ID
order.getM_Locator_ID(), //M_Locator_ID
order.getM_AttributeSetInstance_ID(), //M_AttributeSetInstance_ID
order.getS_Resource_ID(), //S_Resource_ID
0, //PP_Order_BOMLine_ID
node.get_ID(), //PP_Order_Node_ID
MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), //C_DocType_ID,
MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl, //Activity Control
movementdate, //MovementDate
order.getQtyOrdered(), Env.ZERO, Env.ZERO, //qty,scrap,reject
node.getSetupTimeReal(),node.getDurationReal(), //durationSetup,duration
get_TrxName() //trxName
);
}
nodeId = order_workflow.getPrevious(node.get_ID(), order_workflow.getAD_Client_ID());
}
}
/**
* Get Parent
* @return MPPOrder
*/
public MPPOrder getMPPOrder()
{
if (m_order == null)
m_order = new MPPOrder(getCtx(), getPP_Order_ID(), get_TrxName());
return m_order;
} // getParent
} // MPPOrderWorkflow_ID } // MPPOrderWorkflow_ID

View File

@ -156,7 +156,7 @@ public class CRP extends SvrProcess {
else if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) else if (p_ScheduleType.equals(BACKWARD_SCHEDULING))
{ {
Timestamp date = order.getDateFinishSchedule(); Timestamp date = order.getDateFinishSchedule();
int nodeId = owf.getLast(getAD_Client_ID()); int nodeId = owf.getNodeLastID(getAD_Client_ID());
MPPOrderNode node = null; MPPOrderNode node = null;
while(nodeId != 0) while(nodeId != 0)

View File

@ -240,7 +240,7 @@ public abstract class CRPDatasetFactory extends CRPReasoner implements CRPModel
else if(node.getUserObject() instanceof MPPOrderNode) else if(node.getUserObject() instanceof MPPOrderNode)
{ {
MPPOrderNode on = (MPPOrderNode)node.getUserObject(); MPPOrderNode on = (MPPOrderNode)node.getUserObject();
MPPOrderWorkflow owf = on.getPPOrderWorkflow(); MPPOrderWorkflow owf = on.getMPPOrderWorkflow();
MResourceType rt = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID()); MResourceType rt = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
// no function // no function