Search in sources :

Example 41 with MInOutLine

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

the class CostResult method createMaterialReceipt.

public MInOut createMaterialReceipt(Timestamp movementDate, BigDecimal qtyMovement, int C_OrderLine_ID) {
    // Create Material Receipt
    MInOut receipt = new MInOut(getCtx(), 0, trxName);
    receipt.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
    receipt.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_MaterialReceipt));
    receipt.setC_BPartner_ID(bp.getC_BPartner_ID());
    receipt.setC_BPartner_Location_ID(bpls[0].getC_BPartner_Location_ID());
    receipt.setMovementDate(movementDate);
    receipt.setDateAcct(movementDate);
    receipt.setIsSOTrx(false);
    receipt.setM_Warehouse_ID(w.getM_Warehouse_ID());
    receipt.setMovementType(MInOut.MOVEMENTTYPE_VendorReceipts);
    receipt.saveEx();
    // Create Material Receipt Line
    MInOutLine receiptLine = new MInOutLine(receipt);
    receiptLine.setC_OrderLine_ID(C_OrderLine_ID);
    receiptLine.setM_Product_ID(product.getM_Product_ID());
    receiptLine.setMovementQty(qtyMovement);
    receiptLine.setM_Locator_ID(qtyMovement);
    receiptLine.saveEx();
    // Complete Receipt
    receipt.setDocStatus(DocAction.STATUS_Drafted);
    receipt.setDocAction(DocAction.ACTION_Complete);
    receipt.processIt(DocAction.ACTION_Complete);
    receipt.saveEx();
    return receipt;
}
Also used : MInOut(org.compiere.model.MInOut) MInOutLine(org.compiere.model.MInOutLine)

Example 42 with MInOutLine

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

the class ModelValidator method docValidate.

public String docValidate(PO po, int timing) {
    log.info(po.get_TableName() + " Timing: " + timing);
    String result = null;
    // TABLE C_Invoice
    String tableName = po.get_TableName();
    if (tableName.equals(MInvoice.Table_Name)) {
        // Invoice - Validate Fixed Assets Invoice (LRO)
        if (timing == TIMING_AFTER_PREPARE) {
            MInvoice invoice = (MInvoice) po;
            validateFixedAssetsInvoice_LRO(invoice);
        }
        if (timing == TIMING_AFTER_COMPLETE) {
            MInvoice mi = (MInvoice) po;
            if (mi.isSOTrx()) {
                MInvoiceLine[] mils = mi.getLines();
                for (MInvoiceLine mil : mils) {
                    if (mil.isA_CreateAsset() && !mil.isA_Processed()) {
                        MAssetDisposed.createAssetDisposed(mil);
                    }
                }
            }
        }
        if (timing == TIMING_AFTER_VOID) {
            MInvoice invoice = (MInvoice) po;
            String error = afterVoid(invoice);
            if (error != null)
                return error;
        }
        if (timing == TIMING_BEFORE_REVERSECORRECT) {
            MInvoice invoice = (MInvoice) po;
            String error = beforeReverseCorrect(invoice);
            if (error != null)
                return error;
        }
    }
    if (tableName.equals(MInOut.Table_Name)) {
        if (timing == TIMING_AFTER_COMPLETE) {
            MInOut inOut = (MInOut) po;
            for (MInOutLine inOutLine : inOut.getLines()) {
                MProduct product = inOutLine.getProduct();
                //	Create Asset for SO
                if (product != null && inOut.isSOTrx() && product.isCreateAsset() && !product.getM_Product_Category().getA_Asset_Group().isFixedAsset() && inOutLine.getMovementQty().signum() > 0 && !inOut.isReversal()) {
                    log.fine("Asset");
                    //info.append("@A_Asset_ID@: ");
                    int noAssets = inOutLine.getMovementQty().intValue();
                    if (!product.isOneAssetPerUOM())
                        noAssets = 1;
                    for (int i = 0; i < noAssets; i++) {
                        //if (i > 0)
                        //	info.append(" - ");
                        int deliveryCount = i + 1;
                        if (!product.isOneAssetPerUOM())
                            deliveryCount = 0;
                        MAsset asset = new MAsset(inOut, inOutLine, deliveryCount);
                        if (!asset.save(inOut.get_TrxName())) {
                            //return DocAction.STATUS_Invalid;
                            throw new IllegalStateException("Could not create Asset");
                        }
                    //info.append(asset.getValue());
                    }
                }
            }
        //	Asset
        }
        if (timing == TIMING_AFTER_REVERSECORRECT) {
            MInOut inOut = (MInOut) po;
            I_M_InOut inOutReversal = inOut.getReversal();
            for (MInOutLine inOutLine : inOut.getLines()) {
                //	De-Activate Asset
                MAsset asset = MAsset.getFromShipment(inOut.getCtx(), inOutLine.getM_InOutLine_ID(), inOut.get_TrxName());
                if (asset != null) {
                    asset.setIsActive(false);
                    asset.setDescription(asset.getDescription() + " (" + inOutReversal.getDocumentNo() + " #" + inOutLine.getLine() + "<-)");
                    asset.saveEx();
                }
            }
        }
    }
    return result;
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) I_M_InOut(org.compiere.model.I_M_InOut) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MAsset(org.compiere.model.MAsset)

Aggregations

MInOutLine (org.compiere.model.MInOutLine)42 MInOut (org.compiere.model.MInOut)22 BigDecimal (java.math.BigDecimal)19 MOrderLine (org.compiere.model.MOrderLine)15 MInvoiceLine (org.compiere.model.MInvoiceLine)10 MProduct (org.compiere.model.MProduct)10 MMatchPO (org.compiere.model.MMatchPO)9 MInvoice (org.compiere.model.MInvoice)8 MOrder (org.compiere.model.MOrder)8 MMatchInv (org.compiere.model.MMatchInv)7 MInventoryLine (org.compiere.model.MInventoryLine)6 MMovementLine (org.compiere.model.MMovementLine)6 MRMALine (org.compiere.model.MRMALine)6 MTransaction (org.compiere.model.MTransaction)6 ArrayList (java.util.ArrayList)5 MLandedCostAllocation (org.compiere.model.MLandedCostAllocation)5 MStorage (org.compiere.model.MStorage)5 AdempiereException (org.adempiere.exceptions.AdempiereException)4 MCostElement (org.compiere.model.MCostElement)4 MCostType (org.compiere.model.MCostType)4