IDEMPIERE-1963 Implement Generate Shipments (manual) as Info Window (#1410)

- add unit test for Vendor RMA
This commit is contained in:
hengsin 2022-07-25 16:20:52 +08:00 committed by GitHub
parent 5918702166
commit da245c061c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 2 deletions

View File

@ -136,7 +136,7 @@ public class InOutGenerateRMA extends SvrProcess
+ "INNER JOIN M_RMA rma ON dt.C_DocType_ID=rma.C_DocType_ID " + "INNER JOIN M_RMA rma ON dt.C_DocType_ID=rma.C_DocType_ID "
+ "WHERE rma.M_RMA_ID=?"; + "WHERE rma.M_RMA_ID=?";
int docTypeId = DB.getSQLValue(null, docTypeSQl, M_RMA_ID); int docTypeId = DB.getSQLValue(get_TrxName(), docTypeSQl, M_RMA_ID);
return docTypeId; return docTypeId;
} }
@ -147,7 +147,7 @@ public class InOutGenerateRMA extends SvrProcess
if (docTypeId == -1) if (docTypeId == -1)
{ {
throw new IllegalStateException("Could not get invoice document type for Vendor RMA"); throw new IllegalStateException("Could not get shipment document type for Vendor RMA");
} }
MInOut originalReceipt = rma.getShipment(); MInOut originalReceipt = rma.getShipment();

View File

@ -24,6 +24,7 @@
**********************************************************************/ **********************************************************************/
package org.idempiere.test.model; package org.idempiere.test.model;
import static org.compiere.model.SystemIDs.PROCESS_M_INOUT_GENERATERMA_MANUAL;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -42,7 +43,11 @@ import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceLine; import org.compiere.model.MInvoiceLine;
import org.compiere.model.MOrder; import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine; import org.compiere.model.MOrderLine;
import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
import org.compiere.model.MRMA;
import org.compiere.model.MRMALine;
import org.compiere.model.MStorageOnHand; import org.compiere.model.MStorageOnHand;
import org.compiere.model.MStorageReservation; import org.compiere.model.MStorageReservation;
import org.compiere.model.MStorageReservationLog; import org.compiere.model.MStorageReservationLog;
@ -50,6 +55,7 @@ import org.compiere.model.MSysConfig;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl;
import org.compiere.util.CacheMgt; import org.compiere.util.CacheMgt;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -576,4 +582,102 @@ public class PurchaseOrderTest extends AbstractTestCase {
CacheMgt.get().reset(); CacheMgt.get().reset();
} }
} }
@Test
public void testVendorRMA() {
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.PATIO.id));
order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id);
order.setIsSOTrx(false);
order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line1 = new MOrderLine(order);
line1.setLine(10);
line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.MULCH.id));
line1.setQty(new BigDecimal("1"));
line1.setDatePromised(today);
line1.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError());
order.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt.setDocStatus(DocAction.STATUS_Drafted);
receipt.setDocAction(DocAction.ACTION_Complete);
receipt.saveEx();
MInOutLine receiptLine1 = new MInOutLine(receipt);
receiptLine1.setOrderLine(line1, 0, new BigDecimal("1"));
receiptLine1.setQty(new BigDecimal("1"));
receiptLine1.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt, DocAction.ACTION_Complete);
assertFalse(info.isError());
receipt.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, receipt.getDocStatus());
MRMA rma = new MRMA(Env.getCtx(), 0, getTrxName());
rma.setM_InOut_ID(receipt.getM_InOut_ID());
rma.setC_BPartner_ID(receipt.getC_BPartner_ID());
rma.setC_Currency_ID(order.getC_Currency_ID());
rma.setIsSOTrx(false);
rma.setName("testVendorRMA");
rma.setC_DocType_ID(DictionaryIDs.C_DocType.VENDOR_RETURN_MATERIAL.id);
rma.setSalesRep_ID(order.getSalesRep_ID());
rma.setM_RMAType_ID(DictionaryIDs.M_RMAType.DAMAGE_ON_ARRIVAL.id);
rma.saveEx();
MRMALine rmaLine = new MRMALine(Env.getCtx(), 0, getTrxName());
rmaLine.setM_RMA_ID(rma.get_ID());
rmaLine.setM_InOutLine_ID(receiptLine1.get_ID());
rmaLine.setQty(receiptLine1.getMovementQty());
rmaLine.saveEx();
assertEquals(0, rmaLine.getQtyDelivered().intValue(), "Unexpected RMA Line QtyDelivered value");
info = MWorkflow.runDocumentActionWorkflow(rma, DocAction.ACTION_Complete);
assertFalse(info.isError());
rma.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, rma.getDocStatus());
int AD_Process_ID = PROCESS_M_INOUT_GENERATERMA_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(), rma.get_ID()}, null);
//call process
ProcessInfo pi = new ProcessInfo ("InOutGenRMA", 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", getM_Warehouse_ID());
ip.saveEx();
ServerProcessCtl processCtl = new ServerProcessCtl(pi, getTrx());
processCtl.setManagedTrxForJavaProcess(false);
processCtl.run();
assertFalse(pi.isError(), pi.getSummary());
rmaLine.load(getTrxName());
assertEquals(rmaLine.getQty().intValue(), rmaLine.getQtyDelivered().intValue(), "RMA Line QtyDelivered not updated by shipment for Vendor RMA");
}
} }