BF [ 1564496 ] Inventory Move should warn if insufficient stock on hand

This commit is contained in:
teo_sarca 2008-02-01 21:20:47 +00:00
parent f8d10212a8
commit 5ded70c335
2 changed files with 41 additions and 35 deletions

View File

@ -121,9 +121,8 @@ public class CalloutMovement extends CalloutEngine
// If no locator, don't check anything and assume is ok // If no locator, don't check anything and assume is ok
if (M_Locator_ID <= 0) if (M_Locator_ID <= 0)
return; return;
int M_Warehouse_ID = MLocator.get(ctx, M_Locator_ID).getM_Warehouse_ID();
int M_AttributeSetInstance_ID = Env.getContextAsInt(ctx, WindowNo, "M_AttributeSetInstance_ID"); int M_AttributeSetInstance_ID = Env.getContextAsInt(ctx, WindowNo, "M_AttributeSetInstance_ID");
BigDecimal available = MStorage.getQtyAvailable(M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, null); BigDecimal available = MStorage.getQtyAvailable(0, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, null);
if (available == null) if (available == null)
available = Env.ZERO; available = Env.ZERO;
if (available.signum() == 0) if (available.signum() == 0)

View File

@ -503,46 +503,53 @@ public class MStorage extends X_M_Storage
* @param M_AttributeSetInstance_ID masi * @param M_AttributeSetInstance_ID masi
* @param trxName transaction * @param trxName transaction
* @return qty available (QtyOnHand-QtyReserved) or null * @return qty available (QtyOnHand-QtyReserved) or null
* @deprecated Since 331b. Please use {@link #getQtyAvailable(int, int, int, int, String)}.
*/ */
public static BigDecimal getQtyAvailable (int M_Warehouse_ID, public static BigDecimal getQtyAvailable (int M_Warehouse_ID,
int M_Product_ID, int M_AttributeSetInstance_ID, String trxName) int M_Product_ID, int M_AttributeSetInstance_ID, String trxName)
{ {
BigDecimal retValue = null; return getQtyAvailable(M_Warehouse_ID, 0, M_Product_ID, M_AttributeSetInstance_ID, trxName);
PreparedStatement pstmt = null; }
ResultSet rs = null;
String sql = "SELECT SUM(QtyOnHand-QtyReserved) " /**
+ "FROM M_Storage s" * Get Warehouse/Locator Available Qty.
+ " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " * The call is accurate only if there is a storage record
+ "WHERE s.M_Product_ID=?" // #1 * and assumes that the product is stocked
+ " AND l.M_Warehouse_ID=?"; * @param M_Warehouse_ID wh (if the M_Locator_ID!=0 then M_Warehouse_ID is ignored)
if (M_AttributeSetInstance_ID != 0) * @param M_Locator_ID locator (if 0, the whole warehouse will be evaluated)
sql += " AND M_AttributeSetInstance_ID=?"; * @param M_Product_ID product
try * @param M_AttributeSetInstance_ID masi
{ * @param trxName transaction
pstmt = DB.prepareStatement (sql, trxName); * @return qty available (QtyOnHand-QtyReserved) or null if error
pstmt.setInt (1, M_Product_ID); */
pstmt.setInt (2, M_Warehouse_ID); public static BigDecimal getQtyAvailable (int M_Warehouse_ID, int M_Locator_ID,
if (M_AttributeSetInstance_ID != 0) int M_Product_ID, int M_AttributeSetInstance_ID, String trxName)
pstmt.setInt(3, M_AttributeSetInstance_ID); {
rs = pstmt.executeQuery (); ArrayList<Object> params = new ArrayList<Object>();
if (rs.next ()) StringBuffer sql = new StringBuffer("SELECT COALESCE(SUM(s.QtyOnHand-s.QtyReserved),0)")
{ .append(" FROM M_Storage s")
retValue = rs.getBigDecimal(1); .append(" WHERE s.M_Product_ID=?");
if (rs.wasNull()) params.add(M_Product_ID);
retValue = null; // Warehouse level
} if (M_Locator_ID == 0) {
sql.append(" AND EXISTS (SELECT 1 FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID AND l.M_Warehouse_ID=?)");
params.add(M_Warehouse_ID);
} }
catch (Exception e) // Locator level
{ else {
s_log.log(Level.SEVERE, sql, e); sql.append(" AND s.M_Locator_ID=?");
params.add(M_Locator_ID);
} }
finally // With ASI
{ if (M_AttributeSetInstance_ID != 0) {
DB.close(rs, pstmt); sql.append(" AND s.M_AttributeSetInstance_ID=?");
rs = null; pstmt = null; params.add(M_AttributeSetInstance_ID);
} }
s_log.fine("M_Warehouse_ID=" + M_Warehouse_ID //
+ ",M_Product_ID=" + M_Product_ID + " = " + retValue); BigDecimal retValue = DB.getSQLValueBD(trxName, sql.toString(), params);
if (CLogMgt.isLevelFine())
s_log.fine("M_Warehouse_ID=" + M_Warehouse_ID + ", M_Locator_ID=" + M_Locator_ID
+ ",M_Product_ID=" + M_Product_ID + " = " + retValue);
return retValue; return retValue;
} // getQtyAvailable } // getQtyAvailable