MInOut: BF [ 1884379 ] MM Doc: MA should be created on complete and for each line
This commit is contained in:
parent
cab309511f
commit
e2ca6313fa
|
@ -1108,7 +1108,6 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
|
|
||||||
if (!isReversal()) // don't change reversal
|
if (!isReversal()) // don't change reversal
|
||||||
{
|
{
|
||||||
checkMaterialPolicy(); // set MASI
|
|
||||||
createConfirmation();
|
createConfirmation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1224,6 +1223,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
|
|
||||||
log.info("Line=" + sLine.getLine() + " - Qty=" + sLine.getMovementQty());
|
log.info("Line=" + sLine.getLine() + " - Qty=" + sLine.getMovementQty());
|
||||||
|
|
||||||
|
checkMaterialPolicy(sLine);
|
||||||
// Stock Movement - Counterpart MOrder.reserveStock
|
// Stock Movement - Counterpart MOrder.reserveStock
|
||||||
if (product != null
|
if (product != null
|
||||||
&& product.isStocked() )
|
&& product.isStocked() )
|
||||||
|
@ -1497,115 +1497,109 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
* Check Material Policy
|
* Check Material Policy
|
||||||
* Sets line ASI
|
* Sets line ASI
|
||||||
*/
|
*/
|
||||||
private void checkMaterialPolicy()
|
private void checkMaterialPolicy(MInOutLine line)
|
||||||
{
|
{
|
||||||
int no = MInOutLineMA.deleteInOutMA(getM_InOut_ID(), get_TrxName());
|
int no = MInOutLineMA.deleteInOutLineMA(line.getM_InOutLine_ID(), get_TrxName());
|
||||||
if (no > 0)
|
if (no > 0)
|
||||||
log.config("Delete old #" + no);
|
log.config("Delete old #" + no);
|
||||||
MInOutLine[] lines = getLines(false);
|
|
||||||
|
|
||||||
// Incoming Trx
|
// Incoming Trx
|
||||||
String MovementType = getMovementType();
|
String MovementType = getMovementType();
|
||||||
boolean inTrx = MovementType.charAt(1) == '+'; // V+ Vendor Receipt
|
boolean inTrx = MovementType.charAt(1) == '+'; // V+ Vendor Receipt
|
||||||
|
|
||||||
// Check Lines
|
boolean needSave = false;
|
||||||
for (int i = 0; i < lines.length; i++)
|
MProduct product = line.getProduct();
|
||||||
{
|
|
||||||
MInOutLine line = lines[i];
|
|
||||||
boolean needSave = false;
|
|
||||||
MProduct product = line.getProduct();
|
|
||||||
|
|
||||||
// Need to have Location
|
// Need to have Location
|
||||||
if (product != null
|
if (product != null
|
||||||
&& line.getM_Locator_ID() == 0)
|
&& line.getM_Locator_ID() == 0)
|
||||||
|
{
|
||||||
|
line.setM_Warehouse_ID(getM_Warehouse_ID());
|
||||||
|
line.setM_Locator_ID(inTrx ? Env.ZERO : line.getMovementQty()); // default Locator
|
||||||
|
needSave = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attribute Set Instance
|
||||||
|
if (product != null
|
||||||
|
&& line.getM_AttributeSetInstance_ID() == 0)
|
||||||
|
{
|
||||||
|
if (inTrx)
|
||||||
{
|
{
|
||||||
line.setM_Warehouse_ID(getM_Warehouse_ID());
|
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
|
||||||
line.setM_Locator_ID(inTrx ? Env.ZERO : line.getMovementQty()); // default Locator
|
asi.setClientOrg(getAD_Client_ID(), 0);
|
||||||
needSave = true;
|
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
|
||||||
}
|
if (asi.save())
|
||||||
|
|
||||||
// Attribute Set Instance
|
|
||||||
if (product != null
|
|
||||||
&& line.getM_AttributeSetInstance_ID() == 0)
|
|
||||||
{
|
|
||||||
if (inTrx)
|
|
||||||
{
|
{
|
||||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
|
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
||||||
asi.setClientOrg(getAD_Client_ID(), 0);
|
log.config("New ASI=" + line);
|
||||||
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
|
needSave = true;
|
||||||
if (asi.save())
|
|
||||||
{
|
|
||||||
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
|
||||||
log.config("New ASI=" + line);
|
|
||||||
needSave = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // Outgoing Trx
|
}
|
||||||
|
else // Outgoing Trx
|
||||||
|
{
|
||||||
|
String MMPolicy = product.getMMPolicy();
|
||||||
|
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
|
||||||
|
line.getM_Product_ID(), line.getM_Locator_ID(),
|
||||||
|
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
|
||||||
|
BigDecimal qtyToDeliver = line.getMovementQty();
|
||||||
|
for (int ii = 0; ii < storages.length; ii++)
|
||||||
{
|
{
|
||||||
String MMPolicy = product.getMMPolicy();
|
MStorage storage = storages[ii];
|
||||||
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
|
if (ii == 0)
|
||||||
line.getM_Product_ID(), line.getM_Locator_ID(),
|
|
||||||
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
|
|
||||||
BigDecimal qtyToDeliver = line.getMovementQty();
|
|
||||||
for (int ii = 0; ii < storages.length; ii++)
|
|
||||||
{
|
{
|
||||||
MStorage storage = storages[ii];
|
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||||
if (ii == 0)
|
|
||||||
{
|
{
|
||||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
|
||||||
{
|
needSave = true;
|
||||||
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
|
log.config("Direct - " + line);
|
||||||
needSave = true;
|
qtyToDeliver = Env.ZERO;
|
||||||
log.config("Direct - " + line);
|
|
||||||
qtyToDeliver = Env.ZERO;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.config("Split - " + line);
|
|
||||||
MInOutLineMA ma = new MInOutLineMA (line,
|
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
|
||||||
storage.getQtyOnHand());
|
|
||||||
if (!ma.save())
|
|
||||||
;
|
|
||||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
|
||||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // create addl material allocation
|
else
|
||||||
{
|
{
|
||||||
|
log.config("Split - " + line);
|
||||||
MInOutLineMA ma = new MInOutLineMA (line,
|
MInOutLineMA ma = new MInOutLineMA (line,
|
||||||
storage.getM_AttributeSetInstance_ID(),
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
qtyToDeliver);
|
storage.getQtyOnHand());
|
||||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
|
||||||
qtyToDeliver = Env.ZERO;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ma.setMovementQty(storage.getQtyOnHand());
|
|
||||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
|
||||||
}
|
|
||||||
if (!ma.save())
|
if (!ma.save())
|
||||||
;
|
;
|
||||||
|
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
}
|
}
|
||||||
if (qtyToDeliver.signum() == 0)
|
}
|
||||||
break;
|
else // create addl material allocation
|
||||||
} // for all storages
|
|
||||||
|
|
||||||
// No AttributeSetInstance found for remainder
|
|
||||||
if (qtyToDeliver.signum() != 0)
|
|
||||||
{
|
{
|
||||||
MInOutLineMA ma = new MInOutLineMA (line,
|
MInOutLineMA ma = new MInOutLineMA (line,
|
||||||
0, qtyToDeliver);
|
storage.getM_AttributeSetInstance_ID(),
|
||||||
|
qtyToDeliver);
|
||||||
|
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||||
|
qtyToDeliver = Env.ZERO;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ma.setMovementQty(storage.getQtyOnHand());
|
||||||
|
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||||
|
}
|
||||||
if (!ma.save())
|
if (!ma.save())
|
||||||
;
|
;
|
||||||
log.fine("##: " + ma);
|
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||||
}
|
}
|
||||||
} // outgoing Trx
|
if (qtyToDeliver.signum() == 0)
|
||||||
} // attributeSetInstance
|
break;
|
||||||
|
} // for all storages
|
||||||
|
|
||||||
|
// No AttributeSetInstance found for remainder
|
||||||
|
if (qtyToDeliver.signum() != 0)
|
||||||
|
{
|
||||||
|
MInOutLineMA ma = new MInOutLineMA (line,
|
||||||
|
0, qtyToDeliver);
|
||||||
|
if (!ma.save())
|
||||||
|
;
|
||||||
|
log.fine("##: " + ma);
|
||||||
|
}
|
||||||
|
} // outgoing Trx
|
||||||
|
} // attributeSetInstance
|
||||||
|
|
||||||
if (needSave && !line.save())
|
if (needSave && !line.save())
|
||||||
log.severe("NOT saved " + line);
|
log.severe("NOT saved " + line);
|
||||||
} // for all lines
|
|
||||||
} // checkMaterialPolicy
|
} // checkMaterialPolicy
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,19 @@ public class MInOutLineMA extends X_M_InOutLineMA
|
||||||
return DB.executeUpdate(sql, trxName);
|
return DB.executeUpdate(sql, trxName);
|
||||||
} // deleteInOutMA
|
} // deleteInOutMA
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all Material Allocation for InOutLine
|
||||||
|
* @param M_InOutLine_ID Shipment Line
|
||||||
|
* @param trxName transaction
|
||||||
|
* @return number of rows deleted or -1 for error
|
||||||
|
*/
|
||||||
|
public static int deleteInOutLineMA (int M_InOutLine_ID, String trxName)
|
||||||
|
{
|
||||||
|
String sql = "DELETE FROM M_InOutLineMA ma WHERE ma.M_InOutLine_ID=?";
|
||||||
|
return DB.executeUpdate(sql, M_InOutLine_ID, trxName);
|
||||||
|
} // deleteInOutLineMA
|
||||||
|
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger s_log = CLogger.getCLogger (MInOutLineMA.class);
|
private static CLogger s_log = CLogger.getCLogger (MInOutLineMA.class);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue