Search in sources :

Example 36 with AdempiereException

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

the class MTaxCategory method getDefaultTax.

//	MTaxCategory
/**
	 * 	getDefaultTax
	 *	Get the default tax id associated with this tax category
	 *	
	 */
public MTax getDefaultTax() {
    MTax m_tax = new MTax(getCtx(), 0, get_TrxName());
    final String whereClause = COLUMNNAME_C_TaxCategory_ID + "=? AND " + COLUMNNAME_IsDefault + "='Y'";
    List<MTax> list = new Query(getCtx(), I_C_Tax.Table_Name, whereClause, get_TrxName()).setParameters(getC_TaxCategory_ID()).setOnlyActiveRecords(true).list();
    if (list.size() == 0) {
        // Error - should be at least one default
        throw new AdempiereException("NoDefaultTaxRate");
    } else if (list.size() == 1) {
        m_tax = list.get(0);
    } else {
        // Error - should only be one default
        throw new AdempiereException("TooManyDefaults");
    }
    return m_tax;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 37 with AdempiereException

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

the class MDDOrder method createDropShip.

//	completeIt
private void createDropShip() {
    //Create movement delivery
    Date date = Date.from(LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    Timestamp today = new Timestamp(date.getTime());
    List<Integer> recordIds = new ArrayList<>();
    recordIds.add(getDD_Order_ID());
    ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(GenerateMovement.getProcessId()).withTitle(GenerateMovement.getProcessName()).withRecordId(MDDOrder.Table_ID, 0).withSelectedRecordsIds(recordIds).withParameter(MMovement.COLUMNNAME_MovementDate, today).withParameter(MMovement.COLUMNNAME_DocAction, DocAction.ACTION_Complete).withoutTransactionClose().execute(get_TrxName());
    if (processInfo.isError())
        throw new AdempiereException(processInfo.getSummary());
    List<Integer> orderLinesIds = new ArrayList<>();
    LinkedHashMap<Integer, LinkedHashMap<String, Object>> selection = new LinkedHashMap<Integer, LinkedHashMap<String, Object>>();
    getLines().stream().filter(orderLine -> orderLine != null).forEach(orderLine -> {
        orderLinesIds.add(orderLine.get_ID());
        LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
        values.put("LINE_" + MDDOrderLine.COLUMNNAME_QtyInTransit, orderLine.getQtyInTransit());
        selection.put(orderLine.get_ID(), values);
    });
    processInfo = ProcessBuilder.create(getCtx()).process(GenerateMovementMaterial.getProcessId()).withTitle(GenerateMovementMaterial.getProcessName()).withRecordId(MDDOrderLine.Table_ID, 0).withSelectedRecordsIds(orderLinesIds, selection).withParameter(MMovement.COLUMNNAME_MovementDate, today).withoutTransactionClose().execute(get_TrxName());
    if (processInfo.isError())
        throw new AdempiereException(processInfo.getSummary());
}
Also used : DocumentEngine(org.compiere.process.DocumentEngine) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) Date(java.util.Date) Env(org.compiere.util.Env) ProcessBuilder(org.eevolution.service.dsl.ProcessBuilder) MStorage(org.compiere.model.MStorage) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) MBPartnerLocation(org.compiere.model.MBPartnerLocation) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) ResultSet(java.sql.ResultSet) MPeriod(org.compiere.model.MPeriod) ProcessInfo(org.compiere.process.ProcessInfo) DocAction(org.compiere.process.DocAction) Util(org.compiere.util.Util) Properties(java.util.Properties) GenerateMovement(org.eevolution.process.GenerateMovement) Timestamp(java.sql.Timestamp) MDocType(org.compiere.model.MDocType) MRefList(org.compiere.model.MRefList) File(java.io.File) ZoneId(java.time.ZoneId) ReportEngine(org.compiere.print.ReportEngine) ModelValidator(org.compiere.model.ModelValidator) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) MMovement(org.compiere.model.MMovement) LocalDate(java.time.LocalDate) I_C_DocType(org.compiere.model.I_C_DocType) Optional(java.util.Optional) MLocator(org.compiere.model.MLocator) PO(org.compiere.model.PO) ModelValidationEngine(org.compiere.model.ModelValidationEngine) GenerateMovementMaterial(org.eevolution.process.GenerateMovementMaterial) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) Timestamp(java.sql.Timestamp) Date(java.util.Date) LocalDate(java.time.LocalDate) LinkedHashMap(java.util.LinkedHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 38 with AdempiereException

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

the class MDDOrder method reserveStock.

//	prepareIt
/**
	 * 	Reserve Inventory.
	 * 	Counterpart: MMovement.completeIt()
	 * 	@param orderLines distribution order lines (ordered by M_Product_ID for deadlock prevention)
	 * 	@return true if (un) reserved
	 */
public void reserveStock(List<MDDOrderLine> orderLines) {
    //	Always check and (un) Reserve Inventory		
    orderLines.stream().filter(// filter the order line that where Reserved Quantity need be change
    orderLine -> orderLine.getCalculateQtyReserved().signum() != 0).filter(// filter that order line with product stocked
    orderLine -> orderLine.getProduct() != null && orderLine.getProduct().isStocked()).forEach(orderLine -> {
        MLocator locatorFrom = MLocator.get(getCtx(), orderLine.getM_Locator_ID());
        MLocator locatorTo = MLocator.get(getCtx(), orderLine.getM_LocatorTo_ID());
        log.fine("Line=" + orderLine.getLine() + " - Ordered=" + orderLine.getQtyOrdered() + ",Reserved=" + orderLine.getQtyReserved() + ",Delivered=" + orderLine.getQtyDelivered());
        if (!MStorage.add(getCtx(), locatorTo.getM_Warehouse_ID(), locatorTo.getM_Locator_ID(), orderLine.getM_Product_ID(), orderLine.getM_AttributeSetInstance_ID(), orderLine.getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, orderLine.getCalculateQtyReserved(), get_TrxName()))
            throw new AdempiereException("@M_Storage_ID@ @Error@ @To@ @QtyReserved@");
        if (!MStorage.add(getCtx(), locatorFrom.getM_Warehouse_ID(), locatorFrom.getM_Locator_ID(), orderLine.getM_Product_ID(), orderLine.getM_AttributeSetInstanceTo_ID(), orderLine.getM_AttributeSetInstance_ID(), Env.ZERO, orderLine.getCalculateQtyReserved(), Env.ZERO, get_TrxName()))
            throw new AdempiereException("@M_Storage_ID@ @Error@ @To@ @QtyReserved@");
        orderLine.setQtyReserved(orderLine.getQtyReserved().add(orderLine.getCalculateQtyReserved()));
        orderLine.saveEx();
    });
    updateVolume();
    updateWeight();
}
Also used : DocumentEngine(org.compiere.process.DocumentEngine) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) Date(java.util.Date) Env(org.compiere.util.Env) ProcessBuilder(org.eevolution.service.dsl.ProcessBuilder) MStorage(org.compiere.model.MStorage) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) MBPartnerLocation(org.compiere.model.MBPartnerLocation) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) ResultSet(java.sql.ResultSet) MPeriod(org.compiere.model.MPeriod) ProcessInfo(org.compiere.process.ProcessInfo) DocAction(org.compiere.process.DocAction) Util(org.compiere.util.Util) Properties(java.util.Properties) GenerateMovement(org.eevolution.process.GenerateMovement) Timestamp(java.sql.Timestamp) MDocType(org.compiere.model.MDocType) MRefList(org.compiere.model.MRefList) File(java.io.File) ZoneId(java.time.ZoneId) ReportEngine(org.compiere.print.ReportEngine) ModelValidator(org.compiere.model.ModelValidator) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) MMovement(org.compiere.model.MMovement) LocalDate(java.time.LocalDate) I_C_DocType(org.compiere.model.I_C_DocType) Optional(java.util.Optional) MLocator(org.compiere.model.MLocator) PO(org.compiere.model.PO) ModelValidationEngine(org.compiere.model.ModelValidationEngine) GenerateMovementMaterial(org.eevolution.process.GenerateMovementMaterial) AdempiereException(org.adempiere.exceptions.AdempiereException) MLocator(org.compiere.model.MLocator)

Example 39 with AdempiereException

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

the class MDDOrder method setBPartner.

//	setShip_User_ID
/**
	 * 	Set Business Partner Defaults & Details.
	 * 	SOTrx should be set.
	 * 	@param bp business partner
	 */
public void setBPartner(MBPartner bp) {
    if (bp == null)
        return;
    setC_BPartner_ID(bp.getC_BPartner_ID());
    //	Defaults Payment Term
    int ii = 0;
    if (isSOTrx())
        ii = bp.getC_PaymentTerm_ID();
    else
        ii = bp.getPO_PaymentTerm_ID();
    //	Default Price List
    if (isSOTrx())
        ii = bp.getM_PriceList_ID();
    else
        ii = bp.getPO_PriceList_ID();
    //	Default Delivery/Via Rule
    String ss = bp.getDeliveryRule();
    if (ss != null)
        setDeliveryRule(ss);
    ss = bp.getDeliveryViaRule();
    if (ss != null)
        setDeliveryViaRule(ss);
    //	Default Invoice/Payment Rule
    ss = bp.getInvoiceRule();
    if (getSalesRep_ID() == 0) {
        ii = Env.getAD_User_ID(getCtx());
        if (ii != 0)
            setSalesRep_ID(ii);
    }
    //	Set Locations
    /*
		MBPartnerLocation[] locs = bp.getLocations(false);
		if (locs != null)
		{
			for (int i = 0; i < locs.length; i++)
			{
				if (locs[i].isShipTo())
				{
					super.setC_BPartner_Location_ID(locs[i].getC_BPartner_Location_ID());
				}
			}
			//	set to first
			if (getC_BPartner_Location_ID() == 0 && locs.length > 0)
			{
				super.setC_BPartner_Location_ID(locs[0].getC_BPartner_Location_ID());
			}
		}
		*/
    List<MBPartnerLocation> partnerLocations = Arrays.asList(bp.getLocations(false));
    // search the Ship To Location
    MBPartnerLocation partnerLocation = // create steam
    partnerLocations.stream().filter(pl -> pl.isShipTo()).reduce(// get of last Ship to location
    (first, last) -> last).orElse(// if not exist Ship to location else get first partner location
    partnerLocations.stream().findFirst().orElseThrow(() -> new AdempiereException("@IsShipTo@ @NotFound@")));
    setC_BPartner_Location_ID(partnerLocation.getC_BPartner_Location_ID());
    if (getC_BPartner_Location_ID() == 0) {
        log.log(Level.SEVERE, "MDDOrder.setBPartner - Has no Ship To Address: " + bp);
    }
    //	Set Contact
    /*MUser[] contacts = bp.getContacts(false);
		if (contacts != null && contacts.length == 1)
		{
			setAD_User_ID(contacts[0].getAD_User_ID());
		}*/
    Arrays.asList(bp.getContacts(false)).stream().findFirst().ifPresent(user -> setAD_User_ID(user.getAD_User_ID()));
}
Also used : DocumentEngine(org.compiere.process.DocumentEngine) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) Date(java.util.Date) Env(org.compiere.util.Env) ProcessBuilder(org.eevolution.service.dsl.ProcessBuilder) MStorage(org.compiere.model.MStorage) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) MBPartnerLocation(org.compiere.model.MBPartnerLocation) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) ResultSet(java.sql.ResultSet) MPeriod(org.compiere.model.MPeriod) ProcessInfo(org.compiere.process.ProcessInfo) DocAction(org.compiere.process.DocAction) Util(org.compiere.util.Util) Properties(java.util.Properties) GenerateMovement(org.eevolution.process.GenerateMovement) Timestamp(java.sql.Timestamp) MDocType(org.compiere.model.MDocType) MRefList(org.compiere.model.MRefList) File(java.io.File) ZoneId(java.time.ZoneId) ReportEngine(org.compiere.print.ReportEngine) ModelValidator(org.compiere.model.ModelValidator) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) MMovement(org.compiere.model.MMovement) LocalDate(java.time.LocalDate) I_C_DocType(org.compiere.model.I_C_DocType) Optional(java.util.Optional) MLocator(org.compiere.model.MLocator) PO(org.compiere.model.PO) ModelValidationEngine(org.compiere.model.ModelValidationEngine) GenerateMovementMaterial(org.eevolution.process.GenerateMovementMaterial) AdempiereException(org.adempiere.exceptions.AdempiereException) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 40 with AdempiereException

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

the class MPPOrder method explotion.

/**
	 * Create PP_Order_BOM from PP_Product_BOM.
	 * Create PP_Order_Workflow from AD_Workflow.
	 */
private void explotion() {
    // Create BOM Head
    final MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
    // Product from Order should be same as product from BOM - teo_sarca [ 2817870 ] 
    if (getM_Product_ID() != PP_Product_BOM.getM_Product_ID()) {
        throw new AdempiereException("@NotMatch@ @PP_Product_BOM_ID@ , @M_Product_ID@");
    }
    // Product BOM Configuration should be verified - teo_sarca [ 2817870 ]
    final MProduct product = MProduct.get(getCtx(), PP_Product_BOM.getM_Product_ID());
    if (!product.isVerified()) {
        // TODO: translate
        throw new AdempiereException("Product BOM Configuration not verified. Please verify the product first - " + product.getValue());
    }
    if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) {
        MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName());
        PP_Order_BOM.setAD_Org_ID(getAD_Org_ID());
        PP_Order_BOM.saveEx();
        for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines(true)) {
            if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) {
                MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), PP_Order_BOM.get_ID(), getM_Warehouse_ID(), get_TrxName());
                PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
                PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
                PP_Order_BOMLine.setM_Locator_ID(getM_Locator_ID());
                PP_Order_BOMLine.setQtyOrdered(getQtyOrdered());
                PP_Order_BOMLine.saveEx();
            } else // end if valid From / To    
            {
                log.fine("BOM Line skiped - " + PP_Product_BOMline);
            }
        }
    // end Create Order BOM
    } else // end if From / To parent
    {
        throw new BOMExpiredException(PP_Product_BOM, getDateStartSchedule());
    }
    // Create Workflow (Routing & Process)
    final MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID());
    // Workflow should be validated first - teo_sarca [ 2817870 ]
    if (!AD_Workflow.isValid()) {
        // TODO: translate
        throw new AdempiereException("Routing is not valid. Please validate it first - " + AD_Workflow.getValue());
    }
    if (AD_Workflow.isValidFromTo(getDateStartSchedule())) {
        MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName());
        PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID());
        PP_Order_Workflow.saveEx();
        for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) {
            if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) {
                MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, getQtyOrdered(), get_TrxName());
                PP_Order_Node.setAD_Org_ID(getAD_Org_ID());
                PP_Order_Node.saveEx();
                for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) {
                    MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
                    nodenext.setAD_Org_ID(getAD_Org_ID());
                    nodenext.saveEx();
                }
                for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
                    MPPOrderNodeProduct nodeOrderProduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
                    nodeOrderProduct.setAD_Org_ID(getAD_Org_ID());
                    nodeOrderProduct.saveEx();
                }
                for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
                    MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
                    nodeorderasset.setAD_Org_ID(getAD_Org_ID());
                    nodeorderasset.saveEx();
                }
            }
        // for node 
        }
        // Update transitions nexts and set first node
        // requery
        PP_Order_Workflow.getNodes(true);
        for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) {
            // set workflow start node
            if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
                PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
            }
            // set node next
            for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) {
                next.setPP_Order_Next_ID();
                next.saveEx();
            }
        }
        PP_Order_Workflow.saveEx();
    } else // workflow valid from/to
    {
        throw new RoutingExpiredException(AD_Workflow, getDateStartSchedule());
    }
}
Also used : MProduct(org.compiere.model.MProduct) MWorkflow(org.compiere.wf.MWorkflow) BOMExpiredException(org.eevolution.exceptions.BOMExpiredException) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext) RoutingExpiredException(org.eevolution.exceptions.RoutingExpiredException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)216 BigDecimal (java.math.BigDecimal)64 SQLException (java.sql.SQLException)42 ResultSet (java.sql.ResultSet)29 PreparedStatement (java.sql.PreparedStatement)28 MProduct (org.compiere.model.MProduct)28 ArrayList (java.util.ArrayList)27 Timestamp (java.sql.Timestamp)23 Query (org.compiere.model.Query)19 PO (org.compiere.model.PO)16 MBPartner (org.compiere.model.MBPartner)14 Properties (java.util.Properties)13 File (java.io.File)12 List (java.util.List)12 ProcessInfo (org.compiere.process.ProcessInfo)12 Arrays (java.util.Arrays)10 Env (org.compiere.util.Env)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 MMovement (org.compiere.model.MMovement)9 Date (java.util.Date)8