Search in sources :

Example 36 with MWarehouse

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

the class DistributionRunOrders method groovy.

public String groovy(String A_TrxName, Properties A_Ctx, int P_M_Warehouse_ID, int P_M_PriceList_Version_ID, int P_M_DistributionList_ID) {
    MPriceListVersion plv = new MPriceListVersion(A_Ctx, P_M_PriceList_Version_ID, A_TrxName);
    MPriceList pl = new MPriceList(A_Ctx, plv.getM_PriceList_ID(), A_TrxName);
    MWarehouse w = new MWarehouse(A_Ctx, P_M_Warehouse_ID, A_TrxName);
    MDistributionRun dr = new MDistributionRun(A_Ctx, 0, A_TrxName);
    dr.setName(plv.getName());
    dr.setIsActive(true);
    dr.setAD_Org_ID(w.getAD_Org_ID());
    dr.saveEx();
    MProductPrice[] products = plv.getProductPrice(true);
    int seq = 10;
    for (MProductPrice pp : products) {
        int M_Product_ID = pp.getM_Product_ID();
        BigDecimal QtyAvailable = MStorage.getQtyAvailable(P_M_Warehouse_ID, M_Product_ID, 0, 0, A_TrxName);
        BigDecimal QtyOnHand = MPPMRP.getQtyOnHand(A_Ctx, P_M_Warehouse_ID, M_Product_ID, A_TrxName);
        MDistributionRunLine drl = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
        drl.setM_DistributionRun_ID(dr.get_ID());
        drl.setLine(seq);
        drl.setM_Product_ID(M_Product_ID);
        drl.setM_DistributionList_ID(P_M_DistributionList_ID);
        drl.setDescription(Msg.translate(A_Ctx, "QtyAvailable") + " = " + QtyAvailable + " | " + Msg.translate(A_Ctx, "QtyOnHand") + " = " + QtyOnHand);
        drl.setTotalQty(QtyAvailable);
        drl.saveEx();
    }
    return "";
}
Also used : MDistributionRun(org.compiere.model.MDistributionRun) MDistributionRunLine(org.compiere.model.MDistributionRunLine) MPriceListVersion(org.compiere.model.MPriceListVersion) MPriceList(org.compiere.model.MPriceList) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MProductPrice(org.compiere.model.MProductPrice)

Example 37 with MWarehouse

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

the class WLocatorEditor method setDefault_Locator_ID.

// getOnly_Product_ID
/**
	 * Set the default locator if this field is mandatory 
	 * and we have a warehouse restriction.
	 * 
	 * @since 3.1.4
	 */
private void setDefault_Locator_ID() {
    if (!isMandatory() || m_mLocator == null) {
        return;
    }
    int M_Warehouse_ID = getOnly_Warehouse_ID();
    if (M_Warehouse_ID <= 0) {
        return;
    }
    MWarehouse wh = MWarehouse.get(Env.getCtx(), M_Warehouse_ID);
    if (wh == null || wh.get_ID() <= 0) {
        return;
    }
    MLocator loc = wh.getDefaultLocator();
    if (loc == null || loc.get_ID() <= 0) {
        return;
    }
    setValue(Integer.valueOf(loc.get_ID()));
}
Also used : MLocator(org.compiere.model.MLocator) MWarehouse(org.compiere.model.MWarehouse)

Example 38 with MWarehouse

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

the class ValuationEffectiveDate method doIt.

// prepare
/**
	 * execute the Valuation Effective Date
	 */
protected String doIt() throws Exception {
    setup();
    for (MAcctSchema acctSchema : acctSchemas) for (MWarehouse warehouse : warehouses) for (MCostType costType : costTypes) for (MCostElement costElement : costElements) for (int productId : products) generateInventoryValue(productId, acctSchema.getC_AcctSchema_ID(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), warehouse.getM_Warehouse_ID());
    pstmt.executeBatch();
    commitEx();
    DB.close(pstmt);
    DB.executeUpdate("UPDATE T_InventoryValue SET Cost = CASE WHEN QtyOnHand <> 0 THEN (CostAmt + CostAmtLL) / QtyOnHand ELSE  0 END  ,  CumulatedAmt = CASE WHEN QtyOnHand <> 0  THEN  CostAmt + CostAmtLL ELSE 0 END ,  DateValue = " + DB.TO_DATE(getValuationDate()) + " WHERE AD_PInstance_ID=?", getAD_PInstance_ID(), get_TrxName());
    return "@Ok@ " + count;
}
Also used : MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MCostType(org.compiere.model.MCostType) MWarehouse(org.compiere.model.MWarehouse)

Example 39 with MWarehouse

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

the class LiberoValidator method docValidate.

//	modelChange
public String docValidate(PO po, int timing) {
    log.info(po.get_TableName() + " Timing: " + timing);
    if (po instanceof MOrder && timing == TIMING_BEFORE_COMPLETE) {
        MOrder order = (MOrder) po;
        MPPMRP.C_Order(order);
    }
    if (po instanceof MInOut && timing == TIMING_AFTER_COMPLETE) {
        MInOut inout = (MInOut) po;
        if (inout.isSOTrx()) {
            for (MInOutLine outline : inout.getLines()) {
                updateMPPOrder(outline);
            }
        } else //Purchase Receipt
        {
            for (MInOutLine line : inout.getLines()) {
                final String whereClause = "C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL";
                Collection<MOrderLine> olines = new Query(po.getCtx(), MOrderLine.Table_Name, whereClause, po.get_TrxName()).setParameters(new Object[] { line.getC_OrderLine_ID() }).list();
                for (MOrderLine oline : olines) {
                    if (oline.getQtyOrdered().compareTo(oline.getQtyDelivered()) >= 0) {
                        MPPCostCollector cc = new MPPCostCollector(po.getCtx(), oline.getPP_Cost_Collector_ID(), po.get_TrxName());
                        String docStatus = cc.completeIt();
                        cc.setDocStatus(docStatus);
                        cc.setDocAction(MPPCostCollector.DOCACTION_Close);
                        cc.saveEx();
                        return null;
                    }
                }
            }
        }
    } else // Update Distribution Order Line
    if (po instanceof MMovement && timing == TIMING_AFTER_COMPLETE) {
        MMovement move = (MMovement) po;
        for (MMovementLine line : move.getLines(false)) {
            if (line.getDD_OrderLine_ID() > 0) {
                MDDOrderLine oline = new MDDOrderLine(line.getCtx(), line.getDD_OrderLine_ID(), po.get_TrxName());
                MLocator locator_to = MLocator.get(line.getCtx(), line.getM_LocatorTo_ID());
                MWarehouse warehouse = MWarehouse.get(line.getCtx(), locator_to.getM_Warehouse_ID());
                if (warehouse.isInTransit()) {
                    oline.setQtyInTransit(oline.getQtyInTransit().add(line.getMovementQty()));
                    oline.setConfirmedQty(Env.ZERO);
                } else {
                    oline.setQtyInTransit(oline.getQtyInTransit().subtract(line.getMovementQty()));
                    oline.setQtyDelivered(oline.getQtyDelivered().add(line.getMovementQty()));
                }
                oline.saveEx();
            }
        }
        if (move.getDD_Order_ID() > 0) {
            MDDOrder order = new MDDOrder(move.getCtx(), move.getDD_Order_ID(), move.get_TrxName());
            order.setIsInTransit(isInTransting(order));
            order.reserveStock(order.getLines(true, null));
            order.saveEx();
        }
    }
    return null;
}
Also used : MInOut(org.compiere.model.MInOut) Query(org.compiere.model.Query) MInOutLine(org.compiere.model.MInOutLine) MWarehouse(org.compiere.model.MWarehouse) MOrder(org.compiere.model.MOrder) MLocator(org.compiere.model.MLocator) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

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