use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MDDOrder method createDropShip.
// completeIt
private void createDropShip() {
//Create movement delivery
Date date = Date.from(LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
Timestamp today = new Timestamp(date.getTime());
List<Integer> recordIds = new ArrayList<>();
recordIds.add(getDD_Order_ID());
ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(GenerateMovement.getProcessId()).withTitle(GenerateMovement.getProcessName()).withRecordId(MDDOrder.Table_ID, 0).withSelectedRecordsIds(recordIds).withParameter(MMovement.COLUMNNAME_MovementDate, today).withParameter(MMovement.COLUMNNAME_DocAction, DocAction.ACTION_Complete).withoutTransactionClose().execute(get_TrxName());
if (processInfo.isError())
throw new AdempiereException(processInfo.getSummary());
List<Integer> orderLinesIds = new ArrayList<>();
LinkedHashMap<Integer, LinkedHashMap<String, Object>> selection = new LinkedHashMap<Integer, LinkedHashMap<String, Object>>();
getLines().stream().filter(orderLine -> orderLine != null).forEach(orderLine -> {
orderLinesIds.add(orderLine.get_ID());
LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
values.put("LINE_" + MDDOrderLine.COLUMNNAME_QtyInTransit, orderLine.getQtyInTransit());
selection.put(orderLine.get_ID(), values);
});
processInfo = ProcessBuilder.create(getCtx()).process(GenerateMovementMaterial.getProcessId()).withTitle(GenerateMovementMaterial.getProcessName()).withRecordId(MDDOrderLine.Table_ID, 0).withSelectedRecordsIds(orderLinesIds, selection).withParameter(MMovement.COLUMNNAME_MovementDate, today).withoutTransactionClose().execute(get_TrxName());
if (processInfo.isError())
throw new AdempiereException(processInfo.getSummary());
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MDDOrder method reserveStock.
// prepareIt
/**
* Reserve Inventory.
* Counterpart: MMovement.completeIt()
* @param orderLines distribution order lines (ordered by M_Product_ID for deadlock prevention)
* @return true if (un) reserved
*/
public void reserveStock(List<MDDOrderLine> orderLines) {
// Always check and (un) Reserve Inventory
orderLines.stream().filter(// filter the order line that where Reserved Quantity need be change
orderLine -> orderLine.getCalculateQtyReserved().signum() != 0).filter(// filter that order line with product stocked
orderLine -> orderLine.getProduct() != null && orderLine.getProduct().isStocked()).forEach(orderLine -> {
MLocator locatorFrom = MLocator.get(getCtx(), orderLine.getM_Locator_ID());
MLocator locatorTo = MLocator.get(getCtx(), orderLine.getM_LocatorTo_ID());
log.fine("Line=" + orderLine.getLine() + " - Ordered=" + orderLine.getQtyOrdered() + ",Reserved=" + orderLine.getQtyReserved() + ",Delivered=" + orderLine.getQtyDelivered());
if (!MStorage.add(getCtx(), locatorTo.getM_Warehouse_ID(), locatorTo.getM_Locator_ID(), orderLine.getM_Product_ID(), orderLine.getM_AttributeSetInstance_ID(), orderLine.getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, orderLine.getCalculateQtyReserved(), get_TrxName()))
throw new AdempiereException("@M_Storage_ID@ @Error@ @To@ @QtyReserved@");
if (!MStorage.add(getCtx(), locatorFrom.getM_Warehouse_ID(), locatorFrom.getM_Locator_ID(), orderLine.getM_Product_ID(), orderLine.getM_AttributeSetInstanceTo_ID(), orderLine.getM_AttributeSetInstance_ID(), Env.ZERO, orderLine.getCalculateQtyReserved(), Env.ZERO, get_TrxName()))
throw new AdempiereException("@M_Storage_ID@ @Error@ @To@ @QtyReserved@");
orderLine.setQtyReserved(orderLine.getQtyReserved().add(orderLine.getCalculateQtyReserved()));
orderLine.saveEx();
});
updateVolume();
updateWeight();
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MDDOrder method setBPartner.
// setShip_User_ID
/**
* Set Business Partner Defaults & Details.
* SOTrx should be set.
* @param bp business partner
*/
public void setBPartner(MBPartner bp) {
if (bp == null)
return;
setC_BPartner_ID(bp.getC_BPartner_ID());
// Defaults Payment Term
int ii = 0;
if (isSOTrx())
ii = bp.getC_PaymentTerm_ID();
else
ii = bp.getPO_PaymentTerm_ID();
// Default Price List
if (isSOTrx())
ii = bp.getM_PriceList_ID();
else
ii = bp.getPO_PriceList_ID();
// Default Delivery/Via Rule
String ss = bp.getDeliveryRule();
if (ss != null)
setDeliveryRule(ss);
ss = bp.getDeliveryViaRule();
if (ss != null)
setDeliveryViaRule(ss);
// Default Invoice/Payment Rule
ss = bp.getInvoiceRule();
if (getSalesRep_ID() == 0) {
ii = Env.getAD_User_ID(getCtx());
if (ii != 0)
setSalesRep_ID(ii);
}
// Set Locations
/*
MBPartnerLocation[] locs = bp.getLocations(false);
if (locs != null)
{
for (int i = 0; i < locs.length; i++)
{
if (locs[i].isShipTo())
{
super.setC_BPartner_Location_ID(locs[i].getC_BPartner_Location_ID());
}
}
// set to first
if (getC_BPartner_Location_ID() == 0 && locs.length > 0)
{
super.setC_BPartner_Location_ID(locs[0].getC_BPartner_Location_ID());
}
}
*/
List<MBPartnerLocation> partnerLocations = Arrays.asList(bp.getLocations(false));
// search the Ship To Location
MBPartnerLocation partnerLocation = // create steam
partnerLocations.stream().filter(pl -> pl.isShipTo()).reduce(// get of last Ship to location
(first, last) -> last).orElse(// if not exist Ship to location else get first partner location
partnerLocations.stream().findFirst().orElseThrow(() -> new AdempiereException("@IsShipTo@ @NotFound@")));
setC_BPartner_Location_ID(partnerLocation.getC_BPartner_Location_ID());
if (getC_BPartner_Location_ID() == 0) {
log.log(Level.SEVERE, "MDDOrder.setBPartner - Has no Ship To Address: " + bp);
}
// Set Contact
/*MUser[] contacts = bp.getContacts(false);
if (contacts != null && contacts.length == 1)
{
setAD_User_ID(contacts[0].getAD_User_ID());
}*/
Arrays.asList(bp.getContacts(false)).stream().findFirst().ifPresent(user -> setAD_User_ID(user.getAD_User_ID()));
}
use of org.adempiere.exceptions.AdempiereException 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());
}
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPPOrder method updateMakeToKit.
/**
* Create Auto Receipt and Issue based on Quantity
* @param qtyShipment
*/
public void updateMakeToKit(BigDecimal qtyShipment) {
MPPOrderBOM orderBOM = (MPPOrderBOM) getMPPOrderBOM();
getLines(true);
// Auto receipt and issue for kit
if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(orderBOM.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(orderBOM.getBOMUse())) {
Timestamp today = new Timestamp(System.currentTimeMillis());
ArrayList[][] issue = new ArrayList[m_lines.length][1];
for (int i = 0; i < getLines().length; i++) {
MPPOrderBOMLine line = m_lines[i];
KeyNamePair id = null;
if (MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) {
id = new KeyNamePair(line.get_ID(), "Y");
} else
id = new KeyNamePair(line.get_ID(), "N");
ArrayList<Object> data = new ArrayList<Object>();
BigDecimal qtyToDeliver = qtyShipment.multiply(line.getQtyMultiplier());
//0 - MPPOrderBOMLine ID
data.add(id);
//1 - Critical
data.add(line.isCritical());
MProduct product = (MProduct) line.getM_Product();
//2 - Value
data.add(product.getValue());
KeyNamePair productKey = new KeyNamePair(product.get_ID(), product.getName());
//3 - KeyNamePair Product
data.add(productKey);
//4 - QtyToDeliver
data.add(qtyToDeliver);
//5 - QtyScrapComponent
data.add(Env.ZERO);
issue[i][0] = data;
}
boolean forceIssue = false;
MOrderLine orderLine = (MOrderLine) getC_OrderLine();
if (MOrder.DELIVERYRULE_CompleteLine.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_CompleteOrder.equals(orderLine.getParent().getDeliveryRule())) {
boolean isCompleteQtyDeliver = MPPOrder.isQtyAvailable(this, issue, today);
if (!isCompleteQtyDeliver) {
throw new AdempiereException("@NoQtyAvailable@");
}
} else if (MOrder.DELIVERYRULE_Availability.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_AfterReceipt.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_Manual.equals(orderLine.getParent().getDeliveryRule())) {
throw new AdempiereException("@DeliveryRule@ " + orderLine.getParent().getDeliveryRule() + "@ActionNotSupported@");
} else if (MOrder.DELIVERYRULE_Force.equals(orderLine.getParent().getDeliveryRule())) {
forceIssue = true;
}
for (int i = 0; i < issue.length; i++) {
int attributeSetInstanceId = 0;
KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
Boolean isCritical = (Boolean) issue[i][0].get(1);
String value = (String) issue[i][0].get(2);
KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
int productId = productkey.getKey();
MProduct product = MProduct.get(getCtx(), productId);
BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
MPPOrderBOMLine orderBOMLine = null;
int orderBOMLineId = (Integer) key.getKey();
if (orderBOMLineId > 0) {
orderBOMLine = new MPPOrderBOMLine(getCtx(), orderBOMLineId, get_TrxName());
//Validate if AttributeSet generate instance
attributeSetInstanceId = orderBOMLine.getM_AttributeSetInstance_ID();
}
MStorage[] storages = MPPOrder.getStorages(getCtx(), productId, getM_Warehouse_ID(), attributeSetInstanceId, today, get_TrxName());
MPPOrder.createIssue(this, orderBOMLine, today, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
}
MPPOrder.createReceipt(this, today, getQtyDelivered(), qtyShipment, getQtyScrap(), getQtyReject(), getM_Locator_ID(), getM_AttributeSetInstance_ID());
}
}
Aggregations