Search in sources :

Example 1 with FillMandatoryException

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

the class ConvertLead method doIt.

@Override
protected String doIt() throws Exception {
    if (p_AD_User_ID <= 0)
        throw new FillMandatoryException("AD_User_ID");
    MUser lead = new MUser(getCtx(), p_AD_User_ID, get_TrxName());
    if (!lead.isSalesLead() || lead.getC_BPartner_ID() != 0)
        throw new AdempiereUserError("Lead already converted");
    MBPartner bp = MBPartner.getTemplate(getCtx(), getAD_Client_ID());
    bp.set_TrxName(get_TrxName());
    if (!Util.isEmpty(lead.getBPName()))
        bp.setName(lead.getBPName());
    else
        bp.setName(lead.getName());
    bp.saveEx();
    addLog("Business Partner created.");
    lead.setC_BPartner_ID(bp.getC_BPartner_ID());
    if (lead.getC_Location_ID() != 0) {
        MLocation leadAddress = (MLocation) lead.getC_Location();
        MBPartnerLocation loc = new MBPartnerLocation(bp);
        MLocation address = new MLocation(getCtx(), 0, get_TrxName());
        PO.copyValues(leadAddress, address);
        address.saveEx();
        loc.setC_Location_ID(address.getC_Location_ID());
        loc.setPhone(lead.getPhone());
        loc.setPhone2(lead.getPhone2());
        loc.setFax(lead.getFax());
        loc.saveEx();
        lead.setC_BPartner_Location_ID(loc.getC_BPartner_Location_ID());
        addLog("Contact Location added.");
    }
    // company address
    if (lead.getBP_Location_ID() != 0) {
        MLocation leadAddress = (MLocation) lead.getBP_Location();
        MBPartnerLocation loc = new MBPartnerLocation(bp);
        MLocation address = new MLocation(getCtx(), 0, get_TrxName());
        PO.copyValues(leadAddress, address);
        address.saveEx();
        loc.setC_Location_ID(address.getC_Location_ID());
        loc.saveEx();
        addLog("BP Address added.");
    }
    if (p_createOpportunity) {
        MOpportunity op = new MOpportunity(getCtx(), 0, get_TrxName());
        op.setAD_User_ID(lead.getAD_User_ID());
        op.setC_BPartner_ID(bp.getC_BPartner_ID());
        op.setExpectedCloseDate(p_expectedCloseDate != null ? p_expectedCloseDate : new Timestamp(System.currentTimeMillis()));
        op.setOpportunityAmt(p_opportunityAmt != null ? p_opportunityAmt : Env.ZERO);
        if (p_C_SalesStage_ID > 0)
            op.setC_SalesStage_ID(p_C_SalesStage_ID);
        String sql = "SELECT Probability FROM C_SalesStage WHERE C_SalesStage_ID = ?";
        BigDecimal probability = DB.getSQLValueBD(get_TrxName(), sql, p_C_SalesStage_ID);
        op.setProbability(probability != null ? probability : Env.ZERO);
        op.setDescription(p_Description);
        if (p_C_Currency_ID > 0)
            op.setC_Currency_ID(p_C_Currency_ID);
        else
            op.setC_Currency_ID(Env.getContextAsInt(getCtx(), "$C_Currency_ID"));
        if (p_SalesRep_ID > 0)
            op.setSalesRep_ID(p_SalesRep_ID);
        else if (lead.getSalesRep_ID() > 0)
            op.setSalesRep_ID(lead.getSalesRep_ID());
        else
            op.setSalesRep_ID(Env.getContextAsInt(getCtx(), "#SalesRep_ID"));
        op.setC_Campaign_ID(lead.getC_Campaign_ID());
        op.saveEx();
        addLog("Opportunity created.");
    }
    lead.setIsSalesLead(false);
    lead.setLeadStatus(MUser.LEADSTATUS_Converted);
    lead.saveEx();
    addLog("Lead converted.");
    return "@OK@";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MOpportunity(org.compiere.model.MOpportunity) MBPartner(org.compiere.model.MBPartner) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 2 with FillMandatoryException

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

the class MIFixedAsset method getCreateProduct.

//	MIFixedAsset
/**	Create / Load product
	 *	@return product
	 */
public MProduct getCreateProduct() {
    Properties ctx = getCtx();
    String trxName = get_TrxName();
    int M_Product_ID = getM_Product_ID();
    if (M_Product_ID <= 0) {
        StringBuffer whereClause = new StringBuffer();
        String key = getProductValue();
        if (key == null || key.trim().length() == 0) {
            key = getName();
            whereClause.append("UPPER(Name)=");
        } else {
            whereClause.append("UPPER(Value)=");
        }
        if (key == null || key.trim().length() == 0) {
            throw new FillMandatoryException(COLUMNNAME_ProductValue, COLUMNNAME_Name);
        }
        key = key.toUpperCase();
        whereClause.append(DB.TO_STRING(key));
        whereClause.append(" AND AD_Client_ID=").append(getAD_Client_ID());
        String sql = "SELECT M_Product_ID FROM M_Product WHERE " + whereClause.toString();
        M_Product_ID = DB.getSQLValueEx(trxName, sql);
        log.fine("M_Product_ID=" + M_Product_ID + " -- sql=" + sql);
    }
    MProduct prod = null;
    // Create MProduct:
    if (M_Product_ID <= 0) {
        prod = new MProduct(ctx, 0, trxName);
        prod.setName(getName());
        String value = getProductValue();
        if (value != null && value.trim().length() > 0) {
            prod.setValue(value);
        }
        prod.setM_Product_Category_ID(m_M_Product_Category_ID);
        if (getC_UOM_ID() > 0) {
            prod.setC_UOM_ID(getC_UOM_ID());
        } else {
            prod.setC_UOM_ID(MUOM.getDefault_UOM_ID(ctx));
        }
        // Default Tax Category:
        String sql = "SELECT C_TaxCategory_ID FROM C_TaxCategory WHERE AD_Client_ID IN (0,?) ORDER BY IsDefault DESC, AD_Client_ID DESC, C_TaxCategory_ID";
        int C_TaxCategory_ID = DB.getSQLValueEx(null, sql, Env.getAD_Client_ID(ctx));
        prod.setC_TaxCategory_ID(C_TaxCategory_ID);
        //
        prod.saveEx(trxName);
    } else {
        prod = new MProduct(ctx, M_Product_ID, trxName);
    }
    setProduct(prod);
    return prod;
}
Also used : MProduct(org.compiere.model.MProduct) Properties(java.util.Properties) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 3 with FillMandatoryException

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

the class MIFixedAsset method process.

/**
	 *
	 */
public void process() {
    if (isProcessed()) {
        return;
    }
    try {
        if (getUseLifeMonths() <= 0) {
            throw new FillMandatoryException(COLUMNNAME_UseLifeMonths);
        }
        /*//comment by @win
			if (getA_Asset_Class_ID() <= 0)
			{
				throw new FillMandatoryException(COLUMNNAME_A_Asset_Class_ID);
			}
			
			// Fix Asset Class
			MAssetClass assetClass = MAssetClass.get(getCtx(), getA_Asset_Class_ID());
			setA_Asset_Class_Value(assetClass.getValue());
			*/
        //end comment by @win
        // Round amounts:
        int col_count = get_ColumnCount();
        for (int idx = 0; idx < col_count; idx++) {
            int dt = get_ColumnDisplayType(idx);
            if (DisplayType.Amount == dt)
                fixAmount(idx);
            else if (DisplayType.isText(dt))
                fixKeyValue(idx);
        }
        // Create/Set Product
        MProduct product = getCreateProduct();
        log.fine("product=" + product);
        if (getM_Product_ID() <= 0) {
            throw new FillMandatoryException(COLUMNNAME_M_Product_ID);
        }
        // Check Asset Group
        int A_Asset_Group_ID = getA_Asset_Group_ID();
        if (A_Asset_Group_ID <= 0) {
            if (m_A_Asset_Group_ID > 0) {
                A_Asset_Group_ID = m_A_Asset_Group_ID;
            } else {
                A_Asset_Group_ID = product.getA_Asset_Group_ID();
            }
        }
        if (A_Asset_Group_ID > 0) {
            setA_Asset_Group_ID(A_Asset_Group_ID);
        } else {
            throw new FillMandatoryException(COLUMNNAME_A_Asset_Group_ID);
        }
        // Set DateAcct
        if (getA_Remaining_Period() == 0) {
            setDateAcct(getAssetDepreciationDate());
        } else {
            Timestamp dateAcct = getDateAcct();
            if (dateAcct == null) {
                dateAcct = Env.getContextAsDate(getCtx(), "#Date");
                setDateAcct(dateAcct);
            }
        }
        if (getDateAcct() == null) {
            throw new FillMandatoryException(COLUMNNAME_DateAcct);
        }
        // Set Processed
        setProcessed(true);
        setI_ErrorMsg(null);
        // Save
        saveEx();
    } catch (Exception e) {
        setError(e.getLocalizedMessage());
        saveEx();
    }
}
Also used : MProduct(org.compiere.model.MProduct) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) Timestamp(java.sql.Timestamp) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 4 with FillMandatoryException

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

the class ComponentChange method doIt.

//	prepare
@Override
protected String doIt() throws Exception {
    if (p_Action == null) {
        throw new FillMandatoryException("Action");
    }
    List<Object> params = new ArrayList<Object>();
    StringBuffer whereClause = new StringBuffer();
    whereClause.append(MPPProductBOMLine.COLUMNNAME_M_Product_ID + "=?");
    params.add(p_M_Product_ID);
    if (p_ValidTo != null) {
        whereClause.append(" AND TRUNC(" + MPPProductBOMLine.COLUMNNAME_ValidTo + ") <= ?");
        params.add(p_ValidTo);
    }
    if (p_ValidFrom != null) {
        whereClause.append(" AND TRUNC(" + MPPProductBOMLine.COLUMNNAME_ValidFrom + ") >= ?");
        params.add(p_ValidFrom);
    }
    List<MPPProductBOMLine> components = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause.toString(), get_TrxName()).setParameters(params).list();
    for (MPPProductBOMLine bomline : components) {
        if (p_Action.equals(ACTION_Add)) {
            actionAdd(bomline, 0);
        } else if (p_Action.equals(ACTION_Deactivate)) {
            actionDeactivate(bomline);
        } else if (p_Action.equals(ACTION_Expire)) {
            actionExpire(bomline);
        } else if (p_Action.equals(ACTION_Replace)) {
            actionAdd(bomline, bomline.getLine() + 1);
            actionDeactivate(bomline);
        } else if (p_Action.equals(ACTION_ReplaceAndExpire)) {
            actionAdd(bomline, bomline.getLine() + 1);
            actionExpire(bomline);
        } else {
            throw new AdempiereException("Action not supported - " + p_Action);
        }
        addLog(MRefList.getListName(getCtx(), ACTION_AD_Reference_ID, p_Action));
    }
    return "@OK@";
}
Also used : Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine)

Example 5 with FillMandatoryException

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

the class InvoiceCreateInOut method doIt.

//	prepare
/**
	 * 	Create Shipment
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_Invoice_ID=" + p_C_Invoice_ID + ", M_Warehouse_ID=" + p_M_Warehouse_ID);
    if (p_C_Invoice_ID <= 0)
        throw new FillMandatoryException("C_Invoice_ID");
    if (p_M_Warehouse_ID == 0)
        throw new FillMandatoryException(PARAM_M_Warehouse_ID);
    //
    MInvoice invoice = new MInvoice(getCtx(), p_C_Invoice_ID, null);
    if (invoice.get_ID() <= 0)
        throw new AdempiereException("@NotFound@ @C_Invoice_ID@");
    if (!MInvoice.DOCSTATUS_Completed.equals(invoice.getDocStatus()))
        throw new AdempiereException("@InvoiceCreateDocNotCompleted@");
    //
    for (MInvoiceLine invoiceLine : invoice.getLines(false)) {
        createLine(invoice, invoiceLine);
    }
    if (m_inout == null)
        throw new InvoiceFullyMatchedException();
    //
    return m_inout.getDocumentNo();
}
Also used : InvoiceFullyMatchedException(org.adempiere.exceptions.InvoiceFullyMatchedException) AdempiereException(org.adempiere.exceptions.AdempiereException) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Aggregations

FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)20 AdempiereException (org.adempiere.exceptions.AdempiereException)11 I_M_HU (de.metas.handlingunits.model.I_M_HU)3 BigDecimal (java.math.BigDecimal)3 Timestamp (java.sql.Timestamp)3 MProduct (org.compiere.model.MProduct)3 ImmutableList (com.google.common.collect.ImmutableList)2 HUsToNewTUsRequest (de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest)2 I_M_HU_LUTU_Configuration (de.metas.handlingunits.model.I_M_HU_LUTU_Configuration)2 I_M_HU_PI_Item (de.metas.handlingunits.model.I_M_HU_PI_Item)2 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)2 List (java.util.List)2 ITrx (org.adempiere.ad.trx.api.ITrx)2 Services (org.adempiere.util.Services)2 Query (org.compiere.model.Query)2 Env (org.compiere.util.Env)2 Supplier (com.google.common.base.Supplier)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 I_M_InOutLine (de.metas.edi.model.I_M_InOutLine)1 EMail (de.metas.email.EMail)1