Search in sources :

Example 86 with Query

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

the class InventoryUtil method getDefault_TaxCategory_ID.

public static int getDefault_TaxCategory_ID() {
    Properties ctx = Env.getCtx();
    MTaxCategory taxCategory = new Query(ctx, MTaxCategory.Table_Name, "IsDefault='Y'", null).setClient_ID().setOnlyActiveRecords(true).firstOnly();
    return taxCategory != null ? taxCategory.get_ID() : 0;
}
Also used : MTaxCategory(org.compiere.model.MTaxCategory) Query(org.compiere.model.Query) Properties(java.util.Properties)

Example 87 with Query

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

the class InventoryUtil method getCreateProductCategory.

public static MProductCategory getCreateProductCategory(String value, String MMPolicy) {
    if (MMPolicy == null)
        MMPolicy = MProductCategory.MMPOLICY_FiFo;
    Properties ctx = Env.getCtx();
    final String whereClause = I_M_Product_Category.COLUMNNAME_Value + "=?";
    MProductCategory pc = new Query(ctx, I_M_Product_Category.Table_Name, whereClause, null).setParameters(value).setOnlyActiveRecords(true).setClient_ID().firstOnly();
    if (pc == null) {
        pc = new MProductCategory(ctx, 0, null);
    }
    pc.setValue(value);
    pc.setName(value);
    setGeneratedTag(pc);
    pc.setMMPolicy(MMPolicy);
    //
    pc.saveEx();
    return pc;
}
Also used : Query(org.compiere.model.Query) MProductCategory(org.compiere.model.MProductCategory) Properties(java.util.Properties)

Example 88 with Query

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

the class InventoryUtil method getCreateWarehouse.

/**
	 * Helper Method : Create Warehouse
	 */
public static MWarehouse getCreateWarehouse(int AD_Org_ID, String value) {
    if (AD_Org_ID <= 0)
        AD_Org_ID = getFirst_Org_ID();
    Properties ctx = Env.getCtx();
    final String whereClause = "AD_Org_ID=? AND Value=?";
    MWarehouse wh = new Query(ctx, I_M_Warehouse.Table_Name, whereClause, null).setParameters(AD_Org_ID, value).setClient_ID().firstOnly();
    if (wh != null)
        return wh;
    wh = new MWarehouse(ctx, 0, null);
    wh.setAD_Org_ID(AD_Org_ID);
    wh.setValue(value);
    wh.setName(value);
    MLocation loc = new MLocation(ctx, 0, null);
    loc.saveEx();
    wh.setC_Location_ID(loc.get_ID());
    wh.saveEx();
    return wh;
}
Also used : Query(org.compiere.model.Query) Properties(java.util.Properties) MLocation(org.compiere.model.MLocation) MWarehouse(org.compiere.model.MWarehouse)

Example 89 with Query

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

the class QueryTest method testCount_NoValues.

public void testCount_NoValues() throws Exception {
    int count = new Query(getCtx(), "AD_Table", "1=2", getTrxName()).count();
    assertEquals("Counter should be ZERO", 0, count);
}
Also used : Query(org.compiere.model.Query)

Example 90 with Query

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

the class QueryTest method testFirstOnly.

public void testFirstOnly() throws Exception {
    MTable t = new Query(getCtx(), "AD_Table", "AD_Table_ID=?", getTrxName()).setParameters(new Object[] { 318 }).firstOnly();
    assertEquals("Invalid table ID", 318, t.get_ID());
    //
    assertExceptionThrown(null, DBException.class, new Runnable() {

        public void run() {
            new Query(getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName()).setParameters(new Object[] { "C_Invoice", "M_InOut" }).setOrderBy("TableName").firstOnly();
        }
    });
}
Also used : MTable(org.compiere.model.MTable) Query(org.compiere.model.Query)

Aggregations

Query (org.compiere.model.Query)210 ArrayList (java.util.ArrayList)49 BigDecimal (java.math.BigDecimal)25 Properties (java.util.Properties)22 MProduct (org.compiere.model.MProduct)20 AdempiereException (org.adempiere.exceptions.AdempiereException)12 MTable (org.compiere.model.MTable)12 MOrderLine (org.compiere.model.MOrderLine)8 MWarehouse (org.compiere.model.MWarehouse)8 PO (org.compiere.model.PO)8 MBPartner (org.compiere.model.MBPartner)6 MQuery (org.compiere.model.MQuery)6 MPPProductBOM (org.eevolution.model.MPPProductBOM)6 MColumn (org.compiere.model.MColumn)5 MLocation (org.compiere.model.MLocation)5 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)5 SQLException (java.sql.SQLException)4 Timestamp (java.sql.Timestamp)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 MClient (org.compiere.model.MClient)4