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;
}
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;
}
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;
}
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);
}
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();
}
});
}
Aggregations