use of org.eevolution.exceptions.ActivityProcessedException in project adempiere by adempiere.
the class MPPCostCollector method prepareIt.
// invalidateIt
// @Override
public String prepareIt() {
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
if (m_processMsg != null) {
return DocAction.STATUS_Invalid;
}
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocTypeTarget_ID(), getAD_Org_ID());
// Convert/Check DocType
setC_DocType_ID(getC_DocTypeTarget_ID());
// Operation Activity
if (isActivityControl()) {
MPPOrderNode activity = getPP_Order_Node();
if (MPPOrderNode.DOCACTION_Complete.equals(activity.getDocStatus())) {
throw new ActivityProcessedException(activity);
}
if (activity.isSubcontracting()) {
if (MPPOrderNode.DOCSTATUS_InProgress.equals(activity.getDocStatus()) && MPPCostCollector.DOCSTATUS_InProgress.equals(getDocStatus())) {
return MPPOrderNode.DOCSTATUS_InProgress;
} else if (MPPOrderNode.DOCSTATUS_InProgress.equals(activity.getDocStatus()) && MPPCostCollector.DOCSTATUS_Drafted.equals(getDocStatus())) {
throw new ActivityProcessedException(activity);
}
m_processMsg = createPO(activity);
m_justPrepared = false;
activity.setInProgress(this);
activity.saveEx();
return DOCSTATUS_InProgress;
}
activity.setInProgress(this);
activity.setQtyDelivered(activity.getQtyDelivered().add(getMovementQty()));
activity.setQtyScrap(activity.getQtyScrap().add(getScrappedQty()));
activity.setQtyReject(activity.getQtyReject().add(getQtyReject()));
activity.setDurationReal(activity.getDurationReal().add(getDurationReal()));
activity.setSetupTimeReal(activity.getSetupTimeReal().add(getSetupTimeReal()));
activity.saveEx();
// report all activity previews to milestone activity
if (activity.isMilestone()) {
MPPOrderWorkflow order_workflow = activity.getMPPOrderWorkflow();
order_workflow.closeActivities(activity, getMovementDate(), true);
}
} else // Issue
if (isIssue()) {
MProduct product = getM_Product();
if (getM_AttributeSetInstance_ID() == 0 && product.isASIMandatory(false, getAD_Org_ID())) {
throw new AdempiereException("@M_AttributeSet_ID@ @IsMandatory@ @M_Product_ID@=" + product.getValue());
}
} else // Receipt
if (isReceipt()) {
MProduct product = getM_Product();
if (getM_AttributeSetInstance_ID() == 0 && product.isASIMandatory(true, getAD_Org_ID())) {
throw new AdempiereException("@M_AttributeSet_ID@ @IsMandatory@ @M_Product_ID@=" + product.getValue());
}
}
m_justPrepared = true;
setDocAction(DOCACTION_Complete);
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
if (m_processMsg != null) {
return DocAction.STATUS_Invalid;
}
return DocAction.STATUS_InProgress;
}
use of org.eevolution.exceptions.ActivityProcessedException in project adempiere by adempiere.
the class MPPCostCollector method completeIt.
// rejectIt
// @Override
public String completeIt() {
// Re-Check
if (!m_justPrepared) {
String status = prepareIt();
if (!DocAction.STATUS_InProgress.equals(status))
return status;
}
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE);
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
// Material Receipt
if (isIssue() || isReceipt()) {
// Stock Movement
MProduct product = getM_Product();
if (product != null && product.isStocked() && !isVariance()) {
StorageEngine.createTrasaction(this, getMovementType(), getMovementDate(), getMovementQty(), // IsReversal=false
false, getM_Warehouse_ID(), // Reservation ASI
getPP_Order().getM_AttributeSetInstance_ID(), // Reservation Warehouse
getPP_Order().getM_Warehouse_ID(), // IsSOTrx=false
false);
}
if (isIssue() && !isVariance()) {
// Update PP Order Line
MPPOrderBOMLine obomline = getPP_Order_BOMLine();
obomline.setQtyDelivered(obomline.getQtyDelivered().add(getMovementQty()));
obomline.setQtyScrap(obomline.getQtyScrap().add(getScrappedQty()));
obomline.setQtyReject(obomline.getQtyReject().add(getQtyReject()));
// overwrite=last
obomline.setDateDelivered(getMovementDate());
log.fine("OrderLine - Reserved=" + obomline.getQtyReserved() + ", Delivered=" + obomline.getQtyDelivered());
obomline.saveEx();
log.fine("OrderLine -> Reserved=" + obomline.getQtyReserved() + ", Delivered=" + obomline.getQtyDelivered());
}
if (isReceipt()) {
// Update PP Order Qtys
final MPPOrder order = getPP_Order();
order.setQtyDelivered(order.getQtyDelivered().add(getMovementQty()));
order.setQtyScrap(order.getQtyScrap().add(getScrappedQty()));
order.setQtyReject(order.getQtyReject().add(getQtyReject()));
order.setQtyReserved(order.getQtyReserved().subtract(getMovementQty()));
//
// Update PP Order Dates
// overwrite=last
order.setDateDelivered(getMovementDate());
if (order.getDateStart() == null) {
order.setDateStart(getDateStart());
}
if (order.getQtyOpen().signum() <= 0) {
order.setDateFinish(getDateFinish());
}
order.saveEx();
}
} else // Activity Control
if (isActivityControl()) {
MPPOrderNode activity = getPP_Order_Node();
if (activity.isProcessed()) {
throw new ActivityProcessedException(activity);
}
if (isSubcontracting()) {
String whereClause = MOrderLine.COLUMNNAME_PP_Cost_Collector_ID + "=?";
Collection<MOrderLine> olines = new Query(getCtx(), MOrderLine.Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { get_ID() }).list();
String DocStatus = MPPOrderNode.DOCSTATUS_Completed;
StringBuffer msg = new StringBuffer("The quantity do not is complete for next Purchase Order : ");
for (MOrderLine oline : olines) {
if (oline.getQtyDelivered().compareTo(oline.getQtyOrdered()) < 0) {
DocStatus = MPPOrderNode.DOCSTATUS_InProgress;
}
msg.append(oline.getParent().getDocumentNo()).append(",");
}
if (MPPOrderNode.DOCSTATUS_InProgress.equals(DocStatus)) {
m_processMsg = msg.toString();
return DocStatus;
}
setProcessed(true);
setDocAction(MPPOrderNode.DOCACTION_Close);
setDocStatus(MPPOrderNode.DOCSTATUS_Completed);
activity.completeIt();
activity.saveEx();
m_processMsg = Msg.translate(getCtx(), "PP_Order_ID") + ": " + getPP_Order().getDocumentNo() + " " + Msg.translate(getCtx(), "PP_Order_Node_ID") + ": " + getPP_Order_Node().getValue();
return DocStatus;
} else {
final StandardCostingMethod standardCostingMethod = (StandardCostingMethod) CostingMethodFactory.get().getCostingMethod(X_M_CostType.COSTINGMETHOD_StandardCosting);
standardCostingMethod.createActivityControl(this);
if (activity.getQtyDelivered().compareTo(activity.getQtyRequired()) >= 0) {
activity.closeIt();
activity.saveEx();
}
}
} else // Usage Variance (material)
if (isCostCollectorType(COSTCOLLECTORTYPE_UsegeVariance) && getPP_Order_BOMLine_ID() > 0) {
MPPOrderBOMLine orderBOMLine = getPP_Order_BOMLine();
orderBOMLine.setQtyScrap(orderBOMLine.getQtyScrap().add(getScrappedQty()));
orderBOMLine.setQtyReject(orderBOMLine.getQtyReject().add(getQtyReject()));
log.fine("OrderLine - Reserved=" + orderBOMLine.getQtyReserved() + ", Delivered=" + orderBOMLine.getQtyDelivered());
orderBOMLine.saveEx();
log.fine("OrderLine -> Reserved=" + orderBOMLine.getQtyReserved() + ", Delivered=" + orderBOMLine.getQtyDelivered());
final StandardCostingMethod standardCostingMethod = (StandardCostingMethod) CostingMethodFactory.get().getCostingMethod(X_M_CostType.COSTINGMETHOD_StandardCosting);
standardCostingMethod.createUsageVariances(this);
} else // Usage Variance (resource)
if (isCostCollectorType(COSTCOLLECTORTYPE_UsegeVariance) && getPP_Order_Node_ID() > 0) {
MPPOrderNode activity = getPP_Order_Node();
activity.setDurationReal(activity.getDurationReal().add(getDurationReal()));
activity.setSetupTimeReal(activity.getSetupTimeReal().add(getSetupTimeReal()));
activity.saveEx();
final StandardCostingMethod standardCostingMethod = (StandardCostingMethod) CostingMethodFactory.get().getCostingMethod(X_M_CostType.COSTINGMETHOD_StandardCosting);
standardCostingMethod.createActivityControl(this);
} else {
// nothing
;
}
//
//CostEngineFactory.getCostEngine(getAD_Client_ID()).createRateVariances(this);
//CostEngineFactory.getCostEngine(getAD_Client_ID()).createMethodVariances(this);
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
//
setProcessed(true);
setDocAction(DOCACTION_Close);
setDocStatus(DOCSTATUS_Completed);
return DocAction.STATUS_Completed;
}
Aggregations