Issuing of stock should ignore storage with onhand <= 0 - ID: 2545020

http://sourceforge.net/tracker2/index.php?func=detail&aid=2545020&group_id=176962&atid=879332
Merge change from 8234 revision
http://adempiere.svn.sourceforge.net/viewvc/adempiere?view=rev&revision=8234

[ 2545020 ] Issuing of stock should ignore storage with onhand <= 0
- Only process storage with qtyOnHand > 0 when fulfilling for customer shipment, inventory movement and physical inventory.
- Remove remarked code.
- Fixed javadoc in MStorage, restore the original behaviour of getAllASI. Refactor getWarehouse method as the primary method use to
  retrieve storage records for customer shipment, inventory movement and physical inventory transaction.
- Fixed MStorage.getWarehouse to behave as stated in the javadoc, i.e always respect the locator priority.
- Remove the linePerASI logic in InOutGenerate so that the actual allocation of storage only happens in MInOut. Ensure proper reset
  of storage cache.
This commit is contained in:
vpj-cd 2009-01-30 02:04:42 +00:00
parent ccb8dc48a5
commit 9003312769
5 changed files with 1684 additions and 1867 deletions

View File

@ -1654,7 +1654,6 @@ public class MInOut extends X_M_InOut implements DocAction
boolean needSave = false;
BigDecimal qtyASI = Env.ZERO ;
MProduct product = line.getProduct();
@ -1694,65 +1693,12 @@ public class MInOut extends X_M_InOut implements DocAction
else if(getMovementType().compareTo(MInOut.MOVEMENTTYPE_VendorReturns) == 0 || getMovementType().compareTo(MInOut.MOVEMENTTYPE_CustomerShipment) == 0)
{
String MMPolicy = product.getMMPolicy();
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
line.getM_Product_ID(), line.getM_Locator_ID(),
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
Timestamp minGuaranteeDate = getMovementDate();
MStorage[] storages = MStorage.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, line.getM_Locator_ID(), get_TrxName());
BigDecimal qtyToDeliver = line.getMovementQty();
/*for (int ii = 0; ii < storages.length; ii++)
{
MStorage storage = storages[ii];
if (ii == 0)
{
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
{
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
needSave = true;
log.config("Direct - " + line);
qtyToDeliver = Env.ZERO;
}
else
{
log.config("Split - " + line);
MInOutLineMA ma = new MInOutLineMA (line,
storage.getM_AttributeSetInstance_ID(),
storage.getQtyOnHand());
if (!ma.save())
;
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
}
}
else // create addl material allocation
{
MInOutLineMA ma = new MInOutLineMA (line,
storage.getM_AttributeSetInstance_ID(),
qtyToDeliver);
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
qtyToDeliver = Env.ZERO;
else
{
ma.setMovementQty(storage.getQtyOnHand());
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
}
if (!ma.save())
;
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
}
if (qtyToDeliver.signum() == 0)
break;
} // for all storages
*/
for (MStorage storage: storages)
{
//consume ASI Zero
if (storage.getM_AttributeSetInstance_ID() == 0)
{
qtyASI = qtyASI.add(storage.getQtyOnHand());
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
continue;
}
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
{
MInOutLineMA ma = new MInOutLineMA (line,
@ -1779,11 +1725,11 @@ public class MInOut extends X_M_InOut implements DocAction
}
// No AttributeSetInstance found for remainder
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
if (qtyToDeliver.signum() != 0)
{
MInOutLineMA ma = new MInOutLineMA (line, 0, qtyToDeliver.add(qtyASI));
MInOutLineMA ma = new MInOutLineMA (line, 0, qtyToDeliver);
if (!ma.save())
;
throw new IllegalStateException("Error try create ASI Reservation");
log.fine("##: " + ma);
}
} // outgoing Trx

File diff suppressed because it is too large Load Diff

View File

@ -658,81 +658,19 @@ public class MMovement extends X_M_Movement implements DocAction
//{
// MMovementLine line = lines[i];
boolean needSave = false;
BigDecimal qtyASI = Env.ZERO ;
// Attribute Set Instance
if (line.getM_AttributeSetInstance_ID() == 0)
{
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
String MMPolicy = product.getMMPolicy();
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
line.getM_Product_ID(), line.getM_Locator_ID(),
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
MStorage[] storages = MStorage.getWarehouse(getCtx(), 0, line.getM_Product_ID(), 0,
null, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, line.getM_Locator_ID(), get_TrxName());
BigDecimal qtyToDeliver = line.getMovementQty();
/*for (int ii = 0; ii < storages.length; ii++)
{
MStorage storage = storages[ii];
if (ii == 0)
{
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
{
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
needSave = true;
log.config("Direct - " + line);
qtyToDeliver = Env.ZERO;
}
else
{
log.config("Split - " + line);
MMovementLineMA ma = new MMovementLineMA (line,
storage.getM_AttributeSetInstance_ID(),
storage.getQtyOnHand());
if (!ma.save())
;
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
}
}
else // create addl material allocation
{
MMovementLineMA ma = new MMovementLineMA (line,
storage.getM_AttributeSetInstance_ID(),
qtyToDeliver);
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
qtyToDeliver = Env.ZERO;
else
{
ma.setMovementQty(storage.getQtyOnHand());
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
}
if (!ma.save())
;
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
}
if (qtyToDeliver.signum() == 0)
break;
} // for all storages
// No AttributeSetInstance found for remainder
if (qtyToDeliver.signum() != 0)
{
MMovementLineMA ma = new MMovementLineMA (line,
0, qtyToDeliver);
if (!ma.save())
;
log.fine("##: " + ma);
}*/
for (MStorage storage: storages)
{
//consume ASI Zero
if (storage.getM_AttributeSetInstance_ID() == 0)
{
qtyASI = qtyASI.add(storage.getQtyOnHand());
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
continue;
}
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
{
MMovementLineMA ma = new MMovementLineMA (line,
@ -761,12 +699,12 @@ public class MMovement extends X_M_Movement implements DocAction
}
// No AttributeSetInstance found for remainder
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
if (qtyToDeliver.signum() != 0)
{
MMovementLineMA ma = new MMovementLineMA (line, 0 , qtyToDeliver.add(qtyASI));
MMovementLineMA ma = new MMovementLineMA (line, 0 , qtyToDeliver);
if (!ma.save())
;
throw new IllegalStateException("Error try create ASI Reservation");
log.fine("##: " + ma);
}
} // attributeSetInstance

View File

@ -78,7 +78,6 @@ public class MStorage extends X_M_Storage
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
pstmt = null;
if (retValue == null)
s_log.fine("Not Found - M_Locator_ID=" + M_Locator_ID
+ ", M_Product_ID=" + M_Product_ID + ", M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
@ -89,7 +88,7 @@ public class MStorage extends X_M_Storage
} // get
/**
* Get all Storages for Product with ASI and QtyOnHand > 0
* Get all Storages for Product with ASI and QtyOnHand <> 0
* @param ctx context
* @param M_Product_ID product
* @param M_Locator_ID locator
@ -103,13 +102,9 @@ public class MStorage extends X_M_Storage
ArrayList<MStorage> list = new ArrayList<MStorage>();
String sql = "SELECT * FROM M_Storage "
+ "WHERE M_Product_ID=? AND M_Locator_ID=?"
// Remove for management rightly FIFO/LIFO now you can consume a layer with ASI ID = zero and Qty onhand in negative
// + " AND M_AttributeSetInstance_ID > 0"
// + " AND QtyOnHand > 0 "
+ " AND QtyOnHand <> 0 "
+ " AND M_AttributeSetInstance_ID > 0 "
+ " AND QtyOnHand <> 0 "
+ "ORDER BY M_AttributeSetInstance_ID";
if (!FiFo)
sql += " DESC";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
@ -130,14 +125,13 @@ public class MStorage extends X_M_Storage
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
pstmt = null;
MStorage[] retValue = new MStorage[list.size()];
list.toArray(retValue);
return retValue;
} // getAllWithASI
/**
* Get all Storages for Product
* Get all Storages for Product where QtyOnHand <> 0
* @param ctx context
* @param M_Product_ID product
* @param M_Locator_ID locator
@ -172,7 +166,6 @@ public class MStorage extends X_M_Storage
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
pstmt = null;
MStorage[] retValue = new MStorage[list.size()];
list.toArray(retValue);
return retValue;
@ -227,23 +220,41 @@ public class MStorage extends X_M_Storage
* @param FiFo first in-first-out
* @param trxName transaction
* @return existing - ordered by location priority (desc) and/or guarantee date
*
* @deprecated
*/
public static MStorage[] getWarehouse (Properties ctx, int M_Warehouse_ID,
int M_Product_ID, int M_AttributeSetInstance_ID, int M_AttributeSet_ID,
boolean allAttributeInstances, Timestamp minGuaranteeDate,
boolean FiFo, String trxName)
{
if (M_Warehouse_ID == 0 || M_Product_ID == 0)
return getWarehouse(ctx, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,
minGuaranteeDate, FiFo, false, 0, trxName);
}
/**
* Get Storage Info for Warehouse or locator
* @param ctx context
* @param M_Warehouse_ID ignore if M_Locator_ID > 0
* @param M_Product_ID product
* @param M_AttributeSetInstance_ID instance id, 0 to retrieve all instance
* @param minGuaranteeDate optional minimum guarantee date if all attribute instances
* @param FiFo first in-first-out
* @param positiveOnly if true, only return storage records with qtyOnHand > 0
* @param M_Locator_ID optional locator id
* @param trxName transaction
* @return existing - ordered by location priority (desc) and/or guarantee date
*/
public static MStorage[] getWarehouse (Properties ctx, int M_Warehouse_ID,
int M_Product_ID, int M_AttributeSetInstance_ID, Timestamp minGuaranteeDate,
boolean FiFo, boolean positiveOnly, int M_Locator_ID, String trxName)
{
if ((M_Warehouse_ID == 0 && M_Locator_ID == 0) || M_Product_ID == 0)
return new MStorage[0];
if (M_AttributeSet_ID == 0)
allAttributeInstances = true;
else
{
MAttributeSet mas = MAttributeSet.get(ctx, M_AttributeSet_ID);
if (!mas.isInstanceAttribute())
allAttributeInstances = true;
}
boolean allAttributeInstances = false;
if (M_AttributeSetInstance_ID == 0)
allAttributeInstances = true;
ArrayList<MStorage> list = new ArrayList<MStorage>();
// Specific Attribute Set Instance
@ -251,11 +262,18 @@ public class MStorage extends X_M_Storage
+ "s.AD_Client_ID,s.AD_Org_ID,s.IsActive,s.Created,s.CreatedBy,s.Updated,s.UpdatedBy,"
+ "s.QtyOnHand,s.QtyReserved,s.QtyOrdered,s.DateLastInventory "
+ "FROM M_Storage s"
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
+ "WHERE l.M_Warehouse_ID=?"
+ " AND s.M_Product_ID=?"
+ " AND COALESCE(s.M_AttributeSetInstance_ID,0)=? "
+ "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) ";
if (M_Locator_ID > 0)
sql += "WHERE l.M_Locator_ID = ?";
else
sql += "WHERE l.M_Warehouse_ID=?";
sql += " AND s.M_Product_ID=?"
+ " AND COALESCE(s.M_AttributeSetInstance_ID,0)=? ";
if (positiveOnly)
{
sql += " AND s.QtyOnHand > 0 ";
}
sql += "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
if (!FiFo)
sql += " DESC";
// All Attribute Set Instances
@ -266,19 +284,31 @@ public class MStorage extends X_M_Storage
+ "s.QtyOnHand,s.QtyReserved,s.QtyOrdered,s.DateLastInventory "
+ "FROM M_Storage s"
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID)"
+ " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) "
+ "WHERE l.M_Warehouse_ID=?"
+ " AND s.M_Product_ID=? ";
+ " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) ";
if (M_Locator_ID > 0)
sql += "WHERE l.M_Locator_ID = ?";
else
sql += "WHERE l.M_Warehouse_ID=?";
sql += " AND s.M_Product_ID=? ";
if (minGuaranteeDate != null)
{
sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) "
+ "ORDER BY asi.GuaranteeDate, M_AttributeSetInstance_ID";
sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) ";
if (positiveOnly)
{
sql += " AND s.QtyOnHand > 0 ";
}
sql += "ORDER BY l.PriorityNo DESC, " +
"asi.GuaranteeDate, M_AttributeSetInstance_ID";
if (!FiFo)
sql += " DESC";
sql += ", l.PriorityNo DESC, s.QtyOnHand DESC";
sql += ", s.QtyOnHand DESC";
}
else
{
if (positiveOnly)
{
sql += " AND s.QtyOnHand > 0 ";
}
sql += "ORDER BY l.PriorityNo DESC, l.M_Locator_ID, s.M_AttributeSetInstance_ID";
if (!FiFo)
sql += " DESC";
@ -290,12 +320,16 @@ public class MStorage extends X_M_Storage
try
{
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, M_Warehouse_ID);
pstmt.setInt(1, M_Locator_ID > 0 ? M_Locator_ID : M_Warehouse_ID);
pstmt.setInt(2, M_Product_ID);
if (!allAttributeInstances)
{
pstmt.setInt(3, M_AttributeSetInstance_ID);
}
else if (minGuaranteeDate != null)
{
pstmt.setTimestamp(3, minGuaranteeDate);
}
rs = pstmt.executeQuery();
while (rs.next())
list.add (new MStorage (ctx, rs, trxName));

File diff suppressed because it is too large Load Diff