Search in sources :

Example 11 with MMovement

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

the class InventoryUtil method createMovement.

public static MMovement createMovement(MMDocument doc, String trxName) {
    Properties ctx = Env.getCtx();
    int AD_Org_ID = getFirst_Org_ID();
    MProduct product = getCreateProduct(doc);
    MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
    MLocator locatorTo = getCreateLocator(AD_Org_ID, doc.LocatorValueTo, doc.LocatorValueTo);
    //
    MMovement m = new MMovement(ctx, 0, trxName);
    m.setAD_Org_ID(AD_Org_ID);
    m.setMovementDate(doc.Date);
    m.saveEx();
    //
    MMovementLine line = new MMovementLine(m);
    line.setM_Product_ID(product.get_ID());
    line.setM_Locator_ID(locator.get_ID());
    line.setM_LocatorTo_ID(locatorTo.get_ID());
    line.setMovementQty(doc.Qty);
    line.saveEx();
    //
    doc.document = m;
    processDocument(doc, MMovement.DOCACTION_Complete, MMovement.DOCSTATUS_Completed);
    checkLineCosts(doc, line, false);
    return m;
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) Properties(java.util.Properties) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 12 with MMovement

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

the class OrderDistributionReceipt method generate.

//	saveSelection
/**************************************************************************
	 *	Generate Movements
	 */
public String generate(MiniTable miniTable, IStatusBar statusBar, String docActionSelected) {
    String info = "";
    log.info("DD_Order_ID=" + m_DD_Order_ID);
    log.info("MovementDate" + m_MovementDate);
    String trxName = Trx.createTrxName("MVG");
    Trx trx = Trx.get(trxName, true);
    //  prevents from being called twice
    setSelectionActive(false);
    statusBar.setStatusLine(Msg.translate(Env.getCtx(), "M_Movement_ID"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));
    Properties m_ctx = Env.getCtx();
    Timestamp movementDate = (Timestamp) m_MovementDate;
    MDDOrder order = new MDDOrder(m_ctx, Integer.parseInt(m_DD_Order_ID.toString()), trxName);
    MMovement movement = new MMovement(order, movementDate);
    movement.saveEx();
    ArrayList<Integer> ids = getSelection();
    int i = 0;
    for (int DD_OrderLine_ID : ids) {
        MDDOrderLine oline = new MDDOrderLine(m_ctx, DD_OrderLine_ID, trxName);
        MMovementLine line = new MMovementLine(movement);
        line.setM_Product_ID(oline.getM_Product_ID());
        BigDecimal QtyDeliver = (BigDecimal) miniTable.getValueAt(i, 1);
        if (QtyDeliver == null | QtyDeliver.compareTo(oline.getQtyInTransit()) > 0)
            throw new AdempiereException("Error in Qty");
        line.setOrderLine(oline, QtyDeliver, true);
        line.saveEx();
        i++;
    }
    //	Fails if there is a confirmation
    if (!movement.processIt(MMovement.ACTION_Complete))
        log.warning("Failed: " + movement);
    movement.setDocStatus(MMovement.DOCACTION_Complete);
    movement.setDocAction(MMovement.ACTION_Close);
    movement.saveEx();
    return info;
}
Also used : Properties(java.util.Properties) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MDDOrderLine(org.eevolution.model.MDDOrderLine) AdempiereException(org.adempiere.exceptions.AdempiereException) Trx(org.compiere.util.Trx) MDDOrder(org.eevolution.model.MDDOrder) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 13 with MMovement

use of org.compiere.model.MMovement 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 14 with MMovement

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

the class CostResult method createMovement.

public MMovement createMovement(Timestamp documentDate, BigDecimal qty) {
    MMovement move = new MMovement(getCtx(), 0, trxName);
    move.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
    move.setC_DocType_ID((MDocType.getDocType(MDocType.DOCBASETYPE_MaterialMovement)));
    move.setMovementDate(documentDate);
    move.saveEx();
    MMovementLine moveLine = new MMovementLine(getCtx(), 0, trxName);
    moveLine.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
    moveLine.setM_Movement_ID(move.getM_Movement_ID());
    moveLine.setM_Product_ID(product.getM_Product_ID());
    moveLine.setMovementQty(qty);
    // Default HQ Locator
    moveLine.setM_Locator_ID(101);
    // Default Store Locator
    moveLine.setM_LocatorTo_ID(102);
    moveLine.saveEx();
    move.processIt(DocAction.ACTION_Complete);
    move.saveEx();
    return move;
}
Also used : MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 15 with MMovement

use of org.compiere.model.MMovement 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

MMovement (org.compiere.model.MMovement)18 MMovementLine (org.compiere.model.MMovementLine)10 BigDecimal (java.math.BigDecimal)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 Properties (java.util.Properties)4 MProduct (org.compiere.model.MProduct)4 Timestamp (java.sql.Timestamp)3 MLocator (org.compiere.model.MLocator)3 MStorage (org.compiere.model.MStorage)3 MWarehouse (org.compiere.model.MWarehouse)3 MDDOrder (org.eevolution.model.MDDOrder)3 MClient (org.compiere.model.MClient)2 MInOut (org.compiere.model.MInOut)2 MInOutLine (org.compiere.model.MInOutLine)2 MOrder (org.compiere.model.MOrder)2 MOrderLine (org.compiere.model.MOrderLine)2 Query (org.compiere.model.Query)2 X_T_Replenish (org.compiere.model.X_T_Replenish)2 ProcessInfo (org.compiere.process.ProcessInfo)2 Trx (org.compiere.util.Trx)2