IDEMPIERE-2629 M_StorageOnHand Qty and Total M_Transaction Qty did not match

This commit is contained in:
Carlos Ruiz 2015-06-24 20:28:52 -05:00
parent 4e16d1c353
commit c2c9e369b5
4 changed files with 65 additions and 41 deletions

View File

@ -507,7 +507,7 @@ public class InOutGenerate extends SvrProcess
throw new IllegalStateException("Could not create Shipment Line"); throw new IllegalStateException("Could not create Shipment Line");
if (log.isLoggable(Level.FINE)) log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line); if (log.isLoggable(Level.FINE)) log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
toDeliver = toDeliver.subtract(deliver); toDeliver = toDeliver.subtract(deliver);
// Temp adjustment, actual update happen in MInOut.completeIt // Temp adjustment, actual update happen in MInOut.completeIt - just in memory - not saved
storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver)); storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver));
// //
if (toDeliver.signum() == 0) if (toDeliver.signum() == 0)

View File

@ -120,11 +120,8 @@ public class MProductionLine extends X_M_ProductionLine {
} }
MStorageOnHand storage = MStorageOnHand.getCreate(getCtx(), getM_Locator_ID(), MStorageOnHand storage = MStorageOnHand.getCreate(getCtx(), getM_Locator_ID(),
getM_Product_ID(), asi.get_ID(),dateMPolicy, get_TrxName()); getM_Product_ID(), asi.get_ID(),dateMPolicy, get_TrxName());
storage.changeQtyOnHand(getMovementQty(), true); storage.addQtyOnHand(getMovementQty());
if ( !storage.save(get_TrxName()) ) { storage.load(storage.get_TrxName());
log.log(Level.SEVERE, "Could not update storage for " + toString());
errorString.append("Could not save transaction for " + toString() + "\n");
}
if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Created finished goods line " + getLine()); if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Created finished goods line " + getLine());
return errorString.toString(); return errorString.toString();
@ -182,11 +179,8 @@ public class MProductionLine extends X_M_ProductionLine {
if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Saved transaction for " + toString()); if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Saved transaction for " + toString());
} }
DB.getDatabase().forUpdate(storages[sl], 120); DB.getDatabase().forUpdate(storages[sl], 120);
storages[sl].changeQtyOnHand(lineQty, false); storages[sl].addQtyOnHand(lineQty.negate());
if ( !storages[sl].save(get_TrxName()) ) { storages[sl].load(storages[sl].get_TrxName());
log.log(Level.SEVERE, "Could not update storage for " + toString());
errorString.append("Could not update storage for " + toString() + "\n");
}
qtyToMove = qtyToMove.subtract(lineQty); qtyToMove = qtyToMove.subtract(lineQty);
if (log.isLoggable(Level.FINE))log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove ); if (log.isLoggable(Level.FINE))log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove );
} }
@ -244,11 +238,8 @@ public class MProductionLine extends X_M_ProductionLine {
} else { } else {
if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Saved transaction for " + toString()); if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Saved transaction for " + toString());
} }
storage.changeQtyOnHand(lineQty, false); storage.addQtyOnHand(lineQty.negate());
if ( !storage.save(get_TrxName()) ) { storage.load(storage.get_TrxName());
log.log(Level.SEVERE, "Could not update storage for " + toString());
errorString.append("Could not update storage for " + toString() + "\n");
}
qtyToMove = qtyToMove.subtract(lineQty); qtyToMove = qtyToMove.subtract(lineQty);
if (log.isLoggable(Level.FINE))log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove ); if (log.isLoggable(Level.FINE))log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove );
} }

View File

@ -27,6 +27,7 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -44,7 +45,7 @@ public class MStorageOnHand extends X_M_StorageOnHand
/** /**
* *
*/ */
private static final long serialVersionUID = -4934837951332485064L; private static final long serialVersionUID = -3820729340100521329L;
/** /**
* *
@ -735,15 +736,32 @@ public class MStorageOnHand extends X_M_StorageOnHand
return false; return false;
} }
storage.setQtyOnHand (storage.getQtyOnHand().add (diffQtyOnHand)); storage.addQtyOnHand(diffQtyOnHand);
storage.load(storage.get_TrxName());
if (storage.getQtyOnHand().signum() == -1) {
if (MWarehouse.get(Env.getCtx(), M_Warehouse_ID).isDisallowNegativeInv()) {
throw new AdempiereException(Msg.getMsg(ctx, "NegativeInventoryDisallowed"));
}
}
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());
s_log.fine(diffText.toString()); s_log.fine(diffText.toString());
} }
return storage.save (trxName); return true;
} // add } // add
/**
* Add quantity on hand directly - not using cached value - solving IDEMPIERE-2629
* @param addition
*/
public void addQtyOnHand(BigDecimal addition) {
final String sql = "UPDATE M_StorageOnHand SET QtyOnHand=QtyOnHand+?, Updated=SYSDATE, UpdatedBy=? " +
"WHERE M_Product_ID=? AND M_Locator_ID=? AND M_AttributeSetInstance_ID=? AND DateMaterialPolicy=?";
DB.executeUpdateEx(sql,
new Object[] {addition, Env.getAD_User_ID(Env.getCtx()), getM_Product_ID(), getM_Locator_ID(), getM_AttributeSetInstance_ID(), getDateMaterialPolicy()},
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
@ -854,21 +872,6 @@ public class MStorageOnHand extends X_M_StorageOnHand
/** Warehouse */ /** Warehouse */
private int m_M_Warehouse_ID = 0; private int m_M_Warehouse_ID = 0;
/**
* Change Qty OnHand
* @param qty quantity
* @param add add if true
*/
public void changeQtyOnHand (BigDecimal qty, boolean add)
{
if (qty == null || qty.signum() == 0)
return;
if (add)
setQtyOnHand(getQtyOnHand().add(qty));
else
setQtyOnHand(getQtyOnHand().subtract(qty));
} // changeQtyOnHand
/** /**
* Get M_Warehouse_ID of Locator * Get M_Warehouse_ID of Locator
* @return warehouse * @return warehouse
@ -997,8 +1000,9 @@ public class MStorageOnHand extends X_M_StorageOnHand
{ {
StringBuffer sb = new StringBuffer("MStorageOnHand[") StringBuffer sb = new StringBuffer("MStorageOnHand[")
.append("M_Locator_ID=").append(getM_Locator_ID()) .append("M_Locator_ID=").append(getM_Locator_ID())
.append(",M_Product_ID=").append(getM_Product_ID()) .append(",M_Product_ID=").append(getM_Product_ID())
.append(",M_AttributeSetInstance_ID=").append(getM_AttributeSetInstance_ID()) .append(",M_AttributeSetInstance_ID=").append(getM_AttributeSetInstance_ID())
.append(",DateMaterialPolicy=").append(getDateMaterialPolicy())
.append(": OnHand=").append(getQtyOnHand()) .append(": OnHand=").append(getQtyOnHand())
/* @win commented out /* @win commented out
.append(",Reserved=").append(getQtyReserved()) .append(",Reserved=").append(getQtyReserved())

View File

@ -30,7 +30,7 @@ public class MStorageReservation extends X_M_StorageReservation {
/** /**
* *
*/ */
private static final long serialVersionUID = -8646802850122507899L; private static final long serialVersionUID = 8179093165315835613L;
/** /**
* Get Storage Info * Get Storage Info
@ -248,14 +248,27 @@ public class MStorageReservation extends X_M_StorageReservation {
return false; return false;
} }
storage.setQty (storage.getQty().add(diffQty)); storage.addQty(diffQty);
storage.load(storage.get_TrxName());
if (s_log.isLoggable(Level.FINE)) { if (s_log.isLoggable(Level.FINE)) {
StringBuilder diffText = new StringBuilder("(Qty=").append(diffQty).append(") -> ").append(storage.toString()); StringBuilder diffText = new StringBuilder("(Qty=").append(diffQty).append(") -> ").append(storage.toString());
s_log.fine(diffText.toString()); s_log.fine(diffText.toString());
} }
return storage.save (trxName); return true;
} }
/**
* Add quantity on hand directly - not using cached value - solving IDEMPIERE-2629
* @param addition
*/
public void addQty(BigDecimal addition) {
final String sql = "UPDATE M_StorageReservation SET Qty=Qty+?, Updated=SYSDATE, UpdatedBy=? " +
"WHERE M_Product_ID=? AND M_Warehouse_ID=? AND M_AttributeSetInstance_ID=? AND IsSOTrx=?";
DB.executeUpdateEx(sql,
new Object[] {addition, Env.getAD_User_ID(Env.getCtx()), getM_Product_ID(), getM_Warehouse_ID(), getM_AttributeSetInstance_ID(), isSOTrx()},
get_TrxName());
}
/** /**
* Update Storage Info add. * Update Storage Info add.
* Called from MProjectIssue * Called from MProjectIssue
@ -309,4 +322,20 @@ public class MStorageReservation extends X_M_StorageReservation {
return retValue; return retValue;
} // getCreate } // getCreate
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MStorageReservation[")
.append("M_Warehouse_ID=").append(getM_Warehouse_ID())
.append(",M_Product_ID=").append(getM_Product_ID())
.append(",M_AttributeSetInstance_ID=").append(getM_AttributeSetInstance_ID())
.append(",IsSOTrx=").append(isSOTrx())
.append(": Qty=").append(getQty())
.append("]");
return sb.toString();
} // toString
} }