Search in sources :

Example 6 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project adempiere by adempiere.

the class PosKeyGenerate method doIt.

/**
	 * Generate keys for each product
	 */
@Override
protected String doIt() throws Exception {
    if (posKeyLayoutId == 0)
        throw new FillMandatoryException("C_POSKeyLayout_ID");
    int count = 0;
    String where = "";
    Object[] params = new Object[] {};
    if (productCategoryId > 0) {
        where = "M_Product_Category_ID = ? ";
        params = new Object[] { productCategoryId };
    }
    Query query = new Query(getCtx(), MProduct.Table_Name, where, get_TrxName()).setParameters(params).setOnlyActiveRecords(true).setOrderBy("Value");
    List<MProduct> products = query.list();
    for (MProduct product : products) {
        MPOSKey key = new MPOSKey(getCtx(), 0, get_TrxName());
        key.setName(product.getName());
        key.setM_Product_ID(product.getM_Product_ID());
        key.setC_POSKeyLayout_ID(posKeyLayoutId);
        key.setSeqNo(count * 10);
        key.setQty(Env.ONE);
        key.saveEx();
        count++;
    }
    return "@Created@ " + count;
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MPOSKey(org.compiere.model.MPOSKey) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 7 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project adempiere by adempiere.

the class PayrollProcessing method doIt.

@Override
protected String doIt() throws Exception {
    if (m_HR_Process_ID <= 0)
        throw new FillMandatoryException(PARAM_HR_Process_ID);
    MHRProcess process = new MHRProcess(getCtx(), m_HR_Process_ID, get_TrxName());
    long start = System.currentTimeMillis();
    boolean ok = process.processIt(MHRProcess.ACTION_Complete);
    process.saveEx();
    if (!ok) {
        throw new AdempiereException(process.getProcessMsg());
    }
    return "@Processed@ " + process.getName() + " - " + (System.currentTimeMillis() - start) + "ms";
}
Also used : MHRProcess(org.eevolution.model.MHRProcess) AdempiereException(org.adempiere.exceptions.AdempiereException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 8 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project adempiere by adempiere.

the class MResourceType method beforeSave.

//	MResourceType
@Override
protected boolean beforeSave(boolean newRecord) {
    if (isTimeSlot()) {
        Timestamp start = getTimeSlotStart();
        if (start == null)
            throw new FillMandatoryException(COLUMNNAME_TimeSlotStart);
        Timestamp end = getTimeSlotEnd();
        if (end == null)
            throw new FillMandatoryException(COLUMNNAME_TimeSlotEnd);
        if (start.compareTo(end) >= 0) {
            throw new AdempiereException("@TimeSlotStart@ > @TimeSlotEnd@");
        }
    }
    return true;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) Timestamp(java.sql.Timestamp)

Example 9 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project adempiere by adempiere.

the class ModelValidator method modelChange_InvoiceLine.

// docValidate
/**
	 * Model Change Invoice Line
	 * @param model model
	 * @param changeType set when called from model validator (See TYPE_*); else -1, when called from callout
	 */
public static void modelChange_InvoiceLine(SetGetModel model, int changeType) {
    // Set Asset Related Fields:
    if (-1 == changeType || TYPE_BEFORE_NEW == changeType || TYPE_BEFORE_CHANGE == changeType) {
        //int invoice_id = SetGetUtil.get_AttrValueAsInt(m, MInvoiceLine.COLUMNNAME_C_Invoice_ID);
        //boolean isSOTrx = DB.isSOTrx(MInvoice.Table_Name, MInvoice.COLUMNNAME_C_Invoice_ID+"="+invoice_id);
        boolean isAsset = false;
        /* comment by @win
			boolean isFixedAsset = false;
			*/
        int assetGroupId = 0;
        //Goodwill - invoice is an Asset type Invoice
        isAsset = SetGetUtil.get_AttrValueAsBoolean(model, MInvoiceLine.COLUMNNAME_A_CreateAsset);
        //@win commenting this out to enable relating AR Invoice to Asset Disposal
        /*
			if (!isSOTrx) {
				int product_id = SetGetUtil.get_AttrValueAsInt(m, MInvoiceLine.COLUMNNAME_M_Product_ID);
				if (product_id > 0) {
					MProduct prod = MProduct.get(m.getCtx(), product_id);
					isAsset = (prod != null && prod.get_ID() > 0 && prod.isCreateAsset());
					assetGroup_ID = prod.getA_Asset_Group_ID();
					
					//isFixedAsset = MAssetType.isFixedAssetGroup(m.getCtx(), assetGroup_ID); //commented by @win - remove asset type
				}
			}
			*/
        int productId = SetGetUtil.get_AttrValueAsInt(model, MInvoiceLine.COLUMNNAME_M_Product_ID);
        if (productId > 0) {
            MProduct product = MProduct.get(model.getCtx(), productId);
            if (product.isCreateAsset()) {
                isAsset = (product != null && product.get_ID() > 0 && product.isCreateAsset());
                assetGroupId = product.getA_Asset_Group_ID();
            } else
                //Goodwill - if the product is not Asset Type
                assetGroupId = SetGetUtil.get_AttrValueAsInt(model, MInvoiceLine.COLUMNNAME_A_Asset_Group_ID);
        }
        // end modification by @win
        model.set_AttrValue(MInvoiceLine.COLUMNNAME_A_CreateAsset, isAsset);
        if (isAsset) {
            model.set_AttrValue(MInvoiceLine.COLUMNNAME_A_Asset_Group_ID, assetGroupId);
            /* comment by @win
				m.set_AttrValue(MInvoiceLine.COLUMNNAME_IsFixedAssetInvoice, isFixedAsset);
				*/
            model.set_AttrValue("IsFixedAssetInvoice", isAsset);
            model.set_AttrValue(MInvoiceLine.COLUMNNAME_A_CreateAsset, "Y");
        } else {
            model.set_AttrValue(MInvoiceLine.COLUMNNAME_A_Asset_Group_ID, null);
            model.set_AttrValue(MInvoiceLine.COLUMNNAME_A_Asset_ID, null);
            model.set_AttrValue("IsFixedAssetInvoice", false);
        }
        // Validate persistent object: 
        if (isAsset && (model instanceof MInvoiceLine)) {
            MInvoiceLine invoiceLine = (MInvoiceLine) model;
            // If is expense, then asset is mandatory
            if (MInvoiceLine.A_CAPVSEXP_Expense.equals(invoiceLine.getA_CapvsExp()) && invoiceLine.getA_Asset_ID() <= 0) {
                throw new FillMandatoryException(MInvoiceLine.COLUMNNAME_A_Asset_ID);
            }
            // Check Amounts & Qty
            if (invoiceLine.getLineNetAmt().signum() == 0) {
                throw new FillMandatoryException(MInvoiceLine.COLUMNNAME_QtyEntered, MInvoiceLine.COLUMNNAME_PriceEntered);
            }
            //
            // Check Product - fixed assets products shouldn't be stocked (but inventory objects are allowed)
            MProduct product = invoiceLine.getProduct();
            if (product.isStocked() && invoiceLine.get_ValueAsBoolean("IsFixedAssetInvoice")) {
                throw new AssetProductStockedException(product);
            }
        }
    }
    // Update Invoice Header:
    if (TYPE_AFTER_NEW == changeType || TYPE_AFTER_CHANGE == changeType || TYPE_AFTER_DELETE == changeType) {
        int invoiceId = SetGetUtil.get_AttrValueAsInt(model, MInvoiceLine.COLUMNNAME_C_Invoice_ID);
        String sql = "UPDATE C_Invoice i SET IsFixedAssetInvoice" + "=(SELECT COALESCE(MAX(il.IsFixedAssetInvoice),'N')" + " FROM C_InvoiceLine il" + " WHERE il.C_Invoice_ID=i.C_Invoice_ID" + " AND il." + MInvoiceLine.COLUMNNAME_IsDescription + "='N'" + ")" + " WHERE C_Invoice_ID=?";
        DB.executeUpdateEx(sql, new Object[] { invoiceId }, model.get_TrxName());
    }
}
Also used : MProduct(org.compiere.model.MProduct) MInvoiceLine(org.compiere.model.MInvoiceLine) AssetProductStockedException(org.compiere.FA.exceptions.AssetProductStockedException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 10 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project adempiere by adempiere.

the class MAssetAddition method prepareIt.

//	invalidateIt
public String prepareIt() {
    if (log.isLoggable(Level.INFO))
        log.info(toString());
    // Call model validators
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
    if (m_processMsg != null) {
        return DocAction.STATUS_Invalid;
    }
    //Goodwill - new asset doctype
    MPeriod.testPeriodOpen(getCtx(), getDateAcct(), "FAA", getAD_Org_ID());
    // Goodwill - setting Create Asset checkbox
    setA_CreateAsset();
    // Check AssetValueAmt != 0
    if (getAssetValueAmt().signum() == 0) {
        m_processMsg = "@Invalid@ @AssetValueAmt@=0";
        return DocAction.STATUS_Invalid;
    }
    MAsset asset = getA_Asset(true);
    MDepreciationWorkfile assetwk = MDepreciationWorkfile.get(getCtx(), getA_Asset_ID(), getPostingType(), get_TrxName());
    // Goodwill - Check asset disposal status
    if (MAsset.A_ASSET_STATUS_Disposed.equals(asset.getA_Asset_Status())) {
        m_processMsg = "Asset aldready disposed";
        return DocAction.STATUS_Invalid;
    }
    // Goodwill - Check if asset already depreciated 
    if (!MAsset.A_ASSET_STATUS_New.equals(asset.getA_Asset_Status()) && assetwk != null && assetwk.getDateAcct() != null && assetwk.isDepreciated(getDateAcct())) {
        m_processMsg = "Asset already depreciated for this period";
        return DocAction.STATUS_Invalid;
    }
    // Goodwill - Validation on Asset Addition Date
    if (getDateDoc().before(asset.getA_Asset_CreateDate())) {
        throw new AssetCheckDocumentException("Document is date older than Asset Create Date");
    } else if (asset.getAssetServiceDate() != null && getDateDoc().before(asset.getAssetServiceDate())) {
        throw new AssetCheckDocumentException("Document is date older than Asset Service Date");
    }
    // If new assets (not renewals) must have nonzero values
    if (isA_CreateAsset() && hasZeroValues()) {
        throw new AssetException("New document must have non-zero values");
    }
    // Goodwill - can add asset value without adding asset usable life
    if (!isA_CreateAsset() && getDeltaUseLifeYears() < 0) {
        throw new AssetException("Delta Use Life Years cannot be negative values");
    }
    // Goodwill - Validation on Depreciated Asset
    if (MAsset.A_ASSET_STATUS_Depreciated.equals(asset.getA_Asset_Status())) {
        throw new AssetException("Asset is fully depreciated");
    }
    // Only New assets can be activated
    if (isA_CreateAsset() && !MAsset.A_ASSET_STATUS_New.equals(asset.getA_Asset_Status())) {
        throw new AssetException("Only new assets can be activated");
    }
    // Validate Source - Invoice
    if (A_SOURCETYPE_Invoice.equals(getA_SourceType())) {
        int C_Invoice_ID = getC_Invoice_ID();
        MInvoice invoice = new MInvoice(getCtx(), C_Invoice_ID, get_TrxName());
        if (MInvoice.DOCSTATUS_Voided.equals(invoice.getDocStatus())) {
            throw new AssetException("You cannot add asset from voided document(s)");
        }
    }
    // Validate Source - Project
    if (A_SOURCETYPE_Project.equals(getA_SourceType())) {
        if (getC_Project_ID() <= 0) {
            throw new FillMandatoryException(COLUMNNAME_C_Project_ID);
        }
        final String whereClause = COLUMNNAME_C_Project_ID + "=?" + " AND DocStatus IN ('IP','CO','CL')" + " AND " + COLUMNNAME_A_Asset_Addition_ID + "<>?";
        List<MAssetAddition> list = new Query(getCtx(), Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { getC_Project_ID(), get_ID() }).list();
        if (list.size() > 0) {
            StringBuilder sb = new StringBuilder("You can not create project for this asset," + " Project already has assets. View: ");
            for (MAssetAddition aa : list) {
                sb.append(aa.getDocumentInfo()).append("; ");
            }
            throw new AssetException(sb.toString());
        }
    }
    // Call model validators
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
    if (m_processMsg != null) {
        return DocAction.STATUS_Invalid;
    }
    //	Done
    m_justPrepared = true;
    if (!DOCACTION_Complete.equals(getDocAction()))
        setDocAction(DOCACTION_Complete);
    return DocAction.STATUS_InProgress;
}
Also used : AssetCheckDocumentException(org.compiere.FA.exceptions.AssetCheckDocumentException) AssetException(org.compiere.FA.exceptions.AssetException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Aggregations

FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)12 AdempiereException (org.adempiere.exceptions.AdempiereException)6 MProduct (org.compiere.model.MProduct)4 Timestamp (java.sql.Timestamp)3 MInvoiceLine (org.compiere.model.MInvoiceLine)2 Query (org.compiere.model.Query)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 InvoiceFullyMatchedException (org.adempiere.exceptions.InvoiceFullyMatchedException)1 AssetCheckDocumentException (org.compiere.FA.exceptions.AssetCheckDocumentException)1 AssetException (org.compiere.FA.exceptions.AssetException)1 AssetProductStockedException (org.compiere.FA.exceptions.AssetProductStockedException)1 MBPartner (org.compiere.model.MBPartner)1 MBPartnerLocation (org.compiere.model.MBPartnerLocation)1 MDepreciationExp (org.compiere.model.MDepreciationExp)1 MInvoice (org.compiere.model.MInvoice)1 MLocation (org.compiere.model.MLocation)1 MOpportunity (org.compiere.model.MOpportunity)1 MPOSKey (org.compiere.model.MPOSKey)1