Search in sources :

Example 1 with MMovement

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

the class CostResult method createBusinessCaseTest.

/**
	 * create Business Test Case
	 * @param trxName
	 */
void createBusinessCaseTest(String trxName) {
    createDataMaster();
    generateHistoryCost();
    Timestamp dateAcct;
    //First Purchase Receipt 
    dateAcct = today;
    MOrder purchase1 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(36));
    MInOut receipt1 = null;
    for (MOrderLine line : purchase1.getLines()) {
        receipt1 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt1.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("47.7292"), // cumulateQty
        new BigDecimal("30"), //cumulateAmt
        new BigDecimal("1431.8748"), //cdAmt
        new BigDecimal("477.2920"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("53.5937"), //cdCumulateQty
        new BigDecimal("20"), //cdCumulateAmt
        new BigDecimal("1071.8748"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Create Sales Order Order Credit by 5
    dateAcct = TimeUtil.addDays(today, 15);
    MOrder sales1 = createSalesOrder(dateAcct, new BigDecimal(5), new BigDecimal(45));
    for (MOrderLine line : sales1.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("47.7292"), new BigDecimal("25"), new BigDecimal("1193.2288"), new BigDecimal("238.6460"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("47.7292"), new BigDecimal("30"), new BigDecimal("1431.8748"), dateAcct);
        assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    //Second Purchase Receipt 7 day forward
    dateAcct = TimeUtil.addDays(today, 31);
    MOrder purchase2 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(34));
    MInOut receipt2 = null;
    for (MOrderLine line : purchase2.getLines()) {
        receipt2 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt2.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("43.8065"), // cumulateQty
        new BigDecimal("35"), //cumulateAmt
        new BigDecimal("1533.2288"), //cdAmt
        new BigDecimal("438.0650"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("47.7292"), //cdCumulateQty
        new BigDecimal("25"), //cdCumulateAmt
        new BigDecimal("1193.2288"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Create Sales Order Order Credit by 5
    dateAcct = TimeUtil.addDays(today, 60);
    MOrder sales2 = createSalesOrder(dateAcct, new BigDecimal(10), new BigDecimal(45));
    for (MOrderLine line : sales2.getLines()) {
        CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("43.8065"), new BigDecimal("25"), new BigDecimal("1095.1638"), new BigDecimal("438.0650"), new BigDecimal("0"), new BigDecimal("-10"), new BigDecimal("43.8065"), new BigDecimal("35"), new BigDecimal("1533.2288"), dateAcct);
        assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    dateAcct = receipt1.getDateAcct();
    int M_InOutLine_ID = 0;
    for (MInOutLine line : receipt1.getLines()) {
        M_InOutLine_ID = line.getM_InOutLine_ID();
        MInvoice invoice = createInvoiceVendor(dateAcct, new BigDecimal(10), new BigDecimal(38), line.getM_InOutLine_ID());
    }
    CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
    new BigDecimal("44.2827"), // cumulateQty
    new BigDecimal("25"), //cumulateAmt
    new BigDecimal("1107.0688"), //cdAmt
    new BigDecimal("380.0000"), //cdAdjutment
    new BigDecimal("20.0000"), //cdQty
    new BigDecimal("10"), //cdCurrentCostPrice
    new BigDecimal("53.5937"), //cdCumulateQty
    new BigDecimal("20"), //cdCumulateAmt
    new BigDecimal("1071.8748"), dateAcct);
    assertCostInvoice(costResult, M_InOutLine_ID, as, trxName);
    dateAcct = Timestamp.valueOf("2010-01-16 00:00:00.0");
    for (MOrderLine line : sales1.getLines()) {
        costResult = new CostResult(line.getM_Product_ID(), new BigDecimal("44.2827"), new BigDecimal("25"), new BigDecimal("1107.0688"), new BigDecimal("241.9790"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("48.3958"), new BigDecimal("30"), new BigDecimal("1451.8748"), dateAcct);
        assertCostShipmentAdjust(costResult, line.getC_OrderLine_ID(), as, trxName);
    }
    //Reverse Material Receipt		
    dateAcct = today;
    receipt1.processIt(DocAction.ACTION_Reverse_Correct);
    receipt1.saveEx();
    for (MInOutLine line : receipt1.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("44.2827"), // cumulateQty
        new BigDecimal("25"), //cumulateAmt
        new BigDecimal("1107.0688"), //cdAmt
        new BigDecimal("380.0000"), //cdAdjutment
        new BigDecimal("20.0000"), //cdQty
        new BigDecimal("10"), //cdCurrentCostPrice
        new BigDecimal("53.5937"), //cdCumulateQty
        new BigDecimal("20"), //cdCumulateAmt
        new BigDecimal("1071.8748"), dateAcct);
        assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    MInOut reversal = new MInOut(getCtx(), receipt1.getReversal_ID(), trxName);
    for (MInOutLine line : reversal.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("46.8373"), // cumulateQty
        new BigDecimal("19"), //cumulateAmt
        new BigDecimal("889.9081"), //cdAmt
        new BigDecimal("380"), //cdAdjutment
        new BigDecimal("20"), //cdQty
        new BigDecimal("-10"), //cdCurrentCostPrice
        new BigDecimal("49.0073"), //cdCumulateQty
        new BigDecimal("34"), //cdCumulateAmt
        new BigDecimal("1666.2496"), dateAcct);
        assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    //Second Purchase Receipt 7 day forward
    dateAcct = TimeUtil.addDays(today, 7);
    MOrder purchase3 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(37));
    MInOut receipt3 = null;
    for (MOrderLine line : purchase3.getLines()) {
        receipt3 = createMaterialReceipt(dateAcct, new BigDecimal(20), line.getC_OrderLine_ID());
    }
    for (MInOutLine line : receipt3.getLines()) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0489"), // cumulateQty
        new BigDecimal("45"), //cumulateAmt
        new BigDecimal("1892.1983"), //cdAmt
        new BigDecimal("876.7500"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("20"), //cdCurrentCostPrice
        new BigDecimal("48.3958"), //cdCumulateQty
        new BigDecimal("30"), //cdCumulateAmt
        new BigDecimal("1451.8748"), dateAcct);
        assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
    }
    dateAcct = TimeUtil.addDays(today, 65);
    MMovement move = createMovement(dateAcct, new BigDecimal("5"));
    for (MMovementLine line : move.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("53.5938"), // cumulateQty
        new BigDecimal("9"), //cumulateAmt
        new BigDecimal("482.3442"), //cdAmt
        new BigDecimal("267.9690"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("5"), //cdCurrentCostPrice
        new BigDecimal("53.5938"), //cdCumulateQty
        new BigDecimal("4"), //cdCumulateAmt
        new BigDecimal("214.3752"), dateAcct);
        assertCostMovement(costResult, line.getM_MovementLine_ID(), as, trxName);
    }
    dateAcct = TimeUtil.addDays(today, 70);
    MInventory inventory = createPhisicalInventory(dateAcct, new BigDecimal("20"), costResult.cumulateQty);
    for (MInventoryLine line : inventory.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0488"), // cumulateQty
        new BigDecimal("51"), //cumulateAmt
        new BigDecimal("2144.4906"), //cdAmt
        new BigDecimal("462.5368"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("11"), //cdCurrentCostPrice
        new BigDecimal("42.0488"), //cdCumulateQty
        new BigDecimal("40"), //cdCumulateAmt
        new BigDecimal("1681.9538"), dateAcct);
        assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
        break;
    }
    dateAcct = TimeUtil.addDays(today, 80);
    inventory = createInvetoryInternalUse(dateAcct, new BigDecimal("-5"));
    for (MInventoryLine line : inventory.getLines(true)) {
        costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
        new BigDecimal("42.0488"), // cumulateQty
        new BigDecimal("56"), //cumulateAmt
        new BigDecimal("2354.7346"), //cdAmt
        new BigDecimal("210.2440"), //cdAdjutment
        new BigDecimal("0"), //cdQty
        new BigDecimal("5"), //cdCurrentCostPrice
        new BigDecimal("42.0488"), //cdCumulateQty
        new BigDecimal("51"), //cdCumulateAmt
        new BigDecimal("2144.4906"), dateAcct);
        assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
        ;
    }
    createTrxAndInventoryValuationReport();
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MInvoice(org.compiere.model.MInvoice) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) MInventory(org.compiere.model.MInventory) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement)

Example 2 with MMovement

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

the class GenerateShipmentOutBound method processingMovements.

public void processingMovements() {
    distributionOrders.entrySet().stream().forEach(entry -> {
        I_DD_Order distributionOrder = entry.getValue();
        List<Integer> orderIds = new ArrayList<Integer>();
        orderIds.add(distributionOrder.getDD_Order_ID());
        ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(MovementGenerate.getProcessId()).withSelectedRecordsIds(orderIds).withParameter(MWMInOutBound.COLUMNNAME_M_Warehouse_ID, distributionOrder.getM_Warehouse_ID()).withParameter(MMovement.COLUMNNAME_MovementDate, getMovementDate()).withoutTransactionClose().execute(get_TrxName());
        if (processInfo.isError())
            throw new AdempiereException(processInfo.getSummary());
        addLog(processInfo.getSummary());
        Arrays.stream(processInfo.getIDs()).forEach(recordId -> {
            MMovement movement = new MMovement(getCtx(), recordId, get_TrxName());
            if (movement != null && movement.get_ID() > 0)
                GenerateMovement.printDocument(movement, "Inventory Move Hdr (Example)", processInfo.getWindowNo());
            else
                throw new AdempiereException("@M_Movement_ID@ @NotFound@");
        });
    });
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) I_DD_Order(org.eevolution.model.I_DD_Order) MMovement(org.compiere.model.MMovement)

Example 3 with MMovement

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

the class ReplenishReport 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");
    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.saveEx();
            //
            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 4 with MMovement

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

the class StorageCleanup method move.

//	doIt
/**
	 * 	Move stock to location
	 *	@param target target storage
	 *	@return no of movements
	 */
private int move(MStorage target) {
    log.info(target.toString());
    BigDecimal qty = target.getQtyOnHand().negate();
    MMovement mh = null;
    MStorage[] sources = getSources(target.getM_Product_ID(), target.getM_Locator_ID());
    if (sources.length > 0) {
        //	Create Movement
        mh = new MMovement(getCtx(), 0, get_TrxName());
        mh.setAD_Org_ID(target.getAD_Org_ID());
        mh.setC_DocType_ID(p_C_DocType_ID);
        mh.setDescription(getName());
        if (!mh.save())
            return 0;
    } else {
        // No available sources
        return 0;
    }
    int lines = 0;
    for (int i = 0; i < sources.length; i++) {
        MStorage source = sources[i];
        //	Movement Line
        MMovementLine ml = new MMovementLine(mh);
        ml.setM_Product_ID(target.getM_Product_ID());
        ml.setM_LocatorTo_ID(target.getM_Locator_ID());
        ml.setM_AttributeSetInstanceTo_ID(target.getM_AttributeSetInstance_ID());
        //	From
        ml.setM_Locator_ID(source.getM_Locator_ID());
        ml.setM_AttributeSetInstance_ID(source.getM_AttributeSetInstance_ID());
        BigDecimal qtyMove = qty;
        if (qtyMove.compareTo(source.getQtyOnHand()) > 0)
            qtyMove = source.getQtyOnHand();
        ml.setMovementQty(qtyMove);
        //
        lines++;
        ml.setLine(lines * 10);
        if (!ml.save())
            return 0;
        qty = qty.subtract(qtyMove);
        if (qty.signum() <= 0)
            break;
    }
    //	for all movements
    //	Process
    mh.processIt(MMovement.ACTION_Complete);
    mh.saveEx();
    addLog(0, null, new BigDecimal(lines), "@M_Movement_ID@ " + mh.getDocumentNo() + " (" + MRefList.get(getCtx(), MMovement.DOCSTATUS_AD_Reference_ID, mh.getDocStatus(), get_TrxName()) + ")");
    eliminateReservation(target);
    return lines;
}
Also used : MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal)

Example 5 with MMovement

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

the class GenerateMovement method doIt.

//	prepare
/**
     * Generate Movements
     * @return info
     * @throws Exception
     */
protected String doIt() throws Exception {
    ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(MovementGenerate.getProcessId()).withTitle(GenerateMovement.getProcessName()).withRecordId(MDDOrder.Table_ID, 0).withSelectedRecordsIds(getSelectionKeys()).withParameter(MMovement.COLUMNNAME_MovementDate, getMovementDate()).withParameter(MMovement.COLUMNNAME_DocAction, DocAction.ACTION_Complete).execute();
    if (processInfo.isError())
        throw new AdempiereException(processInfo.getSummary());
    result = processInfo.getSummary();
    int[] movementProcessedIds = processInfo.getIDs();
    if (movementProcessedIds != null && movementProcessedIds.length > 0) {
        Arrays.stream(movementProcessedIds).filter(movementId -> movementId > 0).forEach(movementId -> {
            MMovement movement = new MMovement(getCtx(), movementId, null);
            StringBuffer resultText = new StringBuffer(Msg.translate(Env.getCtx(), "DocumentNo") + " : " + movement.getDocumentNo());
            result = result == null ? " " + resultText.toString() : result + " " + resultText.toString();
            printDocument(movement, "Inventory Move Hdr (Example)", processInfo.getWindowNo());
        });
    }
    return result;
}
Also used : Arrays(java.util.Arrays) MDDOrder(org.eevolution.model.MDDOrder) Env(org.compiere.util.Env) ProcessBuilder(org.eevolution.service.dsl.ProcessBuilder) Constructor(java.lang.reflect.Constructor) Ini(org.compiere.util.Ini) AdempiereException(org.adempiere.exceptions.AdempiereException) Msg(org.compiere.util.Msg) MMovement(org.compiere.model.MMovement) ProcessInfo(org.compiere.process.ProcessInfo) DocAction(org.compiere.process.DocAction) PO(org.compiere.model.PO) IPrintDocument(org.eevolution.form.IPrintDocument) AdempiereException(org.adempiere.exceptions.AdempiereException) ProcessInfo(org.compiere.process.ProcessInfo) 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