use of org.eevolution.exceptions.BOMExpiredException in project adempiere by adempiere.
the class MPPOrder method explotion.
/**
* Create PP_Order_BOM from PP_Product_BOM.
* Create PP_Order_Workflow from AD_Workflow.
*/
private void explotion() {
// Create BOM Head
final MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
// Product from Order should be same as product from BOM - teo_sarca [ 2817870 ]
if (getM_Product_ID() != PP_Product_BOM.getM_Product_ID()) {
throw new AdempiereException("@NotMatch@ @PP_Product_BOM_ID@ , @M_Product_ID@");
}
// Product BOM Configuration should be verified - teo_sarca [ 2817870 ]
final MProduct product = MProduct.get(getCtx(), PP_Product_BOM.getM_Product_ID());
if (!product.isVerified()) {
// TODO: translate
throw new AdempiereException("Product BOM Configuration not verified. Please verify the product first - " + product.getValue());
}
if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) {
MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName());
PP_Order_BOM.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOM.saveEx();
for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines(true)) {
if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) {
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), PP_Order_BOM.get_ID(), getM_Warehouse_ID(), get_TrxName());
PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
PP_Order_BOMLine.setM_Locator_ID(getM_Locator_ID());
PP_Order_BOMLine.setQtyOrdered(getQtyOrdered());
PP_Order_BOMLine.saveEx();
} else // end if valid From / To
{
log.fine("BOM Line skiped - " + PP_Product_BOMline);
}
}
// end Create Order BOM
} else // end if From / To parent
{
throw new BOMExpiredException(PP_Product_BOM, getDateStartSchedule());
}
// Create Workflow (Routing & Process)
final MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID());
// Workflow should be validated first - teo_sarca [ 2817870 ]
if (!AD_Workflow.isValid()) {
// TODO: translate
throw new AdempiereException("Routing is not valid. Please validate it first - " + AD_Workflow.getValue());
}
if (AD_Workflow.isValidFromTo(getDateStartSchedule())) {
MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName());
PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID());
PP_Order_Workflow.saveEx();
for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) {
if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) {
MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, getQtyOrdered(), get_TrxName());
PP_Order_Node.setAD_Org_ID(getAD_Org_ID());
PP_Order_Node.saveEx();
for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) {
MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
nodenext.setAD_Org_ID(getAD_Org_ID());
nodenext.saveEx();
}
for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
MPPOrderNodeProduct nodeOrderProduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
nodeOrderProduct.setAD_Org_ID(getAD_Org_ID());
nodeOrderProduct.saveEx();
}
for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
nodeorderasset.setAD_Org_ID(getAD_Org_ID());
nodeorderasset.saveEx();
}
}
// for node
}
// Update transitions nexts and set first node
// requery
PP_Order_Workflow.getNodes(true);
for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) {
// set workflow start node
if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
}
// set node next
for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) {
next.setPP_Order_Next_ID();
next.saveEx();
}
}
PP_Order_Workflow.saveEx();
} else // workflow valid from/to
{
throw new RoutingExpiredException(AD_Workflow, getDateStartSchedule());
}
}
Aggregations