IDEMPIERE-5483 - Physical Inventory Doesn't Update Last Inventory Date on Specific Cases (#1575)
* IDEMPIERE-5483 - Physical Inventory Doesn't Update Last Inventory Date on Specific Cases * IDEMPIERE-5483 - requested changes * IDEMPIERE-5483 - fixes * IDEMPIERE-5483 - fixed fallen test case
This commit is contained in:
parent
8e886a26d6
commit
253125b60a
|
@ -526,6 +526,34 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
}
|
}
|
||||||
|
|
||||||
//If Quantity Count minus Quantity Book = Zero, then no change in Inventory
|
//If Quantity Count minus Quantity Book = Zero, then no change in Inventory
|
||||||
|
if(MDocType.DOCSUBTYPEINV_PhysicalInventory.equals(docSubTypeInv) && !isReversal()) {
|
||||||
|
// We want to update Date Last Inventory on this records as well.
|
||||||
|
if (line.getM_AttributeSetInstance_ID() == 0 ) {
|
||||||
|
MStorageOnHand[] storages = MStorageOnHand.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(), 0,
|
||||||
|
null, MClient.MMPOLICY_FiFo.equals(product.getMMPolicy()), true, line.getM_Locator_ID(), get_TrxName(), false);
|
||||||
|
if(storages != null) {
|
||||||
|
for(MStorageOnHand storage: storages) {
|
||||||
|
storage.setDateLastInventory(getMovementDate());
|
||||||
|
if (!storage.save(get_TrxName())) {
|
||||||
|
m_processMsg = "Storage on hand not updated for DateLastInventory";
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MStorageOnHand[] storages = MStorageOnHand.getAll(getCtx(), line.getM_Product_ID(),
|
||||||
|
line.getM_Locator_ID(), line.getM_AttributeSetInstance_ID(), null, false, get_TrxName());
|
||||||
|
if(storages != null) {
|
||||||
|
for(MStorageOnHand storage: storages) {
|
||||||
|
storage.setDateLastInventory(getMovementDate());
|
||||||
|
if (!storage.save(get_TrxName())) {
|
||||||
|
m_processMsg = "Storage on hand not updated for DateLastInventory";
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (qtyDiff.signum() == 0)
|
if (qtyDiff.signum() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -571,26 +599,13 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
line.getM_Locator_ID(),
|
line.getM_Locator_ID(),
|
||||||
line.getM_Product_ID(),
|
line.getM_Product_ID(),
|
||||||
ma.getM_AttributeSetInstance_ID(),
|
ma.getM_AttributeSetInstance_ID(),
|
||||||
QtyMA.negate(),ma.getDateMaterialPolicy(), get_TrxName()))
|
QtyMA.negate(),ma.getDateMaterialPolicy(), getMovementDate(), get_TrxName()))
|
||||||
{
|
{
|
||||||
String lastError = CLogger.retrieveErrorString("");
|
String lastError = CLogger.retrieveErrorString("");
|
||||||
m_processMsg = "Cannot correct Inventory (MA) - " + lastError;
|
m_processMsg = "Cannot correct Inventory (MA) - " + lastError;
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only Update Date Last Inventory if is a Physical Inventory
|
|
||||||
if (MDocType.DOCSUBTYPEINV_PhysicalInventory.equals(docSubTypeInv))
|
|
||||||
{
|
|
||||||
MStorageOnHand storage = MStorageOnHand.get(getCtx(), line.getM_Locator_ID(),
|
|
||||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),ma.getDateMaterialPolicy(),get_TrxName());
|
|
||||||
storage.setDateLastInventory(getMovementDate());
|
|
||||||
if (!storage.save(get_TrxName()))
|
|
||||||
{
|
|
||||||
m_processMsg = "Storage not updated(2)";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String m_MovementType =null;
|
String m_MovementType =null;
|
||||||
if(QtyMA.negate().compareTo(Env.ZERO) > 0 )
|
if(QtyMA.negate().compareTo(Env.ZERO) > 0 )
|
||||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
||||||
|
@ -629,27 +644,13 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
line.getM_Locator_ID(),
|
line.getM_Locator_ID(),
|
||||||
line.getM_Product_ID(),
|
line.getM_Product_ID(),
|
||||||
line.getM_AttributeSetInstance_ID(),
|
line.getM_AttributeSetInstance_ID(),
|
||||||
qtyDiff,dateMPolicy,get_TrxName()))
|
qtyDiff,dateMPolicy,getMovementDate(),get_TrxName()))
|
||||||
{
|
{
|
||||||
String lastError = CLogger.retrieveErrorString("");
|
String lastError = CLogger.retrieveErrorString("");
|
||||||
m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError;
|
m_processMsg = "Cannot correct Inventory OnHand (MA) - " + lastError;
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only Update Date Last Inventory if is a Physical Inventory
|
|
||||||
if (MDocType.DOCSUBTYPEINV_PhysicalInventory.equals(docSubTypeInv))
|
|
||||||
{
|
|
||||||
MStorageOnHand storage = MStorageOnHand.get(getCtx(), line.getM_Locator_ID(),
|
|
||||||
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),dateMPolicy, get_TrxName());
|
|
||||||
|
|
||||||
storage.setDateLastInventory(getMovementDate());
|
|
||||||
if (!storage.save(get_TrxName()))
|
|
||||||
{
|
|
||||||
m_processMsg = "Storage not updated(2)";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String m_MovementType = null;
|
String m_MovementType = null;
|
||||||
if(qtyDiff.compareTo(Env.ZERO) > 0 )
|
if(qtyDiff.compareTo(Env.ZERO) > 0 )
|
||||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
||||||
|
|
|
@ -242,7 +242,55 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
list.toArray(retValue);
|
list.toArray(retValue);
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getAll
|
} // getAll
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Storage Info
|
||||||
|
* @param ctx context
|
||||||
|
* @param M_Product_ID product
|
||||||
|
* @param M_Locator_ID locator
|
||||||
|
* @param M_AttributeSetInstance_ID instance
|
||||||
|
* @param dateMPolicy
|
||||||
|
* @param ignoreZeroQty
|
||||||
|
* @param trxName transaction
|
||||||
|
* @return existing or null
|
||||||
|
*/
|
||||||
|
public static MStorageOnHand[] getAll (Properties ctx,
|
||||||
|
int M_Product_ID, int M_Locator_ID, int M_AttributeSetInstance_ID, Timestamp dateMPolicy, boolean ignoreZeroQty, String trxName)
|
||||||
|
{
|
||||||
|
String sqlWhere = "M_Locator_ID=? AND M_Product_ID=? AND ";
|
||||||
|
|
||||||
|
if (M_AttributeSetInstance_ID == 0)
|
||||||
|
sqlWhere += "(M_AttributeSetInstance_ID=? OR M_AttributeSetInstance_ID IS NULL)";
|
||||||
|
else
|
||||||
|
sqlWhere += "M_AttributeSetInstance_ID=?";
|
||||||
|
|
||||||
|
if(ignoreZeroQty)
|
||||||
|
sqlWhere += " AND QtyOnHand<>0 ";
|
||||||
|
|
||||||
|
if (dateMPolicy != null)
|
||||||
|
sqlWhere += " AND DateMaterialPolicy=trunc(cast(? as date))";
|
||||||
|
|
||||||
|
Query query = new Query(ctx, MStorageOnHand.Table_Name, sqlWhere, trxName);
|
||||||
|
|
||||||
|
if (dateMPolicy != null)
|
||||||
|
query.setParameters(M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, dateMPolicy);
|
||||||
|
else
|
||||||
|
query.setParameters(M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID);
|
||||||
|
|
||||||
|
List<MStorageOnHand> list = query.list();
|
||||||
|
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("Not Found - M_Locator_ID=" + M_Locator_ID
|
||||||
|
+ ", M_Product_ID=" + M_Product_ID + ", M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
|
||||||
|
} else {
|
||||||
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("Found " + list.size() + " - M_Locator_ID=" + M_Locator_ID
|
||||||
|
+ ", M_Product_ID=" + M_Product_ID + ", M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
MStorageOnHand[] retValue = new MStorageOnHand[list.size()];
|
||||||
|
list.toArray(retValue);
|
||||||
|
return retValue;
|
||||||
|
} // getAll
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Storage Info for Product across warehouses
|
* Get Storage Info for Product across warehouses
|
||||||
|
@ -739,7 +787,14 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
int M_Product_ID, int M_AttributeSetInstance_ID,
|
int M_Product_ID, int M_AttributeSetInstance_ID,
|
||||||
BigDecimal diffQtyOnHand,Timestamp dateMPolicy, String trxName)
|
BigDecimal diffQtyOnHand,Timestamp dateMPolicy, String trxName)
|
||||||
{
|
{
|
||||||
return add(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, diffQtyOnHand, dateMPolicy, trxName);
|
return add(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, diffQtyOnHand, dateMPolicy, null, trxName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean add (Properties ctx, int M_Locator_ID,
|
||||||
|
int M_Product_ID, int M_AttributeSetInstance_ID,
|
||||||
|
BigDecimal diffQtyOnHand,Timestamp dateMPolicy, String trxName)
|
||||||
|
{
|
||||||
|
return add(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, diffQtyOnHand, dateMPolicy, null, trxName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -756,7 +811,7 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
*/
|
*/
|
||||||
public static boolean add (Properties ctx, int M_Locator_ID,
|
public static boolean add (Properties ctx, int M_Locator_ID,
|
||||||
int M_Product_ID, int M_AttributeSetInstance_ID,
|
int M_Product_ID, int M_AttributeSetInstance_ID,
|
||||||
BigDecimal diffQtyOnHand,Timestamp dateMPolicy, String trxName)
|
BigDecimal diffQtyOnHand,Timestamp dateMPolicy, Timestamp dateLastInventory, String trxName)
|
||||||
{
|
{
|
||||||
if (diffQtyOnHand == null || diffQtyOnHand.signum() == 0)
|
if (diffQtyOnHand == null || diffQtyOnHand.signum() == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -776,6 +831,8 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(dateLastInventory != null)
|
||||||
|
storage.updateDateLastInventory(dateLastInventory);
|
||||||
storage.addQtyOnHand(diffQtyOnHand);
|
storage.addQtyOnHand(diffQtyOnHand);
|
||||||
if (s_log.isLoggable(Level.FINE)) {
|
if (s_log.isLoggable(Level.FINE)) {
|
||||||
StringBuilder diffText = new StringBuilder("(OnHand=").append(diffQtyOnHand).append(") -> ").append(storage.toString());
|
StringBuilder diffText = new StringBuilder("(OnHand=").append(diffQtyOnHand).append(") -> ").append(storage.toString());
|
||||||
|
@ -804,6 +861,19 @@ public class MStorageOnHand extends X_M_StorageOnHand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Date Last Inventory
|
||||||
|
* @param dateLastInv
|
||||||
|
*/
|
||||||
|
public void updateDateLastInventory(Timestamp dateLastInv) {
|
||||||
|
final String sql = "UPDATE M_StorageOnHand SET DateLastInventory=? " +
|
||||||
|
"WHERE M_Product_ID=? AND M_Locator_ID=? AND M_AttributeSetInstance_ID=? AND DateMaterialPolicy=?";
|
||||||
|
DB.executeUpdateEx(sql,
|
||||||
|
new Object[] {dateLastInv, getM_Product_ID(), getM_Locator_ID(), getM_AttributeSetInstance_ID(), getDateMaterialPolicy()},
|
||||||
|
get_TrxName());
|
||||||
|
load(get_TrxName());
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Get Location with highest Locator Priority and a sufficient OnHand Qty
|
* Get Location with highest Locator Priority and a sufficient OnHand Qty
|
||||||
* @param M_Warehouse_ID warehouse
|
* @param M_Warehouse_ID warehouse
|
||||||
|
|
Loading…
Reference in New Issue