IDEMPIERE-386 Redesign ASI usage for FIFO. Improve backward compatibility. Ensure dateMPolicy is without time in the MStorageOnHand.* method that will create or update storage record.
This commit is contained in:
parent
216c61b9d9
commit
39247bf2f0
|
@ -121,17 +121,7 @@ public class CalloutMovement extends CalloutEngine
|
||||||
if (M_Locator_ID <= 0)
|
if (M_Locator_ID <= 0)
|
||||||
return;
|
return;
|
||||||
int M_AttributeSetInstance_ID = Env.getContextAsInt(ctx, WindowNo, "M_AttributeSetInstance_ID");
|
int M_AttributeSetInstance_ID = Env.getContextAsInt(ctx, WindowNo, "M_AttributeSetInstance_ID");
|
||||||
BigDecimal available = Env.ZERO;
|
BigDecimal available = MStorageOnHand.getQtyOnHandForLocator(M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID, null);
|
||||||
if (M_AttributeSetInstance_ID > 0) {
|
|
||||||
MStorageOnHand oh = MStorageOnHand.get(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, null,null);
|
|
||||||
if (oh != null)
|
|
||||||
available = oh.getQtyOnHand();
|
|
||||||
} else {
|
|
||||||
MStorageOnHand[] ohs = MStorageOnHand.getAll(ctx, M_Product_ID, M_Locator_ID, null);
|
|
||||||
for (MStorageOnHand oh : ohs) {
|
|
||||||
available = available.add(oh.getQtyOnHand());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (available == null)
|
if (available == null)
|
||||||
available = Env.ZERO;
|
available = Env.ZERO;
|
||||||
|
|
|
@ -509,7 +509,8 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
{
|
{
|
||||||
Timestamp dateMPolicy= getMovementDate();
|
Timestamp dateMPolicy= getMovementDate();
|
||||||
I_M_AttributeSetInstance asi = line.getM_AttributeSetInstance();
|
I_M_AttributeSetInstance asi = line.getM_AttributeSetInstance();
|
||||||
dateMPolicy =asi.getCreated();
|
if (asi != null)
|
||||||
|
dateMPolicy =asi.getCreated();
|
||||||
|
|
||||||
//Fallback: Update Storage - see also VMatch.createMatchRecord
|
//Fallback: Update Storage - see also VMatch.createMatchRecord
|
||||||
if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(),
|
if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(),
|
||||||
|
|
|
@ -46,6 +46,16 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -9202148574984537051L;
|
private static final long serialVersionUID = -9202148574984537051L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param ctx
|
||||||
|
* @param M_Locator_ID
|
||||||
|
* @param M_Product_ID
|
||||||
|
* @param M_AttributeSetInstance_ID
|
||||||
|
* @param trxName
|
||||||
|
* @deprecated
|
||||||
|
* @return MStorageOnHand
|
||||||
|
*/
|
||||||
public static MStorageOnHand get (Properties ctx, int M_Locator_ID,
|
public static MStorageOnHand get (Properties ctx, int M_Locator_ID,
|
||||||
int M_Product_ID, int M_AttributeSetInstance_ID, String trxName) {
|
int M_Product_ID, int M_AttributeSetInstance_ID, String trxName) {
|
||||||
return get (ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, null, trxName);
|
return get (ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, null, trxName);
|
||||||
|
@ -71,13 +81,23 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
sqlWhere += "M_AttributeSetInstance_ID=?";
|
sqlWhere += "M_AttributeSetInstance_ID=?";
|
||||||
|
|
||||||
if (dateMPolicy == null)
|
if (dateMPolicy == null)
|
||||||
dateMPolicy = new Timestamp(new Date().getTime());
|
{
|
||||||
|
if (M_AttributeSetInstance_ID > 0)
|
||||||
|
{
|
||||||
|
MAttributeSetInstance asi = new MAttributeSetInstance(ctx, M_AttributeSetInstance_ID, trxName);
|
||||||
|
dateMPolicy = asi.getCreated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateMPolicy != null)
|
||||||
|
sqlWhere += " AND DateMaterialPolicy=trunc(cast(? as date))";
|
||||||
|
|
||||||
sqlWhere += " AND DateMaterialPolicy=trunc(cast(? as date))";
|
Query query = new Query(ctx, MStorageOnHand.Table_Name, sqlWhere, trxName);
|
||||||
|
if (dateMPolicy != null)
|
||||||
MStorageOnHand retValue = new Query(ctx, MStorageOnHand.Table_Name, sqlWhere, trxName)
|
query.setParameters(M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, dateMPolicy);
|
||||||
.setParameters(M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, dateMPolicy)
|
else
|
||||||
.first();
|
query.setParameters(M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID);
|
||||||
|
MStorageOnHand retValue = query.first();
|
||||||
|
|
||||||
if (retValue == null) {
|
if (retValue == null) {
|
||||||
if (s_log.isLoggable(Level.FINE)) s_log.fine("Not Found - M_Locator_ID=" + M_Locator_ID
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("Not Found - M_Locator_ID=" + M_Locator_ID
|
||||||
|
@ -625,6 +645,8 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
if (dateMPolicy == null)
|
if (dateMPolicy == null)
|
||||||
dateMPolicy = new Timestamp(new Date().getTime());
|
dateMPolicy = new Timestamp(new Date().getTime());
|
||||||
|
|
||||||
|
dateMPolicy = Util.removeTime(dateMPolicy);
|
||||||
|
|
||||||
MStorageOnHand retValue = get(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy, trxName);
|
MStorageOnHand retValue = get(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy, trxName);
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
{
|
{
|
||||||
|
@ -644,7 +666,6 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getCreate
|
} // getCreate
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Storage Info add.
|
* Update Storage Info add.
|
||||||
* Called from MProjectIssue
|
* Called from MProjectIssue
|
||||||
|
@ -656,6 +677,28 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
* @param reservationAttributeSetInstance_ID reservation AS Instance
|
* @param reservationAttributeSetInstance_ID reservation AS Instance
|
||||||
* @param diffQtyOnHand add on hand
|
* @param diffQtyOnHand add on hand
|
||||||
* @param trxName transaction
|
* @param trxName transaction
|
||||||
|
* @deprecated
|
||||||
|
* @return true if updated
|
||||||
|
*/
|
||||||
|
public static boolean add (Properties ctx, int M_Warehouse_ID, int M_Locator_ID,
|
||||||
|
int M_Product_ID, int M_AttributeSetInstance_ID,
|
||||||
|
BigDecimal diffQtyOnHand, String trxName)
|
||||||
|
{
|
||||||
|
return add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, diffQtyOnHand, null, trxName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Storage Info add.
|
||||||
|
* Called from MProjectIssue
|
||||||
|
* @param ctx context
|
||||||
|
* @param M_Warehouse_ID warehouse
|
||||||
|
* @param M_Locator_ID locator
|
||||||
|
* @param M_Product_ID product
|
||||||
|
* @param M_AttributeSetInstance_ID AS Instance
|
||||||
|
* @param reservationAttributeSetInstance_ID reservation AS Instance
|
||||||
|
* @param diffQtyOnHand add on hand
|
||||||
|
* @param dateMPolicy
|
||||||
|
* @param trxName transaction
|
||||||
* @return true if updated
|
* @return true if updated
|
||||||
*/
|
*/
|
||||||
public static boolean add (Properties ctx, int M_Warehouse_ID, int M_Locator_ID,
|
public static boolean add (Properties ctx, int M_Warehouse_ID, int M_Locator_ID,
|
||||||
|
@ -665,8 +708,23 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
if (diffQtyOnHand == null || diffQtyOnHand.signum() == 0)
|
if (diffQtyOnHand == null || diffQtyOnHand.signum() == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (dateMPolicy == null)
|
||||||
|
{
|
||||||
|
if (M_AttributeSetInstance_ID > 0)
|
||||||
|
{
|
||||||
|
MAttributeSetInstance asi = new MAttributeSetInstance(ctx, M_AttributeSetInstance_ID, trxName);
|
||||||
|
dateMPolicy = asi.getCreated();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dateMPolicy = new Timestamp(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dateMPolicy = Util.removeTime(dateMPolicy);
|
||||||
|
|
||||||
// Get Storage
|
// Get Storage
|
||||||
MStorageOnHand storage = getCreate (ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,dateMPolicy, trxName, true, 120);
|
MStorageOnHand storage = getCreate (ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, dateMPolicy, trxName, true, 120);
|
||||||
// Verify
|
// Verify
|
||||||
if (storage.getM_Locator_ID() != M_Locator_ID
|
if (storage.getM_Locator_ID() != M_Locator_ID
|
||||||
&& storage.getM_Product_ID() != M_Product_ID
|
&& storage.getM_Product_ID() != M_Product_ID
|
||||||
|
@ -787,6 +845,7 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
setM_Locator_ID (locator.getM_Locator_ID());
|
setM_Locator_ID (locator.getM_Locator_ID());
|
||||||
setM_Product_ID (M_Product_ID);
|
setM_Product_ID (M_Product_ID);
|
||||||
setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID);
|
setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID);
|
||||||
|
dateMPolicy = Util.removeTime(dateMPolicy);
|
||||||
setDateMaterialPolicy(dateMPolicy);
|
setDateMaterialPolicy(dateMPolicy);
|
||||||
} // MStorageOnHand
|
} // MStorageOnHand
|
||||||
|
|
||||||
|
@ -874,7 +933,7 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
* @param M_Warehouse_ID
|
* @param M_Warehouse_ID
|
||||||
* @param M_AttributeSetInstance_ID
|
* @param M_AttributeSetInstance_ID
|
||||||
* @param trxName
|
* @param trxName
|
||||||
* @return
|
* @return QtyOnHand
|
||||||
*/
|
*/
|
||||||
public static BigDecimal getQtyOnHand(int M_Product_ID, int M_Warehouse_ID, int M_AttributeSetInstance_ID, String trxName) {
|
public static BigDecimal getQtyOnHand(int M_Product_ID, int M_Warehouse_ID, int M_AttributeSetInstance_ID, String trxName) {
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
|
@ -899,6 +958,37 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
return qty;
|
return qty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Quantity On Hand of Locator
|
||||||
|
* @param M_Product_ID
|
||||||
|
* @param M_Locator_ID
|
||||||
|
* @param M_AttributeSetInstance_ID
|
||||||
|
* @param trxName
|
||||||
|
* @return QtyOnHand
|
||||||
|
*/
|
||||||
|
public static BigDecimal getQtyOnHandForLocator(int M_Product_ID, int M_Locator_ID, int M_AttributeSetInstance_ID, String trxName) {
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
sql.append(" SELECT SUM(oh.QtyOnHand) FROM M_StorageOnHand oh")
|
||||||
|
.append(" WHERE oh.M_Product_ID=?")
|
||||||
|
.append(" AND oh.M_Locator_ID=?");
|
||||||
|
|
||||||
|
ArrayList<Object> params = new ArrayList<Object>();
|
||||||
|
params.add(M_Product_ID);
|
||||||
|
params.add(M_Locator_ID);
|
||||||
|
|
||||||
|
// With ASI
|
||||||
|
if (M_AttributeSetInstance_ID != 0) {
|
||||||
|
sql.append(" AND oh.M_AttributeSetInstance_ID=?");
|
||||||
|
params.add(M_AttributeSetInstance_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal qty = DB.getSQLValueBD(trxName, sql.toString(), params);
|
||||||
|
if (qty == null)
|
||||||
|
qty = Env.ZERO;
|
||||||
|
|
||||||
|
return qty;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Representation
|
* String Representation
|
||||||
* @return info
|
* @return info
|
||||||
|
|
Loading…
Reference in New Issue