IDEMPIERE-3495 Project Issue Doesn't respect Material Policy

This commit is contained in:
Heng Sin Low 2017-09-20 16:03:29 +08:00
parent db66155f8d
commit 2734bf3f9f
1 changed files with 48 additions and 12 deletions

View File

@ -175,11 +175,57 @@ public class MProjectIssue extends X_C_ProjectIssue
dateMPolicy = t; dateMPolicy = t;
} }
boolean ok = true;
try try
{ {
if (MStorageOnHand.add(getCtx(), loc.getM_Warehouse_ID(), getM_Locator_ID(), if (getMovementQty().negate().signum() < 0)
{
String MMPolicy = product.getMMPolicy();
Timestamp minGuaranteeDate = getMovementDate();
int M_Warehouse_ID = getM_Locator_ID() > 0 ? getM_Locator().getM_Warehouse_ID() : getC_Project().getM_Warehouse_ID();
MStorageOnHand[] storages = MStorageOnHand.getWarehouse(getCtx(), M_Warehouse_ID, getM_Product_ID(), getM_AttributeSetInstance_ID(),
minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, getM_Locator_ID(), get_TrxName(), true);
BigDecimal qtyToIssue = getMovementQty();
for (MStorageOnHand storage: storages)
{
if (storage.getQtyOnHand().compareTo(qtyToIssue) >= 0)
{
storage.addQtyOnHand(qtyToIssue.negate());
qtyToIssue = BigDecimal.ZERO;
}
else
{
qtyToIssue = qtyToIssue.subtract(storage.getQtyOnHand());
storage.addQtyOnHand(storage.getQtyOnHand().negate());
}
if (qtyToIssue.signum() == 0)
break;
}
if (qtyToIssue.signum() > 0)
{
ok = MStorageOnHand.add(getCtx(), loc.getM_Warehouse_ID(), getM_Locator_ID(),
getM_Product_ID(), getM_AttributeSetInstance_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(),
getMovementQty().negate(),dateMPolicy, get_TrxName())) qtyToIssue.negate(),dateMPolicy, get_TrxName());
}
}
else
{
ok = MStorageOnHand.add(getCtx(), loc.getM_Warehouse_ID(), getM_Locator_ID(),
getM_Product_ID(), getM_AttributeSetInstance_ID(),
getMovementQty().negate(),dateMPolicy, get_TrxName());
}
}
catch (NegativeInventoryDisallowedException e)
{
log.severe(e.getMessage());
StringBuilder error = new StringBuilder();
error.append(Msg.getElement(getCtx(), "Line")).append(" ").append(getLine()).append(": ");
error.append(e.getMessage()).append("\n");
throw new AdempiereException(error.toString());
}
if (ok)
{ {
if (mTrx.save(get_TrxName())) if (mTrx.save(get_TrxName()))
{ {
@ -194,16 +240,6 @@ public class MProjectIssue extends X_C_ProjectIssue
} }
else else
log.log(Level.SEVERE, "Storage not updated"); // OK log.log(Level.SEVERE, "Storage not updated"); // OK
}
catch (NegativeInventoryDisallowedException e)
{
log.severe(e.getMessage());
StringBuilder error = new StringBuilder();
error.append(Msg.getElement(getCtx(), "Line")).append(" ").append(getLine()).append(": ");
error.append(e.getMessage()).append("\n");
throw new AdempiereException(error.toString());
}
// //
return false; return false;
} // process } // process