diff --git a/base/src/org/compiere/model/MLot.java b/base/src/org/compiere/model/MLot.java index dc05809922..04ea86ca13 100644 --- a/base/src/org/compiere/model/MLot.java +++ b/base/src/org/compiere/model/MLot.java @@ -70,16 +70,15 @@ public class MLot extends X_M_Lot * @param M_Product_ID product * @param lot * @param trxName transaction - * @return Array of Lots for Product //red1 -- last Lot + * @return Last Lot for Product */ public static MLot getProductLot (Properties ctx, int M_Product_ID, String lot, String trxName) { final String whereClause = "M_Product_ID=? AND Name=?"; - List list = new Query(ctx, I_M_Lot.Table_Name, whereClause, trxName) + MLot retValue = new Query(ctx, I_M_Lot.Table_Name, whereClause, trxName) .setParameters(M_Product_ID, lot) - .list(); - MLot retValue = null; - retValue = list.get(list.size()-1); //red1 get last lot + .setOrderBy(I_M_Lot.COLUMNNAME_M_Lot_ID + " DESC") + .first(); return retValue; } // getProductLot diff --git a/extend/src/test/functional/MLotTest.java b/extend/src/test/functional/MLotTest.java index 1bc68a0f00..1082fae83a 100644 --- a/extend/src/test/functional/MLotTest.java +++ b/extend/src/test/functional/MLotTest.java @@ -13,7 +13,6 @@ *****************************************************************************/ package test.functional; -import org.compiere.model.MInvoice; import org.compiere.model.MLot; import org.compiere.util.Env; @@ -35,8 +34,12 @@ public class MLotTest extends AdempiereTestCase public void testQuery() throws Exception { - MLot retValue = MLot.getProductLot(getCtx(), 122, "Test", getTrxName()); //red1 test record created with such values - assertTrue("Last Lot Rec is 101", retValue.getM_Lot_ID() == 101); + // to set up record - in a clean seed database + // open material receipt window + // create a material receipt for the product Fertilizer #50 + // and push the "New Record" button on the attribute set instance dialog + MLot retValue = MLot.getProductLot(getCtx(), 136, "100", getTrxName()); + assertTrue("Last Lot Rec is 101", retValue.getM_Lot_ID() == 1000000); }