IDEMPIERE-1999 Adding support for over shipment.

This commit is contained in:
Deepak Pansheriya 2014-06-19 22:50:37 +08:00
parent ec78079e40
commit 97dabc75b5
3 changed files with 80 additions and 101 deletions

View File

@ -758,10 +758,9 @@ public class MInOut extends X_M_InOut implements DocAction
line.setM_RMALine_ID(peer.getRef_RMALine_ID()); line.setM_RMALine_ID(peer.getRef_RMALine_ID());
} }
} }
else if (!isSOTrx())
{ line.setQtyOverReceipt(fromLine.getQtyOverReceipt());
line.setQtyOverReceipt(fromLine.getQtyOverReceipt());
}
// //
line.setProcessed(false); line.setProcessed(false);
if (line.save(get_TrxName())) if (line.save(get_TrxName()))
@ -1290,7 +1289,6 @@ public class MInOut extends X_M_InOut implements DocAction
BigDecimal Qty = sLine.getMovementQty(); BigDecimal Qty = sLine.getMovementQty();
if (MovementType.charAt(1) == '-') // C- Customer Shipment - V- Vendor Return if (MovementType.charAt(1) == '-') // C- Customer Shipment - V- Vendor Return
Qty = Qty.negate(); Qty = Qty.negate();
BigDecimal QtySO = Env.ZERO;
// Update Order Line // Update Order Line
MOrderLine oLine = null; MOrderLine oLine = null;
@ -1299,8 +1297,6 @@ public class MInOut extends X_M_InOut implements DocAction
oLine = new MOrderLine (getCtx(), sLine.getC_OrderLine_ID(), get_TrxName()); oLine = new MOrderLine (getCtx(), sLine.getC_OrderLine_ID(), get_TrxName());
if (log.isLoggable(Level.FINE)) log.fine("OrderLine - Reserved=" + oLine.getQtyReserved() if (log.isLoggable(Level.FINE)) log.fine("OrderLine - Reserved=" + oLine.getQtyReserved()
+ ", Delivered=" + oLine.getQtyDelivered()); + ", Delivered=" + oLine.getQtyDelivered());
if (isSOTrx())
QtySO = sLine.getMovementQty();
} }
@ -1326,41 +1322,29 @@ public class MInOut extends X_M_InOut implements DocAction
log.fine("Material Transaction"); log.fine("Material Transaction");
MTransaction mtrx = null; MTransaction mtrx = null;
//same warehouse in order and receipt?
boolean sameWarehouse = true;
// Reservation ASI - assume none
int reservationAttributeSetInstance_ID = 0; // sLine.getM_AttributeSetInstance_ID();
int reservationWarehouse_ID = getM_Warehouse_ID();
if (oLine != null) {
reservationAttributeSetInstance_ID = oLine.getM_AttributeSetInstance_ID();
sameWarehouse = oLine.getM_Warehouse_ID()==getM_Warehouse_ID();
}
if(!sameWarehouse){
reservationWarehouse_ID = oLine.getM_Warehouse_ID();
}
// //
BigDecimal overReceipt = BigDecimal.ZERO; BigDecimal overReceipt = BigDecimal.ZERO;
if (!isSOTrx()) if (!isReversal())
{ {
if (!isReversal()) if (oLine != null)
{ {
if (oLine != null) BigDecimal toDelivered = oLine.getQtyOrdered()
.subtract(oLine.getQtyDelivered());
if (sLine.getMovementQty().compareTo(toDelivered) > 0)
overReceipt = sLine.getMovementQty().subtract(
toDelivered);
if (overReceipt.signum() != 0)
{ {
BigDecimal toDelivered = oLine.getQtyOrdered().subtract(oLine.getQtyDelivered()); sLine.setQtyOverReceipt(overReceipt);
if (sLine.getMovementQty().compareTo(toDelivered) > 0) sLine.saveEx();
overReceipt = sLine.getMovementQty().subtract(toDelivered);
if (overReceipt.signum() != 0)
{
sLine.setQtyOverReceipt(overReceipt);
sLine.saveEx();
}
} }
} }
else }
{ else
overReceipt = sLine.getQtyOverReceipt(); {
} overReceipt = sLine.getQtyOverReceipt();
} }
BigDecimal orderedQtyToUpdate = sLine.getMovementQty().subtract(overReceipt); BigDecimal orderedQtyToUpdate = sLine.getMovementQty().subtract(overReceipt);
// //
if (sLine.getM_AttributeSetInstance_ID() == 0) if (sLine.getM_AttributeSetInstance_ID() == 0)
@ -1373,27 +1357,6 @@ public class MInOut extends X_M_InOut implements DocAction
BigDecimal QtyMA = ma.getMovementQty(); BigDecimal QtyMA = ma.getMovementQty();
if (MovementType.charAt(1) == '-') // C- Customer Shipment - V- Vendor Return if (MovementType.charAt(1) == '-') // C- Customer Shipment - V- Vendor Return
QtyMA = QtyMA.negate(); QtyMA = QtyMA.negate();
BigDecimal reservedDiff = Env.ZERO;
if (sLine.getC_OrderLine_ID() != 0)
{
if (isSOTrx())
{
reservedDiff = ma.getMovementQty().negate();
}
else
{
if (orderedQtyToUpdate.compareTo(ma.getMovementQty()) >= 0)
{
orderedQtyToUpdate = orderedQtyToUpdate.subtract(ma.getMovementQty());
reservedDiff = ma.getMovementQty().negate();
}
else
{
reservedDiff = orderedQtyToUpdate.negate();
orderedQtyToUpdate = BigDecimal.ZERO;
}
}
}
// Update Storage - see also VMatch.createMatchRecord // Update Storage - see also VMatch.createMatchRecord
if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(), if (!MStorageOnHand.add(getCtx(), getM_Warehouse_ID(),
@ -1406,20 +1369,7 @@ public class MInOut extends X_M_InOut implements DocAction
String lastError = CLogger.retrieveErrorString(""); String lastError = CLogger.retrieveErrorString("");
m_processMsg = "Cannot correct Inventory OnHand (MA) [" + product.getValue() + "] - " + lastError; m_processMsg = "Cannot correct Inventory OnHand (MA) [" + product.getValue() + "] - " + lastError;
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
if (reservedDiff.signum() != 0) {
if (!MStorageReservation.add(getCtx(), reservationWarehouse_ID,
sLine.getM_Product_ID(),
ma.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID,
reservedDiff,
isSOTrx(),
get_TrxName()))
{
String lastError = CLogger.retrieveErrorString("");
m_processMsg = "Cannot correct Inventory " + (isSOTrx()? "Reserved" : "Ordered") + " (MA) - [" + product.getValue() + "] - " + lastError;
return DocAction.STATUS_Invalid;
}
}
// Create Transaction // Create Transaction
mtrx = new MTransaction (getCtx(), sLine.getAD_Org_ID(), mtrx = new MTransaction (getCtx(), sLine.getAD_Org_ID(),
@ -1433,16 +1383,29 @@ public class MInOut extends X_M_InOut implements DocAction
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
} }
if (oLine!=null && mtrx!=null)
{
if (sLine.getC_OrderLine_ID() != 0)
{
if (!MStorageReservation.add(getCtx(), oLine.getM_Warehouse_ID(),
sLine.getM_Product_ID(),
oLine.getM_AttributeSetInstance_ID(),
orderedQtyToUpdate.negate(),
isSOTrx(),
get_TrxName()))
{
String lastError = CLogger.retrieveErrorString("");
m_processMsg = "Cannot correct Inventory " + (isSOTrx()? "Reserved" : "Ordered") + " (MA) - [" + product.getValue() + "] - " + lastError;
return DocAction.STATUS_Invalid;
}
}
}
} }
// sLine.getM_AttributeSetInstance_ID() != 0 // sLine.getM_AttributeSetInstance_ID() != 0
if (mtrx == null) if (mtrx == null)
{ {
BigDecimal reservedDiff = null;
if(isSOTrx())
reservedDiff = QtySO.negate();
else
reservedDiff = orderedQtyToUpdate.negate();
Timestamp dateMPolicy = getMovementDate(); Timestamp dateMPolicy = getMovementDate();
if(sLine.getM_AttributeSetInstance_ID()>0){ if(sLine.getM_AttributeSetInstance_ID()>0){
I_M_AttributeSetInstance asi = sLine.getM_AttributeSetInstance(); I_M_AttributeSetInstance asi = sLine.getM_AttributeSetInstance();
@ -1460,11 +1423,12 @@ public class MInOut extends X_M_InOut implements DocAction
m_processMsg = "Cannot correct Inventory OnHand [" + product.getValue() + "] - " + lastError; m_processMsg = "Cannot correct Inventory OnHand [" + product.getValue() + "] - " + lastError;
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
if (reservedDiff.signum() != 0) { if (oLine!=null)
if (!MStorageReservation.add(getCtx(), reservationWarehouse_ID, {
if (!MStorageReservation.add(getCtx(), oLine.getM_Warehouse_ID(),
sLine.getM_Product_ID(), sLine.getM_Product_ID(),
sLine.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, oLine.getM_AttributeSetInstance_ID(),
reservedDiff, isSOTrx(), get_TrxName())) orderedQtyToUpdate.negate(), isSOTrx(), get_TrxName()))
{ {
m_processMsg = "Cannot correct Inventory Reserved " + (isSOTrx()? "Reserved [" :"Ordered [") + product.getValue() + "]"; m_processMsg = "Cannot correct Inventory Reserved " + (isSOTrx()? "Reserved [" :"Ordered [") + product.getValue() + "]";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;

View File

@ -1747,7 +1747,7 @@ public class MOrder extends X_C_Order implements DocAction
// Update Reservation Storage // Update Reservation Storage
if (!MStorageReservation.add(getCtx(), line.getM_Warehouse_ID(), if (!MStorageReservation.add(getCtx(), line.getM_Warehouse_ID(),
line.getM_Product_ID(), line.getM_Product_ID(),
line.getM_AttributeSetInstance_ID(), line.getM_AttributeSetInstance_ID(), line.getM_AttributeSetInstance_ID(),
difference, isSOTrx, get_TrxName())) difference, isSOTrx, get_TrxName()))
return false; return false;
} // stocked } // stocked

View File

@ -210,22 +210,20 @@ public class MStorageReservation extends X_M_StorageReservation {
} }
/** /**
* Update Storage Info add. *
* Called from MProjectIssue * @param ctx
* @param ctx context * @param M_Warehouse_ID
* @param M_Warehouse_ID warehouse * @param M_Product_ID
* @param M_Product_ID product * @param M_AttributeSetInstance_ID
* @param M_AttributeSetInstance_ID AS Instance * @param diffQty
* @param reservationAttributeSetInstance_ID reservation AS Instance * @param isSOTrx
* @param diffQty add * @param trxName
* @param isSOTrx * @return
* @param trxName transaction
* @return true if updated
*/ */
public static boolean add (Properties ctx, int M_Warehouse_ID, public static boolean add (Properties ctx, int M_Warehouse_ID,
int M_Product_ID, int M_AttributeSetInstance_ID, int reservationAttributeSetInstance_ID, int M_Product_ID, int M_AttributeSetInstance_ID,
BigDecimal diffQty, boolean isSOTrx, String trxName) BigDecimal diffQty, boolean isSOTrx, String trxName){
{
if (diffQty == null || diffQty.signum() == 0) if (diffQty == null || diffQty.signum() == 0)
return true; return true;
@ -233,13 +231,8 @@ public class MStorageReservation extends X_M_StorageReservation {
MProduct prd = new MProduct(ctx, M_Product_ID, trxName); MProduct prd = new MProduct(ctx, M_Product_ID, trxName);
if (prd.getM_AttributeSet_ID() == 0 || ! prd.getM_AttributeSet().isInstanceAttribute()) { if (prd.getM_AttributeSet_ID() == 0 || ! prd.getM_AttributeSet().isInstanceAttribute()) {
// Product doesn't manage attribute set, always reserved with 0 // Product doesn't manage attribute set, always reserved with 0
reservationAttributeSetInstance_ID = 0;
M_AttributeSetInstance_ID = 0; M_AttributeSetInstance_ID = 0;
} }
//
if (M_AttributeSetInstance_ID != reservationAttributeSetInstance_ID) {
M_AttributeSetInstance_ID = reservationAttributeSetInstance_ID;
}
// Get Storage // Get Storage
MStorageReservation storage = getCreate (ctx, M_Warehouse_ID, MStorageReservation storage = getCreate (ctx, M_Warehouse_ID,
@ -261,6 +254,28 @@ public class MStorageReservation extends X_M_StorageReservation {
s_log.fine(diffText.toString()); s_log.fine(diffText.toString());
} }
return storage.save (trxName); return storage.save (trxName);
}
/**
* Update Storage Info add.
* Called from MProjectIssue
* @param ctx context
* @param M_Warehouse_ID warehouse
* @param M_Product_ID product
* @param M_AttributeSetInstance_ID AS Instance
* @param reservationAttributeSetInstance_ID reservation AS Instance
* @param diffQty add
* @param isSOTrx
* @param trxName transaction
* @return true if updated
*/
@Deprecated
public static boolean add (Properties ctx, int M_Warehouse_ID,
int M_Product_ID, int M_AttributeSetInstance_ID, int reservationAttributeSetInstance_ID,
BigDecimal diffQty, boolean isSOTrx, String trxName)
{
return add(ctx, M_Warehouse_ID, M_Product_ID, reservationAttributeSetInstance_ID, diffQty, isSOTrx, trxName);
} // add } // add
/** /**