use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class CalloutBOM method parent.
/**
* Parent cycle check and BOM Line defaults.
* @param ctx Context
* @param WindowNo current Window No
* @param mTab Model Tab
* @param mField Model Field
* @param value The new value
*/
public String parent(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
if (isCalloutActive() || value == null)
return "";
final int M_Product_ID = (Integer) value;
if (M_Product_ID <= 0)
return "";
I_PP_Product_BOMLine bomLine = GridTabWrapper.create(mTab, I_PP_Product_BOMLine.class);
I_PP_Product_BOM bom = bomLine.getPP_Product_BOM();
if (//Adempiere-272 changes
bom == null) {
throw new AdempiereException("Please save header record first.");
}
if (bom.getM_Product_ID() == bomLine.getM_Product_ID()) {
throw new AdempiereException("@ValidComponent@ - Error Parent not be Component");
}
// Set BOM Line defaults
// May be the parent;
MProduct product = MProduct.get(ctx, M_Product_ID);
bomLine.setDescription(product.getDescription());
bomLine.setHelp(product.getHelp());
bomLine.setC_UOM_ID(product.getC_UOM_ID());
bomLine.setM_AttributeSetInstance_ID(product.getEnvAttributeSetInstance(ctx, WindowNo) == null ? 0 : product.getEnvAttributeSetInstance(ctx, WindowNo));
return "";
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPPOrder method closeIt.
// voidIt
public boolean closeIt() {
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()))
return true;
if (!MPPOrder.DOCSTATUS_Completed.equals(getDocStatus())) {
String DocStatus = completeIt();
setDocStatus(DocStatus);
setDocAction(MPPOrder.ACTION_None);
}
if (!isDelivered()) {
// TODO: Create Message for Translation
throw new AdempiereException("Cannot close this document because do not exist transactions");
}
createVariances();
for (MPPOrderBOMLine line : getLines()) {
BigDecimal old = line.getQtyRequired();
if (old.compareTo(line.getQtyDelivered()) != 0) {
line.setQtyRequired(line.getQtyDelivered());
line.addDescription(Msg.parseTranslation(getCtx(), "@closed@ @QtyRequired@ (" + old + ")"));
line.saveEx();
}
}
//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);
BigDecimal old = getQtyOrdered();
if (old.signum() != 0) {
addDescription(Msg.parseTranslation(getCtx(), "@closed@ @QtyOrdered@ : (" + old + ")"));
setQtyOrdered(getQtyDelivered());
saveEx();
}
// Clear Ordered Quantities
orderStock();
// Clear Reservations
reserveStock(getLines());
setDocStatus(DOCSTATUS_Closed);
//setProcessed(true);
setDocAction(DOCACTION_None);
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_CLOSE);
if (m_processMsg != null)
return false;
return true;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPPOrderWorkflow method closeActivities.
// getDurationCalendarField
/**
* Close Activities
* @param activity current activity / reporting activity
* @param movementDate
* @param milestone stop on previous milestone
*/
public void closeActivities(MPPOrderNode activity, Timestamp movementDate, boolean milestone) {
if (activity.getPP_Order_Workflow_ID() != get_ID()) {
throw new AdempiereException("Activity and Order Workflow not matching" + " (" + activity + ", PP_Order_Workflow_ID=" + get_ID() + ")");
}
MPPOrder order = getMPPOrder();
for (int nodeId = activity.get_ID(); nodeId != 0; nodeId = getPrevious(nodeId, getAD_Client_ID())) {
MPPOrderNode node = getNode(nodeId);
// Break the cycle
if (milestone && node.isMilestone() && node.get_ID() != activity.get_ID()) {
break;
}
if (MPPOrderNode.DOCSTATUS_Drafted.equals(node.getDocStatus())) {
BigDecimal qtyToDeliver = node.getQtyToDeliver();
if (qtyToDeliver.signum() <= 0) {
// TODO: should we create a negate CC?
continue;
}
BigDecimal setupTimeReal = node.getSetupTimeRequired().subtract(node.getSetupTimeReal());
RoutingService routingService = RoutingServiceFactory.get().getRoutingService(node.getAD_Client_ID());
BigDecimal durationReal = routingService.estimateWorkingTime(node, qtyToDeliver);
// arhipac: cristi_pup: Generate even if nothing was reporting on this activity
// https://sourceforge.net/projects/adempiere/forums/forum/639403/topic/3407220
// if (setupTimeReal <= 0 && durationReal.signum() <= 0)
// {
// continue;
// }
MPPCostCollector.createCollector(//MPPOrder
order, //M_Product_ID
order.getM_Product_ID(), //M_Locator_ID
order.getM_Locator_ID(), //M_AttributeSetInstance_ID
order.getM_AttributeSetInstance_ID(), //S_Resource_ID
node.getS_Resource_ID(), //PP_Order_BOMLine_ID
0, //PP_Order_Node_ID
node.get_ID(), //C_DocType_ID,
MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingCostCollector), //Activity Control
MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl, //MovementDate
movementDate, //qty,scrap,reject
qtyToDeliver, //qty,scrap,reject
Env.ZERO, //qty,scrap,reject
Env.ZERO, setupTimeReal, //durationSetup,duration
durationReal);
// reload because it was modified outside of our context
node.load(order.get_TrxName());
node.closeIt();
node.saveEx();
} else if (MPPOrderNode.DOCSTATUS_Completed.equals(node.getDocStatus()) || MPPOrderNode.DOCSTATUS_InProgress.equals(node.getDocStatus())) {
node.closeIt();
node.saveEx();
}
}
// for each node
// reset nodes
m_nodes = null;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPPCostCollector method getCostCollectorNotTransaction.
/**
* get Cost Collector That not was generate by inventory transaction
* @param productId
* @param dateAccount
* @param dateAccountTo
* @param trxName
* @return Collection the Cost Collector
*/
public static List<MPPCostCollector> getCostCollectorNotTransaction(Properties ctx, int productId, Timestamp dateAccount, Timestamp dateAccountTo, String trxName) {
List<Object> params = new ArrayList();
final StringBuffer whereClause = new StringBuffer();
whereClause.append(MPPCostCollector.COLUMNNAME_CostCollectorType + " NOT IN ('100','110') AND ");
if (productId > 0) {
whereClause.append(MPPCostCollector.COLUMNNAME_M_Product_ID + "=? AND ");
params.add(productId);
}
if (dateAccount == null || dateAccountTo == null)
throw new AdempiereException("@DateAcct@ @NotFound@");
whereClause.append(MPPCostCollector.COLUMNNAME_DateAcct + ">=? AND ");
params.add(dateAccount);
whereClause.append(MPPCostCollector.COLUMNNAME_DateAcct + "<=?");
params.add(dateAccountTo);
return new Query(ctx, I_PP_Cost_Collector.Table_Name, whereClause.toString(), trxName).setClient_ID().setParameters(params).list();
}
use of org.adempiere.exceptions.AdempiereException 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;
}
Aggregations