use of org.compiere.model.MInventory in project adempiere by adempiere.
the class CostResult method createInvetoryInternalUse.
public MInventory createInvetoryInternalUse(Timestamp documentDate, BigDecimal qty) {
int M_Locator_ID = 101;
MInventory inventory = new MInventory(getCtx(), 0, trxName);
inventory.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
inventory.setM_Warehouse_ID(w.getM_Warehouse_ID());
inventory.setC_DocType_ID((MDocType.getDocType(MDocType.DOCBASETYPE_MaterialPhysicalInventory)));
inventory.setMovementDate(documentDate);
inventory.saveEx();
MInventoryLine invenotryLine = new MInventoryLine(getCtx(), 0, trxName);
invenotryLine.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
invenotryLine.setM_Inventory_ID(inventory.getM_Inventory_ID());
invenotryLine.setM_Product_ID(product.getM_Product_ID());
invenotryLine.setQtyBook(Env.ZERO);
invenotryLine.setQtyCount(Env.ZERO);
invenotryLine.setQtyInternalUse(qty);
invenotryLine.setInventoryType(MInventoryLine.INVENTORYTYPE_ChargeAccount);
invenotryLine.setC_Charge_ID(100);
// Default HQ Locator
invenotryLine.setM_Locator_ID(M_Locator_ID);
invenotryLine.saveEx();
inventory.processIt(DocAction.ACTION_Complete);
inventory.saveEx();
return inventory;
}
use of org.compiere.model.MInventory in project adempiere by adempiere.
the class CostResult method createBusinessCaseTest.
/**
* create Business Test Case
* @param trxName
*/
void createBusinessCaseTest(String trxName) {
createDataMaster();
generateHistoryCost();
Timestamp dateAcct;
//First Purchase Receipt
dateAcct = today;
MOrder purchase1 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(36));
MInOut receipt1 = null;
for (MOrderLine line : purchase1.getLines()) {
receipt1 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
}
for (MInOutLine line : receipt1.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("47.7292"), // cumulateQty
new BigDecimal("30"), //cumulateAmt
new BigDecimal("1431.8748"), //cdAmt
new BigDecimal("477.2920"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("53.5937"), //cdCumulateQty
new BigDecimal("20"), //cdCumulateAmt
new BigDecimal("1071.8748"), dateAcct);
assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
}
//Create Sales Order Order Credit by 5
dateAcct = TimeUtil.addDays(today, 15);
MOrder sales1 = createSalesOrder(dateAcct, new BigDecimal(5), new BigDecimal(45));
for (MOrderLine line : sales1.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("47.7292"), new BigDecimal("25"), new BigDecimal("1193.2288"), new BigDecimal("238.6460"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("47.7292"), new BigDecimal("30"), new BigDecimal("1431.8748"), dateAcct);
assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
}
//Second Purchase Receipt 7 day forward
dateAcct = TimeUtil.addDays(today, 31);
MOrder purchase2 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(34));
MInOut receipt2 = null;
for (MOrderLine line : purchase2.getLines()) {
receipt2 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
}
for (MInOutLine line : receipt2.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("43.8065"), // cumulateQty
new BigDecimal("35"), //cumulateAmt
new BigDecimal("1533.2288"), //cdAmt
new BigDecimal("438.0650"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("47.7292"), //cdCumulateQty
new BigDecimal("25"), //cdCumulateAmt
new BigDecimal("1193.2288"), dateAcct);
assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
}
//Create Sales Order Order Credit by 5
dateAcct = TimeUtil.addDays(today, 60);
MOrder sales2 = createSalesOrder(dateAcct, new BigDecimal(10), new BigDecimal(45));
for (MOrderLine line : sales2.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("43.8065"), new BigDecimal("25"), new BigDecimal("1095.1638"), new BigDecimal("438.0650"), new BigDecimal("0"), new BigDecimal("-10"), new BigDecimal("43.8065"), new BigDecimal("35"), new BigDecimal("1533.2288"), dateAcct);
assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
}
dateAcct = receipt1.getDateAcct();
int M_InOutLine_ID = 0;
for (MInOutLine line : receipt1.getLines()) {
M_InOutLine_ID = line.getM_InOutLine_ID();
MInvoice invoice = createInvoiceVendor(dateAcct, new BigDecimal(10), new BigDecimal(38), line.getM_InOutLine_ID());
}
CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("44.2827"), // cumulateQty
new BigDecimal("25"), //cumulateAmt
new BigDecimal("1107.0688"), //cdAmt
new BigDecimal("380.0000"), //cdAdjutment
new BigDecimal("20.0000"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("53.5937"), //cdCumulateQty
new BigDecimal("20"), //cdCumulateAmt
new BigDecimal("1071.8748"), dateAcct);
assertCostInvoice(costResult, M_InOutLine_ID, as, trxName);
dateAcct = Timestamp.valueOf("2010-01-16 00:00:00.0");
for (MOrderLine line : sales1.getLines()) {
costResult = new CostResult(line.getM_Product_ID(), new BigDecimal("44.2827"), new BigDecimal("25"), new BigDecimal("1107.0688"), new BigDecimal("241.9790"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("48.3958"), new BigDecimal("30"), new BigDecimal("1451.8748"), dateAcct);
assertCostShipmentAdjust(costResult, line.getC_OrderLine_ID(), as, trxName);
}
//Reverse Material Receipt
dateAcct = today;
receipt1.processIt(DocAction.ACTION_Reverse_Correct);
receipt1.saveEx();
for (MInOutLine line : receipt1.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("44.2827"), // cumulateQty
new BigDecimal("25"), //cumulateAmt
new BigDecimal("1107.0688"), //cdAmt
new BigDecimal("380.0000"), //cdAdjutment
new BigDecimal("20.0000"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("53.5937"), //cdCumulateQty
new BigDecimal("20"), //cdCumulateAmt
new BigDecimal("1071.8748"), dateAcct);
assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
}
MInOut reversal = new MInOut(getCtx(), receipt1.getReversal_ID(), trxName);
for (MInOutLine line : reversal.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("46.8373"), // cumulateQty
new BigDecimal("19"), //cumulateAmt
new BigDecimal("889.9081"), //cdAmt
new BigDecimal("380"), //cdAdjutment
new BigDecimal("20"), //cdQty
new BigDecimal("-10"), //cdCurrentCostPrice
new BigDecimal("49.0073"), //cdCumulateQty
new BigDecimal("34"), //cdCumulateAmt
new BigDecimal("1666.2496"), dateAcct);
assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
}
//Second Purchase Receipt 7 day forward
dateAcct = TimeUtil.addDays(today, 7);
MOrder purchase3 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(37));
MInOut receipt3 = null;
for (MOrderLine line : purchase3.getLines()) {
receipt3 = createMaterialReceipt(dateAcct, new BigDecimal(20), line.getC_OrderLine_ID());
}
for (MInOutLine line : receipt3.getLines()) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("42.0489"), // cumulateQty
new BigDecimal("45"), //cumulateAmt
new BigDecimal("1892.1983"), //cdAmt
new BigDecimal("876.7500"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("20"), //cdCurrentCostPrice
new BigDecimal("48.3958"), //cdCumulateQty
new BigDecimal("30"), //cdCumulateAmt
new BigDecimal("1451.8748"), dateAcct);
assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
}
dateAcct = TimeUtil.addDays(today, 65);
MMovement move = createMovement(dateAcct, new BigDecimal("5"));
for (MMovementLine line : move.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("53.5938"), // cumulateQty
new BigDecimal("9"), //cumulateAmt
new BigDecimal("482.3442"), //cdAmt
new BigDecimal("267.9690"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("5"), //cdCurrentCostPrice
new BigDecimal("53.5938"), //cdCumulateQty
new BigDecimal("4"), //cdCumulateAmt
new BigDecimal("214.3752"), dateAcct);
assertCostMovement(costResult, line.getM_MovementLine_ID(), as, trxName);
}
dateAcct = TimeUtil.addDays(today, 70);
MInventory inventory = createPhisicalInventory(dateAcct, new BigDecimal("20"), costResult.cumulateQty);
for (MInventoryLine line : inventory.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("42.0488"), // cumulateQty
new BigDecimal("51"), //cumulateAmt
new BigDecimal("2144.4906"), //cdAmt
new BigDecimal("462.5368"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("11"), //cdCurrentCostPrice
new BigDecimal("42.0488"), //cdCumulateQty
new BigDecimal("40"), //cdCumulateAmt
new BigDecimal("1681.9538"), dateAcct);
assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
break;
}
dateAcct = TimeUtil.addDays(today, 80);
inventory = createInvetoryInternalUse(dateAcct, new BigDecimal("-5"));
for (MInventoryLine line : inventory.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("42.0488"), // cumulateQty
new BigDecimal("56"), //cumulateAmt
new BigDecimal("2354.7346"), //cdAmt
new BigDecimal("210.2440"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("5"), //cdCurrentCostPrice
new BigDecimal("42.0488"), //cdCumulateQty
new BigDecimal("51"), //cdCumulateAmt
new BigDecimal("2144.4906"), dateAcct);
assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
;
}
createTrxAndInventoryValuationReport();
}
use of org.compiere.model.MInventory in project adempiere by adempiere.
the class InventoryCountUpdate method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("M_Inventory_ID=" + getRecord_ID());
MInventory inventory = new MInventory(getCtx(), getRecord_ID(), get_TrxName());
if (inventory.get_ID() == 0)
throw new AdempiereSystemError("Not found: M_Inventory_ID=" + getRecord_ID());
// Multiple Lines for one item
String sql = "UPDATE M_InventoryLine SET IsActive='N' " + "WHERE M_Inventory_ID=" + getRecord_ID() + " AND (M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID) IN " + "(SELECT M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID " + "FROM M_InventoryLine " + "WHERE M_Inventory_ID=" + getRecord_ID() + " GROUP BY M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID " + "HAVING COUNT(*) > 1)";
int multiple = DB.executeUpdate(sql, get_TrxName());
log.info("Multiple=" + multiple);
int deleteInventoryMA = MInventoryLineMA.deleteInventoryMA(getRecord_ID(), get_TrxName());
log.info("DeletedMA=" + deleteInventoryMA);
// ASI
sql = "UPDATE M_InventoryLine l " + "SET (QtyBook,QtyCount) = " + "(SELECT QtyOnHand, " + (isUpdateCountQty() ? "s.QtyOnHand" : "l.QtyCount") + " FROM M_Storage s " + "WHERE s.M_Product_ID=l.M_Product_ID AND s.M_Locator_ID=l.M_Locator_ID" + " AND s.M_AttributeSetInstance_ID=l.M_AttributeSetInstance_ID)," + " Updated=SysDate," + " UpdatedBy=" + getAD_User_ID() + //
" WHERE M_Inventory_ID=" + getRecord_ID() + " AND EXISTS (SELECT * FROM M_Storage s " + "WHERE s.M_Product_ID=l.M_Product_ID AND s.M_Locator_ID=l.M_Locator_ID" + " AND s.M_AttributeSetInstance_ID=l.M_AttributeSetInstance_ID)";
int no = DB.executeUpdate(sql, get_TrxName());
log.info("Update with ASI=" + no);
// No ASI
int noMA = updateWithMA();
// Set Count to Zero
if (isUpdateCountQty() && "Z".equals(getSetInventoryCountto())) {
sql = "UPDATE M_InventoryLine l " + "SET QtyCount=0 " + "WHERE M_Inventory_ID=" + getRecord_ID();
no = DB.executeUpdate(sql, get_TrxName());
log.info("Set Count to Zero=" + no);
}
if (multiple > 0)
return "@M_InventoryLine_ID@ - #" + (no + noMA) + " --> @InventoryProductMultiple@";
return "@M_InventoryLine_ID@ - #" + no;
}
use of org.compiere.model.MInventory in project adempiere by adempiere.
the class UpdateQuantityCount method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("M_Inventory_ID=" + p_M_Inventory_ID);
m_inventory = new MInventory(getCtx(), p_M_Inventory_ID, get_TrxName());
if (m_inventory.get_ID() == 0)
throw new AdempiereSystemError("Not found: M_Inventory_ID=" + p_M_Inventory_ID);
if (m_inventory.isProcessed())
throw new AdempiereSystemError("@M_Inventory_ID@ @Processed@");
// Update Quantity Count
String sql1 = "UPDATE M_InventoryLine l " + "SET QtyCount=COALESCE(SecondCountQty,FirstCountQty) + PickedQty " + "WHERE M_Inventory_ID=" + p_M_Inventory_ID;
int no = DB.executeUpdate(sql1, get_TrxName());
log.info("Update Quantity Count #" + no);
//
return "@M_Inventory_ID@ - #" + no;
}
use of org.compiere.model.MInventory in project adempiere by adempiere.
the class Doc_Inventory method loadDocumentDetails.
// Doc_Inventory
/**
* Load Document Details
* @return error message or null
*/
protected String loadDocumentDetails() {
setC_Currency_ID(NO_CURRENCY);
MInventory inventory = (MInventory) getPO();
setDateDoc(inventory.getMovementDate());
setDateAcct(inventory.getMovementDate());
//store original (voided/reversed) document
m_Reversal_ID = inventory.getReversal_ID();
m_DocStatus = inventory.getDocStatus();
// Contained Objects
p_lines = loadLines(inventory);
log.fine("Lines=" + p_lines.length);
return null;
}
Aggregations