Search in sources :

Example 31 with MWarehouse

use of org.compiere.model.MWarehouse in project adempiere by adempiere.

the class MStorageTest method testGetQtyAvailable.

public void testGetQtyAvailable() throws Exception {
    BigDecimal whQty = Env.ZERO;
    MWarehouse wh = new MWarehouse(getCtx(), 0, getTrxName());
    wh.setValue("test-wh");
    wh.setName("test-wh");
    wh.setC_Location_ID(location_id);
    wh.saveEx();
    assertWarehouseQty(wh, whQty);
    //
    for (int i = 1; i <= 10; i++) {
        createLocator(wh, "" + i, i);
        whQty = whQty.add(BigDecimal.valueOf(i));
        assertWarehouseQty(wh, whQty);
    }
}
Also used : BigDecimal(java.math.BigDecimal) MWarehouse(org.compiere.model.MWarehouse)

Example 32 with MWarehouse

use of org.compiere.model.MWarehouse in project adempiere by adempiere.

the class InventoryUtil method getCreateLocator.

/**
	 * Helper Method : Create Locator
	 */
public static MLocator getCreateLocator(int AD_Org_ID, String whValue, String value) {
    if (AD_Org_ID <= 0)
        AD_Org_ID = getFirst_Org_ID();
    MWarehouse wh = getCreateWarehouse(AD_Org_ID, whValue);
    MLocator locator = null;
    for (MLocator loc : wh.getLocators(false)) {
        if (loc.getValue().equals(value)) {
            locator = loc;
            break;
        }
    }
    if (locator == null) {
        locator = new MLocator(wh, value);
        locator.setXYZ(value, value, value);
    }
    if (wh.getLocators(false).length == 0) {
        locator.setIsDefault(true);
    }
    locator.saveEx();
    //
    return locator;
}
Also used : MLocator(org.compiere.model.MLocator) MWarehouse(org.compiere.model.MWarehouse)

Example 33 with MWarehouse

use of org.compiere.model.MWarehouse in project adempiere by adempiere.

the class CPOS method validLocator.

/**
	 * Valid Locator
	 * @return
	 * @return String
	 */
public void validLocator() {
    MWarehouse warehouse = MWarehouse.get(ctx, getM_Warehouse_ID());
    MLocator[] locators = warehouse.getLocators(true);
    for (MLocator mLocator : locators) {
        if (mLocator.isDefault()) {
            return;
        }
    }
    throw new AdempierePOSException("@M_Locator_ID@ @default@ " + "@not.found@ @M_Warehouse_ID@: " + warehouse.getName());
}
Also used : MLocator(org.compiere.model.MLocator) AdempierePOSException(org.adempiere.pos.AdempierePOSException) MWarehouse(org.compiere.model.MWarehouse)

Example 34 with MWarehouse

use of org.compiere.model.MWarehouse in project adempiere by adempiere.

the class ReplenishReportProduction method createMovements.

//	createRequisition
/**
	 * 	Create Inventory Movements
	 */
private void createMovements() {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MMovement move = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL AND C_BPartner_ID > 0");
    for (int i = 0; i < replenishs.length; i++) {
        X_T_Replenish replenish = replenishs[i];
        if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
            whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
            client = MClient.get(getCtx(), whSource.getAD_Client_ID());
        //
        if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
            M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
            M_Warehouse_ID = replenish.getM_Warehouse_ID();
            move = new MMovement(getCtx(), 0, get_TrxName());
            move.setC_DocType_ID(p_C_DocType_ID);
            move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            move.setAD_Org_ID(whSource.getAD_Org_ID());
            if (!move.save())
                return;
            log.fine(move.toString());
            noMoves++;
            info += " - " + move.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        //	From: Look-up Storage
        MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
        String MMPolicy = product.getMMPolicy();
        MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
        //
        BigDecimal target = replenish.getQtyToOrder();
        for (int j = 0; j < storages.length; j++) {
            MStorage storage = storages[j];
            if (storage.getQtyOnHand().signum() <= 0)
                continue;
            BigDecimal moveQty = target;
            if (storage.getQtyOnHand().compareTo(moveQty) < 0)
                moveQty = storage.getQtyOnHand();
            //
            MMovementLine line = new MMovementLine(move);
            line.setM_Product_ID(replenish.getM_Product_ID());
            line.setMovementQty(moveQty);
            if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
                line.setDescription("Total: " + replenish.getQtyToOrder());
            //	from
            line.setM_Locator_ID(storage.getM_Locator_ID());
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
            //	to
            line.setM_LocatorTo_ID(M_LocatorTo_ID);
            line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
            line.save();
            //
            target = target.subtract(moveQty);
            if (target.signum() == 0)
                break;
        }
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : MProduct(org.compiere.model.MProduct) X_T_Replenish(org.compiere.model.X_T_Replenish) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement) MStorage(org.compiere.model.MStorage) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MClient(org.compiere.model.MClient)

Example 35 with MWarehouse

use of org.compiere.model.MWarehouse in project adempiere by adempiere.

the class ReplenishReportProduction method createDO.

//	Create Inventory Movements
/**
	 * 	Create Distribution Order
	 */
private void createDO() throws Exception {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MDDOrder order = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
    for (X_T_Replenish replenish : replenishs) {
        if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
            whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
            client = MClient.get(getCtx(), whSource.getAD_Client_ID());
        //
        if (order == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
            M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
            M_Warehouse_ID = replenish.getM_Warehouse_ID();
            order = new MDDOrder(getCtx(), 0, get_TrxName());
            order.setC_DocType_ID(p_C_DocType_ID);
            order.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            order.setAD_Org_ID(whSource.getAD_Org_ID());
            // Set Org Trx
            MOrg orgTrx = MOrg.get(getCtx(), wh.getAD_Org_ID());
            order.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
            int C_BPartner_ID = orgTrx.getLinkedC_BPartner_ID(get_TrxName());
            if (C_BPartner_ID == 0)
                throw new AdempiereUserError(Msg.translate(getCtx(), "C_BPartner_ID") + " @FillMandatory@ ");
            MBPartner bp = new MBPartner(getCtx(), C_BPartner_ID, get_TrxName());
            // Set BPartner Link to Org
            order.setBPartner(bp);
            order.setDateOrdered(new Timestamp(System.currentTimeMillis()));
            //order.setDatePromised(DatePromised);
            order.setDeliveryRule(MDDOrder.DELIVERYRULE_Availability);
            order.setDeliveryViaRule(MDDOrder.DELIVERYVIARULE_Delivery);
            order.setPriorityRule(MDDOrder.PRIORITYRULE_Medium);
            order.setIsInDispute(false);
            order.setIsApproved(false);
            order.setIsDropShip(false);
            order.setIsDelivered(false);
            order.setIsInTransit(false);
            order.setIsPrinted(false);
            order.setIsSelected(false);
            order.setIsSOTrx(false);
            // Warehouse in Transit
            MWarehouse[] whsInTransit = MWarehouse.getForOrg(getCtx(), whSource.getAD_Org_ID());
            for (MWarehouse whInTransit : whsInTransit) {
                if (whInTransit.isInTransit())
                    order.setM_Warehouse_ID(whInTransit.getM_Warehouse_ID());
            }
            if (order.getM_Warehouse_ID() == 0)
                throw new AdempiereUserError("Warehouse inTransit is @FillMandatory@ ");
            if (!order.save())
                return;
            log.fine(order.toString());
            noMoves++;
            info += " - " + order.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        int M_Locator_ID = whSource.getDefaultLocator().getM_Locator_ID();
        if (M_LocatorTo_ID == 0 || M_Locator_ID == 0)
            throw new AdempiereUserError(Msg.translate(getCtx(), "M_Locator_ID") + " @FillMandatory@ ");
        //	From: Look-up Storage
        /*MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
			MProductCategory pc = MProductCategory.get(getCtx(), product.getM_Product_Category_ID());
			String MMPolicy = pc.getMMPolicy();
			if (MMPolicy == null || MMPolicy.length() == 0)
				MMPolicy = client.getMMPolicy();
			//
			MStorage[] storages = MStorage.getWarehouse(getCtx(), 
				whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0,
				true, null, 
				MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
			
			
			BigDecimal target = replenish.getQtyToOrder();
			for (int j = 0; j < storages.length; j++)
			{
				MStorage storage = storages[j];
				if (storage.getQtyOnHand().signum() <= 0)
					continue;
				BigDecimal moveQty = target;
				if (storage.getQtyOnHand().compareTo(moveQty) < 0)
					moveQty = storage.getQtyOnHand();
				//
				MDDOrderLine line = new MDDOrderLine(order);
				line.setM_Product_ID(replenish.getM_Product_ID());
				line.setQtyEntered(moveQty);
				if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
					line.setDescription("Total: " + replenish.getQtyToOrder());
				line.setM_Locator_ID(storage.getM_Locator_ID());		//	from
				line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
				line.setM_LocatorTo_ID(M_LocatorTo_ID);					//	to
				line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
				line.setIsInvoiced(false);
				line.save();
				//
				target = target.subtract(moveQty);
				if (target.signum() == 0)
					break;
			}*/
        MDDOrderLine line = new MDDOrderLine(order);
        line.setM_Product_ID(replenish.getM_Product_ID());
        line.setQty(replenish.getQtyToOrder());
        if (replenish.getQtyToOrder().compareTo(replenish.getQtyToOrder()) != 0)
            line.setDescription("Total: " + replenish.getQtyToOrder());
        //	from
        line.setM_Locator_ID(M_Locator_ID);
        line.setM_AttributeSetInstance_ID(0);
        //	to
        line.setM_LocatorTo_ID(M_LocatorTo_ID);
        line.setM_AttributeSetInstanceTo_ID(0);
        line.setIsInvoiced(false);
        line.save();
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner) Timestamp(java.sql.Timestamp) MWarehouse(org.compiere.model.MWarehouse) MClient(org.compiere.model.MClient) MDDOrderLine(org.eevolution.model.MDDOrderLine) MOrg(org.compiere.model.MOrg) X_T_Replenish(org.compiere.model.X_T_Replenish) MDDOrder(org.eevolution.model.MDDOrder)

Aggregations

MWarehouse (org.compiere.model.MWarehouse)39 MLocator (org.compiere.model.MLocator)12 BigDecimal (java.math.BigDecimal)9 X_T_Replenish (org.compiere.model.X_T_Replenish)9 MBPartner (org.compiere.model.MBPartner)8 MOrg (org.compiere.model.MOrg)8 Query (org.compiere.model.Query)8 MProduct (org.compiere.model.MProduct)6 MClient (org.compiere.model.MClient)5 AdempiereUserError (org.compiere.util.AdempiereUserError)5 MDDOrder (org.eevolution.model.MDDOrder)5 MDDOrderLine (org.eevolution.model.MDDOrderLine)5 MOrder (org.compiere.model.MOrder)4 MStorage (org.compiere.model.MStorage)4 Properties (java.util.Properties)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MLocation (org.compiere.model.MLocation)3 MMovement (org.compiere.model.MMovement)3 MMovementLine (org.compiere.model.MMovementLine)3 MOrderLine (org.compiere.model.MOrderLine)3