Merge bug fix from branches/adempiere343
[ 2545020 ] Issuing of stock should ignore storage with onhand <= 0 [ 2566690 ] Create new ASI instead of using 0 when no QtyOnHand [ 2567104 ] Inventory move should allow movement between ASI
This commit is contained in:
parent
0900f687a5
commit
71ee570659
|
|
@ -102,9 +102,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
String MMPolicy = product.getMMPolicy();
|
String MMPolicy = product.getMMPolicy();
|
||||||
storages = MStorage.getWarehouse (order.getCtx(), order.getM_Warehouse_ID(),
|
storages = MStorage.getWarehouse (order.getCtx(), order.getM_Warehouse_ID(),
|
||||||
oLines[i].getM_Product_ID(), oLines[i].getM_AttributeSetInstance_ID(),
|
oLines[i].getM_Product_ID(), oLines[i].getM_AttributeSetInstance_ID(),
|
||||||
product.getM_AttributeSet_ID(),
|
minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, 0, trxName);
|
||||||
allAttributeInstances, minGuaranteeDate,
|
|
||||||
MClient.MMPOLICY_FiFo.equals(MMPolicy), trxName);
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1256,7 +1254,9 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
{
|
{
|
||||||
//Ignore the Material Policy when is Reverse Correction
|
//Ignore the Material Policy when is Reverse Correction
|
||||||
if(!isReversal())
|
if(!isReversal())
|
||||||
|
{
|
||||||
checkMaterialPolicy(sLine);
|
checkMaterialPolicy(sLine);
|
||||||
|
}
|
||||||
|
|
||||||
log.fine("Material Transaction");
|
log.fine("Material Transaction");
|
||||||
MTransaction mtrx = null;
|
MTransaction mtrx = null;
|
||||||
|
|
@ -1672,33 +1672,37 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
if (product != null && line.getM_AttributeSetInstance_ID() == 0)
|
if (product != null && line.getM_AttributeSetInstance_ID() == 0)
|
||||||
{
|
{
|
||||||
//Validate Transaction
|
//Validate Transaction
|
||||||
//if (inTrx)
|
|
||||||
if (getMovementType().compareTo(MInOut.MOVEMENTTYPE_CustomerReturns) == 0 || getMovementType().compareTo(MInOut.MOVEMENTTYPE_VendorReceipts) == 0 )
|
if (getMovementType().compareTo(MInOut.MOVEMENTTYPE_CustomerReturns) == 0 || getMovementType().compareTo(MInOut.MOVEMENTTYPE_VendorReceipts) == 0 )
|
||||||
{
|
{
|
||||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
|
MAttributeSetInstance asi = null;
|
||||||
asi.setClientOrg(getAD_Client_ID(), 0);
|
//auto balance negative on hand
|
||||||
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
|
MStorage[] storages = MStorage.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(), 0,
|
||||||
if (!asi.save())
|
null, MClient.MMPOLICY_FiFo.equals(product.getMMPolicy()), false, line.getM_Locator_ID(), get_TrxName());
|
||||||
|
for (MStorage storage : storages)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
if (storage.getQtyOnHand().signum() < 0)
|
||||||
|
{
|
||||||
|
asi = new MAttributeSetInstance(getCtx(), storage.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (asi.save())
|
}
|
||||||
|
//always create asi so fifo/lifo work.
|
||||||
|
if (asi == null)
|
||||||
{
|
{
|
||||||
|
asi = MAttributeSetInstance.create(getCtx(), product, get_TrxName());
|
||||||
|
}
|
||||||
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
||||||
log.config("New ASI=" + line);
|
log.config("New ASI=" + line);
|
||||||
needSave = true;
|
needSave = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Create consume the Attribute Set Instance using policy FIFO/LIFO
|
// Create consume the Attribute Set Instance using policy FIFO/LIFO
|
||||||
else if(getMovementType().compareTo(MInOut.MOVEMENTTYPE_VendorReturns) == 0 || getMovementType().compareTo(MInOut.MOVEMENTTYPE_CustomerShipment) == 0)
|
else if(getMovementType().compareTo(MInOut.MOVEMENTTYPE_VendorReturns) == 0 || getMovementType().compareTo(MInOut.MOVEMENTTYPE_CustomerShipment) == 0)
|
||||||
{
|
{
|
||||||
String MMPolicy = product.getMMPolicy();
|
String MMPolicy = product.getMMPolicy();
|
||||||
Timestamp minGuaranteeDate = getMovementDate();
|
Timestamp minGuaranteeDate = getMovementDate();
|
||||||
MStorage[] storages = MStorage.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(),
|
MStorage[] storages = MStorage.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
|
||||||
line.getM_AttributeSetInstance_ID(),
|
|
||||||
minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, line.getM_Locator_ID(), get_TrxName());
|
minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, line.getM_Locator_ID(), get_TrxName());
|
||||||
BigDecimal qtyToDeliver = line.getMovementQty();
|
BigDecimal qtyToDeliver = line.getMovementQty();
|
||||||
BigDecimal qtyNegativeOnhand = Env.ZERO;
|
|
||||||
for (MStorage storage: storages)
|
for (MStorage storage: storages)
|
||||||
{
|
{
|
||||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||||
|
|
@ -1706,39 +1710,39 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
MInOutLineMA ma = new MInOutLineMA (line,
|
MInOutLineMA ma = new MInOutLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
qtyToDeliver);
|
qtyToDeliver);
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
{
|
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
}
|
|
||||||
qtyToDeliver = Env.ZERO;
|
qtyToDeliver = Env.ZERO;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MInOutLineMA ma = new MInOutLineMA (line,
|
MInOutLineMA ma = new MInOutLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
storage.getQtyOnHand());
|
storage.getQtyOnHand());
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
{
|
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
}
|
|
||||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (qtyToDeliver.signum() == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qtyToDeliver.signum() != 0)
|
if (qtyToDeliver.signum() != 0)
|
||||||
{
|
{
|
||||||
MInOutLineMA ma = new MInOutLineMA (line, 0, qtyToDeliver);
|
//deliver using new asi
|
||||||
if (!ma.save())
|
MAttributeSetInstance asi = MAttributeSetInstance.create(getCtx(), product, get_TrxName());
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
int M_AttributeSetInstance_ID = asi.getM_AttributeSetInstance_ID();
|
||||||
|
MInOutLineMA ma = new MInOutLineMA (line, M_AttributeSetInstance_ID, qtyToDeliver);
|
||||||
|
ma.saveEx();
|
||||||
log.fine("##: " + ma);
|
log.fine("##: " + ma);
|
||||||
}
|
}
|
||||||
} // outgoing Trx
|
} // outgoing Trx
|
||||||
} // attributeSetInstance
|
} // attributeSetInstance
|
||||||
|
|
||||||
if (needSave && !line.save())
|
if (needSave)
|
||||||
log.severe("NOT saved " + line);
|
{
|
||||||
|
line.saveEx();
|
||||||
|
}
|
||||||
} // checkMaterialPolicy
|
} // checkMaterialPolicy
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@ import org.compiere.util.Msg;
|
||||||
*/
|
*/
|
||||||
public class MInventory extends X_M_Inventory implements DocAction
|
public class MInventory extends X_M_Inventory implements DocAction
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* generated serialVersionUID
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 6039577059413522140L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Inventory from Cache
|
* Get Inventory from Cache
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
|
@ -577,8 +583,6 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check Material Policy.
|
* Check Material Policy.
|
||||||
* (NOT USED)
|
|
||||||
* Sets line ASI
|
|
||||||
*/
|
*/
|
||||||
private void checkMaterialPolicy(MInventoryLine line, BigDecimal qtyDiff)
|
private void checkMaterialPolicy(MInventoryLine line, BigDecimal qtyDiff)
|
||||||
{
|
{
|
||||||
|
|
@ -586,7 +590,6 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
if (no > 0)
|
if (no > 0)
|
||||||
log.config("Delete old #" + no);
|
log.config("Delete old #" + no);
|
||||||
|
|
||||||
|
|
||||||
// Check Line
|
// Check Line
|
||||||
boolean needSave = false;
|
boolean needSave = false;
|
||||||
// Attribute Set Instance
|
// Attribute Set Instance
|
||||||
|
|
@ -595,19 +598,25 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
|
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
|
||||||
if (qtyDiff.signum() > 0) // Incoming Trx
|
if (qtyDiff.signum() > 0) // Incoming Trx
|
||||||
{
|
{
|
||||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
|
MAttributeSetInstance asi = null;
|
||||||
asi.setClientOrg(getAD_Client_ID(), 0);
|
//auto balance negative on hand
|
||||||
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
|
MStorage[] storages = MStorage.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(), 0,
|
||||||
if (!asi.save())
|
null, MClient.MMPOLICY_FiFo.equals(product.getMMPolicy()), false, line.getM_Locator_ID(), get_TrxName());
|
||||||
|
for (MStorage storage : storages)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
if (storage.getQtyOnHand().signum() < 0)
|
||||||
|
{
|
||||||
|
asi = new MAttributeSetInstance(getCtx(), storage.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (asi.save())
|
}
|
||||||
|
if (asi == null)
|
||||||
{
|
{
|
||||||
|
asi = MAttributeSetInstance.create(getCtx(), product, get_TrxName());
|
||||||
|
}
|
||||||
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
||||||
needSave = true;
|
needSave = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else // Outgoing Trx
|
else // Outgoing Trx
|
||||||
{
|
{
|
||||||
String MMPolicy = product.getMMPolicy();
|
String MMPolicy = product.getMMPolicy();
|
||||||
|
|
@ -623,41 +632,40 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
qtyToDeliver);
|
qtyToDeliver);
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
{
|
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
}
|
|
||||||
qtyToDeliver = Env.ZERO;
|
qtyToDeliver = Env.ZERO;
|
||||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
storage.getQtyOnHand());
|
storage.getQtyOnHand());
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
{
|
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
}
|
|
||||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
}
|
}
|
||||||
|
if (qtyToDeliver.signum() == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No AttributeSetInstance found for remainder
|
// No AttributeSetInstance found for remainder
|
||||||
if (qtyToDeliver.signum() != 0)
|
if (qtyToDeliver.signum() != 0)
|
||||||
{
|
{
|
||||||
MInventoryLineMA ma = new MInventoryLineMA (line, 0 , qtyToDeliver);
|
//deliver using new asi
|
||||||
|
MAttributeSetInstance asi = MAttributeSetInstance.create(getCtx(), product, get_TrxName());
|
||||||
|
int M_AttributeSetInstance_ID = asi.getM_AttributeSetInstance_ID();
|
||||||
|
MInventoryLineMA ma = new MInventoryLineMA (line, M_AttributeSetInstance_ID , qtyToDeliver);
|
||||||
|
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
log.fine("##: " + ma);
|
log.fine("##: " + ma);
|
||||||
}
|
}
|
||||||
} // outgoing Trx
|
} // outgoing Trx
|
||||||
|
|
||||||
if (needSave && !line.save())
|
if (needSave)
|
||||||
log.severe("NOT saved " + line);
|
{
|
||||||
|
line.saveEx();
|
||||||
|
}
|
||||||
} // for all lines
|
} // for all lines
|
||||||
|
|
||||||
} // checkMaterialPolicy
|
} // checkMaterialPolicy
|
||||||
|
|
|
||||||
|
|
@ -315,10 +315,6 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
m_processMsg = "@NoLines@";
|
m_processMsg = "@NoLines@";
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
// Add up Amounts
|
|
||||||
|
|
||||||
|
|
||||||
//checkMaterialPolicy();
|
|
||||||
|
|
||||||
// Confirmation
|
// Confirmation
|
||||||
if (dt.isInTransit())
|
if (dt.isInTransit())
|
||||||
|
|
@ -429,12 +425,6 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
{
|
{
|
||||||
MMovementLineMA ma = mas[j];
|
MMovementLineMA ma = mas[j];
|
||||||
//
|
//
|
||||||
/*MStorage storageFrom = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
|
||||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
|
||||||
if (storageFrom == null)
|
|
||||||
storageFrom = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
|
|
||||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
|
||||||
//*/
|
|
||||||
MLocator locator = new MLocator (getCtx(), line.getM_Locator_ID(), get_TrxName());
|
MLocator locator = new MLocator (getCtx(), line.getM_Locator_ID(), get_TrxName());
|
||||||
//Update Storage
|
//Update Storage
|
||||||
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||||
|
|
@ -447,39 +437,23 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*MStorage storageTo = MStorage.get(getCtx(), line.getM_LocatorTo_ID(),
|
int M_AttributeSetInstanceTo_ID = line.getM_AttributeSetInstanceTo_ID();
|
||||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
//only can be same asi if locator is different
|
||||||
if (storageTo == null)
|
if (M_AttributeSetInstanceTo_ID == 0 && line.getM_Locator_ID() != line.getM_LocatorTo_ID())
|
||||||
storageTo = MStorage.getCreate(getCtx(), line.getM_LocatorTo_ID(),
|
{
|
||||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
M_AttributeSetInstanceTo_ID = ma.getM_AttributeSetInstance_ID();
|
||||||
//*/
|
}
|
||||||
|
|
||||||
// MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
|
||||||
//Update Storage
|
//Update Storage
|
||||||
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||||
line.getM_LocatorTo_ID(),
|
line.getM_LocatorTo_ID(),
|
||||||
line.getM_Product_ID(),
|
line.getM_Product_ID(),
|
||||||
ma.getM_AttributeSetInstance_ID(), 0,
|
M_AttributeSetInstanceTo_ID, 0,
|
||||||
ma.getMovementQty(), Env.ZERO , Env.ZERO , get_TrxName()))
|
ma.getMovementQty(), Env.ZERO , Env.ZERO , get_TrxName()))
|
||||||
{
|
{
|
||||||
m_processMsg = "Cannot correct Inventory (MA)";
|
m_processMsg = "Cannot correct Inventory (MA)";
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*storageFrom.setQtyOnHand(storageFrom.getQtyOnHand().subtract(ma.getMovementQty()));
|
|
||||||
if (!storageFrom.save(get_TrxName()))
|
|
||||||
{
|
|
||||||
m_processMsg = "Storage From not updated (MA)";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
storageTo.setQtyOnHand(storageTo.getQtyOnHand().add(ma.getMovementQty()));
|
|
||||||
if (!storageTo.save(get_TrxName()))
|
|
||||||
{
|
|
||||||
m_processMsg = "Storage To not updated (MA)";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//
|
//
|
||||||
trxFrom = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
trxFrom = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
||||||
MTransaction.MOVEMENTTYPE_MovementFrom,
|
MTransaction.MOVEMENTTYPE_MovementFrom,
|
||||||
|
|
@ -494,7 +468,7 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
//
|
//
|
||||||
MTransaction trxTo = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
MTransaction trxTo = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
||||||
MTransaction.MOVEMENTTYPE_MovementTo,
|
MTransaction.MOVEMENTTYPE_MovementTo,
|
||||||
line.getM_LocatorTo_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
|
line.getM_LocatorTo_ID(), line.getM_Product_ID(), M_AttributeSetInstanceTo_ID,
|
||||||
ma.getMovementQty(), getMovementDate(), get_TrxName());
|
ma.getMovementQty(), getMovementDate(), get_TrxName());
|
||||||
trxTo.setM_MovementLine_ID(line.getM_MovementLine_ID());
|
trxTo.setM_MovementLine_ID(line.getM_MovementLine_ID());
|
||||||
if (!trxTo.save())
|
if (!trxTo.save())
|
||||||
|
|
@ -507,32 +481,6 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
// Fallback - We have ASI
|
// Fallback - We have ASI
|
||||||
if (trxFrom == null)
|
if (trxFrom == null)
|
||||||
{
|
{
|
||||||
/*MStorage storageFrom = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
|
||||||
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
|
|
||||||
if (storageFrom == null)
|
|
||||||
storageFrom = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
|
|
||||||
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
|
|
||||||
//
|
|
||||||
MStorage storageTo = MStorage.get(getCtx(), line.getM_LocatorTo_ID(),
|
|
||||||
line.getM_Product_ID(), line.getM_AttributeSetInstanceTo_ID(), get_TrxName());
|
|
||||||
if (storageTo == null)
|
|
||||||
storageTo = MStorage.getCreate(getCtx(), line.getM_LocatorTo_ID(),
|
|
||||||
line.getM_Product_ID(), line.getM_AttributeSetInstanceTo_ID(), get_TrxName());
|
|
||||||
//
|
|
||||||
storageFrom.setQtyOnHand(storageFrom.getQtyOnHand().subtract(line.getMovementQty()));
|
|
||||||
if (!storageFrom.save(get_TrxName()))
|
|
||||||
{
|
|
||||||
m_processMsg = "Storage From not updated";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
storageTo.setQtyOnHand(storageTo.getQtyOnHand().add(line.getMovementQty()));
|
|
||||||
if (!storageTo.save(get_TrxName()))
|
|
||||||
{
|
|
||||||
m_processMsg = "Storage To not updated";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
MLocator locator = new MLocator (getCtx(), line.getM_Locator_ID(), get_TrxName());
|
MLocator locator = new MLocator (getCtx(), line.getM_Locator_ID(), get_TrxName());
|
||||||
//Update Storage
|
//Update Storage
|
||||||
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||||
|
|
@ -545,12 +493,11 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
|
||||||
//Update Storage
|
//Update Storage
|
||||||
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||||
line.getM_LocatorTo_ID(),
|
line.getM_LocatorTo_ID(),
|
||||||
line.getM_Product_ID(),
|
line.getM_Product_ID(),
|
||||||
line.getM_AttributeSetInstance_ID(), 0,
|
line.getM_AttributeSetInstanceTo_ID(), 0,
|
||||||
line.getMovementQty(), Env.ZERO , Env.ZERO , get_TrxName()))
|
line.getMovementQty(), Env.ZERO , Env.ZERO , get_TrxName()))
|
||||||
{
|
{
|
||||||
m_processMsg = "Cannot correct Inventory (MA)";
|
m_processMsg = "Cannot correct Inventory (MA)";
|
||||||
|
|
@ -651,12 +598,7 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
int no = MMovementLineMA.deleteMovementMA(getM_Movement_ID(), get_TrxName());
|
int no = MMovementLineMA.deleteMovementMA(getM_Movement_ID(), get_TrxName());
|
||||||
if (no > 0)
|
if (no > 0)
|
||||||
log.config("Delete old #" + no);
|
log.config("Delete old #" + no);
|
||||||
//MMovementLine[] lines = getLines(false);
|
|
||||||
|
|
||||||
// Check Lines
|
|
||||||
//for (int i = 0; i < lines.length; i++)
|
|
||||||
//{
|
|
||||||
// MMovementLine line = lines[i];
|
|
||||||
boolean needSave = false;
|
boolean needSave = false;
|
||||||
|
|
||||||
// Attribute Set Instance
|
// Attribute Set Instance
|
||||||
|
|
@ -676,43 +618,39 @@ public class MMovement extends X_M_Movement implements DocAction
|
||||||
MMovementLineMA ma = new MMovementLineMA (line,
|
MMovementLineMA ma = new MMovementLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
qtyToDeliver);
|
qtyToDeliver);
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
{
|
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
}
|
|
||||||
qtyToDeliver = Env.ZERO;
|
qtyToDeliver = Env.ZERO;
|
||||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MMovementLineMA ma = new MMovementLineMA (line,
|
MMovementLineMA ma = new MMovementLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
storage.getQtyOnHand());
|
storage.getQtyOnHand());
|
||||||
if (!ma.save())
|
ma.saveEx();
|
||||||
{
|
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
|
||||||
}
|
|
||||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
}
|
}
|
||||||
|
if (qtyToDeliver.signum() == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No AttributeSetInstance found for remainder
|
// No AttributeSetInstance found for remainder
|
||||||
if (qtyToDeliver.signum() != 0)
|
if (qtyToDeliver.signum() != 0)
|
||||||
{
|
{
|
||||||
MMovementLineMA ma = new MMovementLineMA (line, 0 , qtyToDeliver);
|
//deliver using new asi
|
||||||
|
MAttributeSetInstance asi = MAttributeSetInstance.create(getCtx(), product, get_TrxName());
|
||||||
if (!ma.save())
|
int M_AttributeSetInstance_ID = asi.getM_AttributeSetInstance_ID();
|
||||||
throw new IllegalStateException("Error try create ASI Reservation");
|
MMovementLineMA ma = new MMovementLineMA (line, M_AttributeSetInstance_ID , qtyToDeliver);
|
||||||
|
ma.saveEx();
|
||||||
log.fine("##: " + ma);
|
log.fine("##: " + ma);
|
||||||
}
|
}
|
||||||
} // attributeSetInstance
|
} // attributeSetInstance
|
||||||
|
|
||||||
if (needSave && !line.save())
|
if (needSave)
|
||||||
log.severe("NOT saved " + line);
|
{
|
||||||
//} // for all lines
|
line.saveEx();
|
||||||
|
}
|
||||||
} // checkMaterialPolicy
|
} // checkMaterialPolicy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ public class MMovementLine extends X_M_MovementLine
|
||||||
public int getM_AttributeSetInstanceTo_ID ()
|
public int getM_AttributeSetInstanceTo_ID ()
|
||||||
{
|
{
|
||||||
int M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstanceTo_ID();
|
int M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstanceTo_ID();
|
||||||
if (M_AttributeSetInstanceTo_ID == 0)
|
if (M_AttributeSetInstanceTo_ID == 0 && (getM_Locator_ID() == getM_LocatorTo_ID()))
|
||||||
M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstance_ID();
|
M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstance_ID();
|
||||||
return M_AttributeSetInstanceTo_ID;
|
return M_AttributeSetInstanceTo_ID;
|
||||||
} // getM_AttributeSetInstanceTo_ID
|
} // getM_AttributeSetInstanceTo_ID
|
||||||
|
|
@ -174,9 +174,10 @@ public class MMovementLine extends X_M_MovementLine
|
||||||
setLine (ii);
|
setLine (ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getM_Locator_ID() == getM_LocatorTo_ID())
|
//either movement between locator or movement between lot
|
||||||
|
if (getM_Locator_ID() == getM_LocatorTo_ID() && getM_AttributeSetInstance_ID() == getM_AttributeSetInstanceTo_ID())
|
||||||
{
|
{
|
||||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@M_Locator_ID@ == @M_LocatorTo_ID@"));
|
log.saveError("Error", Msg.parseTranslation(getCtx(), "@M_Locator_ID@ == @M_LocatorTo_ID@ and @M_AttributeSetInstance_ID@ == @M_AttributeSetInstanceTo_ID@"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,16 +214,18 @@ public class MMovementLine extends X_M_MovementLine
|
||||||
}
|
}
|
||||||
if (getM_AttributeSetInstanceTo_ID() == 0)
|
if (getM_AttributeSetInstanceTo_ID() == 0)
|
||||||
{
|
{
|
||||||
if (getM_AttributeSetInstance_ID() != 0) // set to from
|
//instance id default to same for movement between locator
|
||||||
setM_AttributeSetInstanceTo_ID(getM_AttributeSetInstance_ID());
|
if (getM_Locator_ID() != getM_LocatorTo_ID())
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (product != null && product.isASIMandatory(true))
|
if (getM_AttributeSetInstance_ID() != 0) //set to from
|
||||||
|
setM_AttributeSetInstanceTo_ID(getM_AttributeSetInstance_ID());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (product != null && product.isASIMandatory(true) && getM_AttributeSetInstanceTo_ID() == 0)
|
||||||
{
|
{
|
||||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstanceTo_ID));
|
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstanceTo_ID));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} // ASI
|
} // ASI
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@ import org.compiere.util.Env;
|
||||||
*/
|
*/
|
||||||
public class MStorage extends X_M_Storage
|
public class MStorage extends X_M_Storage
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* generated serialVersionUID
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 9086223702645715061L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Storage Info
|
* Get Storage Info
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
|
@ -105,6 +110,8 @@ public class MStorage extends X_M_Storage
|
||||||
+ " AND M_AttributeSetInstance_ID > 0 "
|
+ " AND M_AttributeSetInstance_ID > 0 "
|
||||||
+ " AND QtyOnHand <> 0 "
|
+ " AND QtyOnHand <> 0 "
|
||||||
+ "ORDER BY M_AttributeSetInstance_ID";
|
+ "ORDER BY M_AttributeSetInstance_ID";
|
||||||
|
if (!FiFo)
|
||||||
|
sql += " DESC";
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
|
|
@ -273,6 +280,10 @@ public class MStorage extends X_M_Storage
|
||||||
{
|
{
|
||||||
sql += " AND s.QtyOnHand > 0 ";
|
sql += " AND s.QtyOnHand > 0 ";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql += " AND s.QtyOnHand <> 0 ";
|
||||||
|
}
|
||||||
sql += "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
|
sql += "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
|
||||||
if (!FiFo)
|
if (!FiFo)
|
||||||
sql += " DESC";
|
sql += " DESC";
|
||||||
|
|
@ -290,13 +301,17 @@ public class MStorage extends X_M_Storage
|
||||||
else
|
else
|
||||||
sql += "WHERE l.M_Warehouse_ID=?";
|
sql += "WHERE l.M_Warehouse_ID=?";
|
||||||
sql += " AND s.M_Product_ID=? ";
|
sql += " AND s.M_Product_ID=? ";
|
||||||
if (minGuaranteeDate != null)
|
|
||||||
{
|
|
||||||
sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) ";
|
|
||||||
if (positiveOnly)
|
if (positiveOnly)
|
||||||
{
|
{
|
||||||
sql += " AND s.QtyOnHand > 0 ";
|
sql += " AND s.QtyOnHand > 0 ";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql += " AND s.QtyOnHand <> 0 ";
|
||||||
|
}
|
||||||
|
if (minGuaranteeDate != null)
|
||||||
|
{
|
||||||
|
sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) ";
|
||||||
sql += "ORDER BY l.PriorityNo DESC, " +
|
sql += "ORDER BY l.PriorityNo DESC, " +
|
||||||
"asi.GuaranteeDate, M_AttributeSetInstance_ID";
|
"asi.GuaranteeDate, M_AttributeSetInstance_ID";
|
||||||
if (!FiFo)
|
if (!FiFo)
|
||||||
|
|
@ -305,10 +320,6 @@ public class MStorage extends X_M_Storage
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (positiveOnly)
|
|
||||||
{
|
|
||||||
sql += " AND s.QtyOnHand > 0 ";
|
|
||||||
}
|
|
||||||
sql += "ORDER BY l.PriorityNo DESC, l.M_Locator_ID, s.M_AttributeSetInstance_ID";
|
sql += "ORDER BY l.PriorityNo DESC, l.M_Locator_ID, s.M_AttributeSetInstance_ID";
|
||||||
if (!FiFo)
|
if (!FiFo)
|
||||||
sql += " DESC";
|
sql += " DESC";
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.MAttributeSet;
|
|
||||||
import org.compiere.model.MClient;
|
import org.compiere.model.MClient;
|
||||||
import org.compiere.model.MInOut;
|
import org.compiere.model.MInOut;
|
||||||
import org.compiere.model.MInOutLine;
|
import org.compiere.model.MInOutLine;
|
||||||
|
|
@ -465,6 +464,10 @@ public class InOutGenerate extends SvrProcess
|
||||||
{
|
{
|
||||||
MStorage storage = storages[i];
|
MStorage storage = storages[i];
|
||||||
BigDecimal deliver = toDeliver;
|
BigDecimal deliver = toDeliver;
|
||||||
|
//skip negative storage record
|
||||||
|
if (storage.getQtyOnHand().signum() < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Not enough On Hand
|
// Not enough On Hand
|
||||||
if (deliver.compareTo(storage.getQtyOnHand()) > 0
|
if (deliver.compareTo(storage.getQtyOnHand()) > 0
|
||||||
&& storage.getQtyOnHand().signum() >= 0) // positive storage
|
&& storage.getQtyOnHand().signum() >= 0) // positive storage
|
||||||
|
|
@ -557,7 +560,7 @@ public class InOutGenerate extends SvrProcess
|
||||||
{
|
{
|
||||||
m_lastStorages = MStorage.getWarehouse(getCtx(),
|
m_lastStorages = MStorage.getWarehouse(getCtx(),
|
||||||
M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,
|
M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,
|
||||||
minGuaranteeDate, FiFo,true, 0, get_TrxName());
|
minGuaranteeDate, FiFo,false, 0, get_TrxName());
|
||||||
m_map.put(m_lastPP, m_lastStorages);
|
m_map.put(m_lastPP, m_lastStorages);
|
||||||
}
|
}
|
||||||
return m_lastStorages;
|
return m_lastStorages;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue