peer review for 11545 and 11546 - refactored getProductLot to have predictable results

FR: [ 2214883 ] Remove SQL code and Replace for Query
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Carlos Ruiz 2010-03-03 22:40:26 +00:00
parent ff9dffd082
commit 98c74ef980
2 changed files with 10 additions and 8 deletions

View File

@ -70,16 +70,15 @@ public class MLot extends X_M_Lot
* @param M_Product_ID product * @param M_Product_ID product
* @param lot * @param lot
* @param trxName transaction * @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) public static MLot getProductLot (Properties ctx, int M_Product_ID, String lot, String trxName)
{ {
final String whereClause = "M_Product_ID=? AND Name=?"; final String whereClause = "M_Product_ID=? AND Name=?";
List <MLot> 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) .setParameters(M_Product_ID, lot)
.list(); .setOrderBy(I_M_Lot.COLUMNNAME_M_Lot_ID + " DESC")
MLot retValue = null; .first();
retValue = list.get(list.size()-1); //red1 get last lot
return retValue; return retValue;
} // getProductLot } // getProductLot

View File

@ -13,7 +13,6 @@
*****************************************************************************/ *****************************************************************************/
package test.functional; package test.functional;
import org.compiere.model.MInvoice;
import org.compiere.model.MLot; import org.compiere.model.MLot;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -35,8 +34,12 @@ public class MLotTest extends AdempiereTestCase
public void testQuery() throws Exception public void testQuery() throws Exception
{ {
MLot retValue = MLot.getProductLot(getCtx(), 122, "Test", getTrxName()); //red1 test record created with such values // to set up record - in a clean seed database
assertTrue("Last Lot Rec is 101", retValue.getM_Lot_ID() == 101); // 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);
} }