From 5c8b7ae6a8b685228f115194e37bc1f5ec0c61ed Mon Sep 17 00:00:00 2001 From: hengsin Date: Sun, 14 Nov 2021 15:10:56 +0800 Subject: [PATCH] IDEMPIERE-4854 Bugfixes in InOutGenerate (#979) add unit test --- .../idempiere/test/model/SalesOrderTest.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/org.idempiere.test/src/org/idempiere/test/model/SalesOrderTest.java b/org.idempiere.test/src/org/idempiere/test/model/SalesOrderTest.java index 781d7cdeba..5a5507a37c 100644 --- a/org.idempiere.test/src/org/idempiere/test/model/SalesOrderTest.java +++ b/org.idempiere.test/src/org/idempiere/test/model/SalesOrderTest.java @@ -663,6 +663,7 @@ public class SalesOrderTest extends AbstractTestCase { @Test /** * https://idempiere.atlassian.net/browse/IDEMPIERE-4768 + * https://idempiere.atlassian.net/browse/IDEMPIERE-4854 */ public void testMultiASIShipment() { Properties ctx = Env.getCtx(); @@ -707,7 +708,7 @@ public class SalesOrderTest extends AbstractTestCase { MOrder order = new MOrder(ctx, 0, trxName); order.setAD_Org_ID(ORG_FERTILIZER); order.setBPartner(MBPartner.get(ctx, BP_JOE_BLOCK)); - order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_POS); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); order.setM_Warehouse_ID(WAREHOUSE_FERTILIZER); order.setDocStatus(DocAction.STATUS_Drafted); @@ -729,10 +730,41 @@ public class SalesOrderTest extends AbstractTestCase { assertFalse(info.isError(), info.getSummary()); order.load(trxName); assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + + //generate shipment + int AD_Process_ID = PROCESS_M_INOUT_GENERATE_MANUAL; + MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0); + instance.saveEx(); + + String insert = "INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) Values (?, ?)"; + DB.executeUpdateEx(insert, new Object[] {instance.getAD_PInstance_ID(), order.getC_Order_ID()}, null); + + //call process + ProcessInfo pi = new ProcessInfo ("InOutGen", AD_Process_ID); + pi.setAD_PInstance_ID (instance.getAD_PInstance_ID()); + + // Add Parameter - Selection=Y + MPInstancePara ip = new MPInstancePara(instance, 10); + ip.setParameter("Selection","Y"); + ip.saveEx(); + //Add Document action parameter + ip = new MPInstancePara(instance, 20); + ip.setParameter("DocAction", "CO"); + ip.saveEx(); + // Add Parameter - M_Warehouse_ID=x + ip = new MPInstancePara(instance, 30); + ip.setParameter("M_Warehouse_ID", WAREHOUSE_FERTILIZER); + ip.saveEx(); + + ServerProcessCtl processCtl = new ServerProcessCtl(pi, getTrx()); + processCtl.setManagedTrxForJavaProcess(false); + processCtl.run(); + + assertFalse(pi.isError(), pi.getSummary()); + line1.load(trxName); assertEquals(0, line1.getQtyReserved().intValue()); assertEquals(2, line1.getQtyDelivered().intValue()); - assertEquals(2, line1.getQtyInvoiced().intValue()); // Expected to have cleared both storage entries on shipment storages = MStorageOnHand.getWarehouse(ctx, WAREHOUSE_FERTILIZER, @@ -740,6 +772,17 @@ public class SalesOrderTest extends AbstractTestCase { MClient.MMPOLICY_FiFo.equals(fert50.getMMPolicy()), false, 0, trxName); assertEquals(0, storages.length); + + Query query = new Query(Env.getCtx(), MInOut.Table_Name, "C_Order_ID=?", getTrxName()); + MInOut inout = query.setParameters(order.get_ID()).first(); + assertNotNull(inout, "Can't find shipment for order"); + MInOutLine[] ilines = inout.getLines(); + assertTrue(ilines.length==1, "Shipment doesn't has 1 line as expected: " + ilines.length); + assertEquals(line1.get_ID(), ilines[0].getC_OrderLine_ID(), "Shipment line doesn't has the expected order line ID"); + assertEquals(line1.getQtyOrdered(), ilines[0].getMovementQty(), "Shipment line doesn't has the expected movement quantity"); + assertEquals(line1.getM_Product_ID(), ilines[0].getM_Product_ID(), "Shipment line doesn't has the expected product ID"); + assertEquals(line1.getM_AttributeSetInstance_ID(), ilines[0].getM_AttributeSetInstance_ID(), "Shipment line doesn't has the expected ASI ID"); + assertEquals(LOCATOR_FERTILIZER, ilines[0].getM_Locator_ID(), "Shipment line doesn't has the expected Locator ID"); } @Test @@ -826,5 +869,5 @@ public class SalesOrderTest extends AbstractTestCase { assertTrue(log.getDeltaQty().intValue() == -1, "Delta quantity of MStorageReservationLog != -1 ("+log.getDeltaQty().toPlainString()+")"); reservation = MStorageReservation.get(Env.getCtx(), line1.getM_Warehouse_ID(), PRODUCT_AZALEA, 0, true, getTrxName()); assertTrue(log.getNewQty().equals(reservation.getQty()), "New Qty from MStorageReservationLog != Qty from MStorageReservation"); - } + } }