MProduct packedProduct,
MInventory inv,
int chargeID) throws Exception
{
MPPProductBOMLine[] bomLines = bom.getLines();
MInventoryLine invLine;
MProduct lineProduct;
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(),
pack.getM_AttributeSetInstance_ID(),
get_TrxName());
BigDecimal sg = (BigDecimal)asi.get_Value("SG");
BigDecimal vol;
int asiID;
// Make sure SG in the Attribute Set Instance has a value. Abort if not.
if (sg == null || sg.equals(BigDecimal.valueOf(0)))
throw new AdempiereUserError("@Error@ SG value not set for Attribute Set Instance "+
asi.getDescription());
// Generate inventory lines from the BOM lines
for (MPPProductBOMLine bomLine : bomLines)
{
lineProduct = new MProduct(getCtx(), bomLine.getM_Product_ID(), get_TrxName());
// Only assign the Attribute Set Instance to lines where the product on
// that line has a Finished Product Batch Number
if (lineProduct.getAttributeSet() != null &&
lineProduct.getAttributeSet().getName().equals("Finished Product Batch Number"))
asiID = asi.getM_AttributeSetInstance_ID();
else
asiID = 0;
invLine = new MInventoryLine(inv,
p_M_Locator_ID,
lineProduct.getM_Product_ID(),
asiID,
BigDecimal.ZERO,
BigDecimal.ZERO);
// Bulk line calculation = Qty x SG x Vol. Other lines = Qty x QtyBOM.
if ((Boolean)lineProduct.get_Value("IsBulk"))
{
vol = packedProduct.getVolume();
invLine.setQtyInternalUse(pack.getQty().multiply(sg).multiply(vol));
}
else
{
invLine.setQtyInternalUse(pack.getQty().multiply(bomLine.getQtyBOM()));
}
invLine.setDescription("Pack");
invLine.setC_Charge_ID(chargeID);
invLine.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
invLine.setM_Inventory_ID(inv.getM_Inventory_ID());
invLine.save(get_TrxName());
} // end for
} // copyBOMLines