Search in sources :

Example 1 with WMRuleEngine

use of org.eevolution.engine.warehouse.WMRuleEngine in project adempiere by adempiere.

the class ReleaseInOutBound method createDistributionOrder.

/**
	 * get Out Bound Order Lines from Smart Browser
	 * @return
     */
/*private List <MWMInOutBoundLine> getOutBoundOrderLine()
	{
		StringBuilder whereClause = new StringBuilder();
		whereClause.append("EXISTS (SELECT 1 FROM WM_InOutBound o WHERE o.WM_InOutBound_ID=WM_InOutBoundLine.WM_InOutBound_ID AND o.Processed='N' AND o.DocAction NOT IN ('CO','CL','VO')) AND ");
		whereClause.append("EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE  T_Selection.AD_PInstance_ID=? AND T_Selection.T_Selection_ID=WM_InOutBoundLine.WM_InOutboundLine_ID)");
		return new Query(getCtx(), I_WM_InOutBoundLine.Table_Name, whereClause.toString(), get_TrxName())
				.setClient_ID()
				.setParameters(getAD_PInstance_ID())
				.list();
	}*/
/**
	 * create Distribution Order to performance a Pick List
	 * @param outBoundOrderLine Out bound Line
	 * @return Quantity that was not covert for inventory
	 */
protected BigDecimal createDistributionOrder(MWMInOutBoundLine outBoundOrderLine) {
    WMRuleEngine engineRule = WMRuleEngine.get();
    List<MStorage> storageList = engineRule.getStorage(outBoundOrderLine, getWarehouseAreaTypeId(), getWarehouseSectionTypeId());
    int shipperId = 0;
    BigDecimal qtySupply = BigDecimal.ZERO;
    if (storageList != null && storageList.size() > 0) {
        //get the warehouse in transit
        MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), outBoundLocator.getAD_Org_ID());
        if (wsts == null || wsts.length == 0)
            throw new AdempiereException("@M_Warehouse_ID@ @IsInTransit@ @NotFound@");
        //Org Must be linked to BPartner
        MOrg org = MOrg.get(getCtx(), outBoundLocator.getAD_Org_ID());
        int partnerId = org.getLinkedC_BPartner_ID(get_TrxName());
        if (partnerId == 0)
            throw new NoBPartnerLinkedforOrgException(org);
        MBPartner partner = MBPartner.get(getCtx(), partnerId);
        if (orderDistribution == null) {
            orderDistribution = new MDDOrder(getCtx(), 0, get_TrxName());
            orderDistribution.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
            orderDistribution.setC_BPartner_ID(partnerId);
            if (getDocumentTypeId() > 0) {
                orderDistribution.setC_DocType_ID(getDocumentTypeId());
            } else {
                orderDistribution.setC_DocType_ID(MDocType.getDocType(X_C_DocType.DOCBASETYPE_DistributionOrder));
            }
            orderDistribution.setM_Warehouse_ID(wsts[0].get_ID());
            if (getDocumentAction() != null)
                orderDistribution.setDocAction(getDocumentAction());
            else
                orderDistribution.setDocAction(X_DD_Order.DOCACTION_Prepare);
            MUser[] users = MUser.getOfBPartner(getCtx(), partner.getC_BPartner_ID(), get_TrxName());
            if (users == null || users.length == 0)
                throw new AdempiereException("@AD_User_ID@ @NotFound@ @Value@ - @C_BPartner_ID@ : " + partner.getValue() + " - " + partner.getName());
            orderDistribution.setAD_User_ID(users[0].getAD_User_ID());
            orderDistribution.setDateOrdered(getToday());
            orderDistribution.setDatePromised(getToday());
            orderDistribution.setM_Shipper_ID(shipperId);
            orderDistribution.setIsInDispute(false);
            orderDistribution.setIsInTransit(false);
            orderDistribution.setSalesRep_ID(getAD_User_ID());
            orderDistribution.saveEx();
        }
        storageList.stream().forEach(storage -> {
            MDDOrderLine orderLine = new MDDOrderLine(orderDistribution);
            orderLine.setM_Locator_ID(storage.getM_Locator_ID());
            orderLine.setM_LocatorTo_ID(outBoundLocator.getM_Locator_ID());
            orderLine.setC_UOM_ID(outBoundOrderLine.getC_UOM_ID());
            orderLine.setM_Product_ID(outBoundOrderLine.getM_Product_ID());
            orderLine.setDateOrdered(getToday());
            orderLine.setDatePromised(outBoundOrderLine.getPickDate());
            orderLine.setWM_InOutBoundLine_ID(outBoundOrderLine.getWM_InOutBoundLine_ID());
            orderLine.setIsInvoiced(false);
            orderLine.saveEx();
        });
    } else {
        qtySupply = outBoundOrderLine.getQtyToPick().subtract(qtySupply);
    }
    return qtySupply;
}
Also used : MBPartner(org.compiere.model.MBPartner) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MWarehouse(org.compiere.model.MWarehouse) MDDOrderLine(org.eevolution.model.MDDOrderLine) WMRuleEngine(org.eevolution.engine.warehouse.WMRuleEngine) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException) NoBPartnerLinkedforOrgException(org.eevolution.exceptions.NoBPartnerLinkedforOrgException) MDDOrder(org.eevolution.model.MDDOrder) MUser(org.compiere.model.MUser)

Aggregations

BigDecimal (java.math.BigDecimal)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MBPartner (org.compiere.model.MBPartner)1 MOrg (org.compiere.model.MOrg)1 MStorage (org.compiere.model.MStorage)1 MUser (org.compiere.model.MUser)1 MWarehouse (org.compiere.model.MWarehouse)1 WMRuleEngine (org.eevolution.engine.warehouse.WMRuleEngine)1 NoBPartnerLinkedforOrgException (org.eevolution.exceptions.NoBPartnerLinkedforOrgException)1 MDDOrder (org.eevolution.model.MDDOrder)1 MDDOrderLine (org.eevolution.model.MDDOrderLine)1