Search in sources :

Example 1 with I_M_InOut

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

I_M_InOut (org.compiere.model.I_M_InOut)1 MAsset (org.compiere.model.MAsset)1 MInOut (org.compiere.model.MInOut)1 MInOutLine (org.compiere.model.MInOutLine)1 MInvoice (org.compiere.model.MInvoice)1 MInvoiceLine (org.compiere.model.MInvoiceLine)1 MProduct (org.compiere.model.MProduct)1