IDEMPIERE-5440 Add unit test for Matching form (#1510)

This commit is contained in:
hengsin 2022-09-30 18:25:20 +08:00 committed by GitHub
parent a6a80b7a8c
commit 13d26966b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 227 additions and 84 deletions

View File

@ -81,11 +81,6 @@ import org.zkoss.zul.Vlayout;
public class WMatch extends Match public class WMatch extends Match
implements IFormController, EventListener<Event>, WTableModelListener implements IFormController, EventListener<Event>, WTableModelListener
{ {
/**
*
*/
@SuppressWarnings("unused")
private static final long serialVersionUID = -6383121932802974801L;
private CustomForm form = new CustomForm(); private CustomForm form = new CustomForm();
/** /**
@ -94,8 +89,9 @@ public class WMatch extends Match
public WMatch() public WMatch()
{ {
m_WindowNo = form.getWindowNo(); m_WindowNo = form.getWindowNo();
log.info("WinNo=" + m_WindowNo if (log.isLoggable(Level.INFO))
+ " - AD_Client_ID=" + m_AD_Client_ID + ", AD_Org_ID=" + m_AD_Org_ID + ", By=" + m_by); log.info("WinNo=" + m_WindowNo
+ " - AD_Client_ID=" + m_AD_Client_ID + ", AD_Org_ID=" + m_AD_Org_ID + ", By=" + m_by);
Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "N"); Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "N");
try try
@ -122,7 +118,7 @@ public class WMatch extends Match
{ {
ClientInfo.onClientInfo(form, this::onClientInfo); ClientInfo.onClientInfo(form, this::onClientInfo);
} }
} // init }
/** Window No */ /** Window No */
private int m_WindowNo = 0; private int m_WindowNo = 0;
@ -146,11 +142,6 @@ public class WMatch extends Match
private static final int MODE_NOTMATCHED = 0; private static final int MODE_NOTMATCHED = 0;
private static final int MODE_MATCHED = 1; private static final int MODE_MATCHED = 1;
/** Indexes in Table */
private static final int I_QTY = 6;
private static final int I_MATCHED = 7;
private BigDecimal m_xMatched = Env.ZERO; private BigDecimal m_xMatched = Env.ZERO;
private BigDecimal m_xMatchedTo = Env.ZERO; private BigDecimal m_xMatchedTo = Env.ZERO;
@ -293,7 +284,7 @@ public class WMatch extends Match
ZKUpdateUtil.setVflex(xMatchedTable, true); ZKUpdateUtil.setVflex(xMatchedTable, true);
centerPanel.setStyle("min-height: 300px;"); centerPanel.setStyle("min-height: 300px;");
} // jbInit }
protected void layoutParameterAndSummary() { protected void layoutParameterAndSummary() {
setupParameterColumns(); setupParameterColumns();
@ -391,16 +382,7 @@ public class WMatch extends Match
*/ */
private void dynInit() private void dynInit()
{ {
ColumnInfo[] layout = new ColumnInfo[] { ColumnInfo[] layout = getColumnLayout();
new ColumnInfo(" ", ".", IDColumn.class, false, false, ""),
new ColumnInfo(Msg.translate(Env.getCtx(), "DocumentNo"), ".", String.class), // 1
new ColumnInfo(Msg.translate(Env.getCtx(), "Date"), ".", Timestamp.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"),".", KeyNamePair.class, "."), // 3
new ColumnInfo(Msg.translate(Env.getCtx(), "Line"), ".", KeyNamePair.class, "."),
new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class, "."), // 5
new ColumnInfo(Msg.translate(Env.getCtx(), "Qty"), ".", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Matched"), ".", Double.class)
};
xMatchedTable.prepareTable(layout, "", "", false, ""); xMatchedTable.prepareTable(layout, "", "", false, "");
xMatchedToTable.prepareTable(layout, "", "", true, ""); xMatchedToTable.prepareTable(layout, "", "", true, "");
@ -417,7 +399,6 @@ public class WMatch extends Match
sameProduct.addActionListener(this); sameProduct.addActionListener(this);
sameQty.addActionListener(this); sameQty.addActionListener(this);
// Init Yvonne
String selection = (String)matchFrom.getSelectedItem().getValue(); String selection = (String)matchFrom.getSelectedItem().getValue();
SimpleListModel model = new SimpleListModel(cmd_matchFrom((String)matchFrom.getSelectedItem().getLabel())); SimpleListModel model = new SimpleListModel(cmd_matchFrom((String)matchFrom.getSelectedItem().getLabel()));
matchTo.setItemRenderer(model); matchTo.setItemRenderer(model);
@ -477,6 +458,7 @@ public class WMatch extends Match
* Action Listener * Action Listener
* @param e event * @param e event
*/ */
@Override
public void onEvent (Event e) public void onEvent (Event e)
{ {
Integer product = onlyProduct.getValue()!=null?(Integer)onlyProduct.getValue():null; Integer product = onlyProduct.getValue()!=null?(Integer)onlyProduct.getValue():null;
@ -485,7 +467,6 @@ public class WMatch extends Match
Timestamp to = dateTo.getValue()!=null?(Timestamp)dateTo.getValue():null; Timestamp to = dateTo.getValue()!=null?(Timestamp)dateTo.getValue():null;
if (e.getTarget() == matchFrom) { if (e.getTarget() == matchFrom) {
//cmd_matchFrom((String)matchFrom.getSelectedItem().getLabel());
String selection = (String)matchFrom.getSelectedItem().getValue(); String selection = (String)matchFrom.getSelectedItem().getValue();
SimpleListModel model = new SimpleListModel(cmd_matchFrom((String)matchFrom.getSelectedItem().getLabel())); SimpleListModel model = new SimpleListModel(cmd_matchFrom((String)matchFrom.getSelectedItem().getLabel()));
matchTo.setItemRenderer(model); matchTo.setItemRenderer(model);
@ -503,7 +484,6 @@ public class WMatch extends Match
cmd_matchTo(); cmd_matchTo();
else if (e.getTarget() == bSearch) else if (e.getTarget() == bSearch)
{ {
//cmd_search();
xMatchedTable = (WListbox)cmd_search(xMatchedTable, matchFrom.getSelectedIndex(), (String)matchTo.getSelectedItem().getLabel(), product, vendor, from, to, matchMode.getSelectedIndex() == MODE_MATCHED); xMatchedTable = (WListbox)cmd_search(xMatchedTable, matchFrom.getSelectedIndex(), (String)matchTo.getSelectedItem().getLabel(), product, vendor, from, to, matchMode.getSelectedIndex() == MODE_MATCHED);
xMatched.setValue(Env.ZERO); xMatched.setValue(Env.ZERO);
@ -516,7 +496,6 @@ public class WMatch extends Match
} }
else if (e.getTarget() == bProcess) else if (e.getTarget() == bProcess)
{ {
//cmd_process();
cmd_process(xMatchedTable, xMatchedToTable, matchMode.getSelectedIndex(), matchFrom.getSelectedIndex(), matchTo.getSelectedItem().getLabel(), m_xMatched); cmd_process(xMatchedTable, xMatchedToTable, matchMode.getSelectedIndex(), matchFrom.getSelectedIndex(), matchTo.getSelectedItem().getLabel(), m_xMatched);
xMatchedTable = (WListbox) cmd_search(xMatchedTable, matchFrom.getSelectedIndex(), (String)matchTo.getSelectedItem().getLabel(), product, vendor, from, to, matchMode.getSelectedIndex() == MODE_MATCHED); xMatchedTable = (WListbox) cmd_search(xMatchedTable, matchFrom.getSelectedIndex(), (String)matchTo.getSelectedItem().getLabel(), product, vendor, from, to, matchMode.getSelectedIndex() == MODE_MATCHED);
xMatched.setValue(Env.ZERO); xMatched.setValue(Env.ZERO);
@ -533,7 +512,7 @@ public class WMatch extends Match
cmd_searchTo(); cmd_searchTo();
else if (AEnv.contains(xMatchedTable, e.getTarget())) else if (AEnv.contains(xMatchedTable, e.getTarget()))
cmd_searchTo(); cmd_searchTo();
} // actionPerformed }
/** /**
@ -541,7 +520,6 @@ public class WMatch extends Match
*/ */
private void cmd_matchTo() private void cmd_matchTo()
{ {
// log.fine( "VMatch.cmd_matchTo");
int index = matchTo.getSelectedIndex(); int index = matchTo.getSelectedIndex();
String selection = (String)matchTo.getModel().getElementAt(index); String selection = (String)matchTo.getModel().getElementAt(index);
xMatchedToBorder.setValue(selection); xMatchedToBorder.setValue(selection);
@ -596,6 +574,7 @@ public class WMatch extends Match
* Table Model Listener - calculate matchd Qty * Table Model Listener - calculate matchd Qty
* @param e event * @param e event
*/ */
@Override
public void tableChanged (WTableModelEvent e) public void tableChanged (WTableModelEvent e)
{ {
if (e.getColumn() != 0) if (e.getColumn() != 0)
@ -638,7 +617,7 @@ public class WMatch extends Match
statusBar.setStatusDB(noRows + ""); statusBar.setStatusDB(noRows + "");
} // tableChanged } // tableChanged
@Override
public ADForm getForm() { public ADForm getForm() {
return form; return form;
} }

View File

@ -349,7 +349,6 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
return; return;
String PaymentRule = pp.getValue(); String PaymentRule = pp.getValue();
log.info("PaymentRule=" + PaymentRule);
fNoPayments.setText(" "); fNoPayments.setText(" ");
String msg = loadPaymentRuleInfo(m_C_PaySelection_ID, PaymentRule); String msg = loadPaymentRuleInfo(m_C_PaySelection_ID, PaymentRule);
@ -414,7 +413,6 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
if (fPaymentRule.getSelectedItem() == null) if (fPaymentRule.getSelectedItem() == null)
return; return;
String PaymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue(); String PaymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue();
log.info(PaymentRule);
if (!getChecks(PaymentRule)) if (!getChecks(PaymentRule))
return; return;

View File

@ -26,6 +26,7 @@ import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.IReservationTracer; import org.adempiere.util.IReservationTracer;
import org.adempiere.util.IReservationTracerFactory; import org.adempiere.util.IReservationTracerFactory;
import org.compiere.acct.Doc; import org.compiere.acct.Doc;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn; import org.compiere.minigrid.IDColumn;
import org.compiere.minigrid.IMiniTable; import org.compiere.minigrid.IMiniTable;
import org.compiere.model.MClient; import org.compiere.model.MClient;
@ -66,6 +67,9 @@ public class Match
//private static final int MODE_MATCHED = 1; //private static final int MODE_MATCHED = 1;
/** Indexes in Table */ /** Indexes in Table */
public static final int I_ID = 0;
public static final int I_DocumentNo = 1;
public static final int I_DocumentDate = 2;
public static final int I_BPartner = 3; public static final int I_BPartner = 3;
public static final int I_Line = 4; public static final int I_Line = 4;
public static final int I_Product = 5; public static final int I_Product = 5;
@ -146,7 +150,6 @@ public class Match
*/ */
public void cmd_process(IMiniTable xMatchedTable, IMiniTable xMatchedToTable, int matchMode, int matchFrom, String matchTo, BigDecimal m_xMatched) public void cmd_process(IMiniTable xMatchedTable, IMiniTable xMatchedToTable, int matchMode, int matchFrom, String matchTo, BigDecimal m_xMatched)
{ {
log.config("");
// Matched From // Matched From
int matchedRow = xMatchedTable.getSelectedRow(); int matchedRow = xMatchedTable.getSelectedRow();
if (matchedRow < 0) if (matchedRow < 0)
@ -608,4 +611,22 @@ public class Match
return m_matchOptions[matchType]; return m_matchOptions[matchType];
return null; return null;
} }
/**
*
* @return {@link ColumnInfo} array
*/
public ColumnInfo[] getColumnLayout() {
ColumnInfo[] layout = new ColumnInfo[] {
new ColumnInfo(" ", ".", IDColumn.class, false, false, ""),
new ColumnInfo(Msg.translate(Env.getCtx(), "DocumentNo"), ".", String.class), // 1
new ColumnInfo(Msg.translate(Env.getCtx(), "Date"), ".", Timestamp.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"),".", KeyNamePair.class, "."), // 3
new ColumnInfo(Msg.translate(Env.getCtx(), "Line"), ".", KeyNamePair.class, "."),
new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class, "."), // 5
new ColumnInfo(Msg.translate(Env.getCtx(), "Qty"), ".", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Matched"), ".", Double.class)
};
return layout;
}
} }

View File

@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp;
import org.compiere.apps.form.Match; import org.compiere.apps.form.Match;
import org.compiere.minigrid.ColumnInfo; import org.compiere.minigrid.ColumnInfo;
@ -53,8 +52,6 @@ import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl; import org.compiere.process.ServerProcessCtl;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.wf.MWorkflow; import org.compiere.wf.MWorkflow;
import org.idempiere.test.AbstractTestCase; import org.idempiere.test.AbstractTestCase;
import org.idempiere.test.DictionaryIDs; import org.idempiere.test.DictionaryIDs;
@ -572,31 +569,22 @@ public class MatchPOTest extends AbstractTestCase {
newOnHand = MStorageOnHand.getQtyOnHand(product.get_ID(), getM_Warehouse_ID(), 0, getTrxName()).intValue(); newOnHand = MStorageOnHand.getQtyOnHand(product.get_ID(), getM_Warehouse_ID(), 0, getTrxName()).intValue();
assertEquals(initialOnHand+1, newOnHand, "Unexpected qty on hand value"); assertEquals(initialOnHand+1, newOnHand, "Unexpected qty on hand value");
MiniTableImpl fromTable = new MiniTableImpl();
MiniTableImpl toTable = new MiniTableImpl();
ColumnInfo[] layout = new ColumnInfo[] {
new ColumnInfo(" ", ".", IDColumn.class, false, false, ""),
new ColumnInfo(Msg.translate(Env.getCtx(), "DocumentNo"), ".", String.class), // 1
new ColumnInfo(Msg.translate(Env.getCtx(), "Date"), ".", Timestamp.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"),".", KeyNamePair.class, "."), // 3
new ColumnInfo(Msg.translate(Env.getCtx(), "Line"), ".", KeyNamePair.class, "."),
new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class, "."), // 5
new ColumnInfo(Msg.translate(Env.getCtx(), "Qty"), ".", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Matched"), ".", Double.class)
};
fromTable.prepareTable(layout, null, null, false, null);
toTable.prepareTable(layout, null, null, false, null);
Match match = new Match(); Match match = new Match();
match.setTrxName(getTrxName()); match.setTrxName(getTrxName());
MiniTableImpl fromTable = new MiniTableImpl();
MiniTableImpl toTable = new MiniTableImpl();
ColumnInfo[] layout = match.getColumnLayout();
fromTable.prepareTable(layout, null, null, false, null);
toTable.prepareTable(layout, null, null, false, null);
match.cmd_search(fromTable, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), product.get_ID(), bpartner.get_ID(), null, null, false); match.cmd_search(fromTable, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), product.get_ID(), bpartner.get_ID(), null, null, false);
assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount()); assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount());
int selectedRow = -1; int selectedRow = -1;
for(int i = 0; i < fromTable.getRowCount(); i++) { for(int i = 0; i < fromTable.getRowCount(); i++) {
String docNo = (String)fromTable.getValueAt(i, 1); String docNo = (String)fromTable.getValueAt(i, Match.I_DocumentNo);
if (receipt.getDocumentNo().equals(docNo)) { if (receipt.getDocumentNo().equals(docNo)) {
int matched = ((Number)fromTable.getValueAt(i, 7)).intValue(); int matched = ((Number)fromTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for Material Receipt line"); assertEquals(0, matched, "Unexpected matched qty for Material Receipt line");
int qty = ((Number)fromTable.getValueAt(i, 6)).intValue(); int qty = ((Number)fromTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line"); assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line");
selectedRow = i; selectedRow = i;
break; break;
@ -608,11 +596,11 @@ public class MatchPOTest extends AbstractTestCase {
assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount()); assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount());
int selectedOrderRow = -1; int selectedOrderRow = -1;
for(int i = 0; i < toTable.getRowCount(); i++) { for(int i = 0; i < toTable.getRowCount(); i++) {
String docNo = (String)toTable.getValueAt(i, 1); String docNo = (String)toTable.getValueAt(i, Match.I_DocumentNo);
if (order.getDocumentNo().equals(docNo)) { if (order.getDocumentNo().equals(docNo)) {
int matched = ((Number)toTable.getValueAt(i, 7)).intValue(); int matched = ((Number)toTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for PO line"); assertEquals(0, matched, "Unexpected matched qty for PO line");
int qty = ((Number)toTable.getValueAt(i, 6)).intValue(); int qty = ((Number)toTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line"); assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line");
selectedOrderRow = i; selectedOrderRow = i;
break; break;
@ -648,11 +636,11 @@ public class MatchPOTest extends AbstractTestCase {
assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount()); assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount());
selectedRow = -1; selectedRow = -1;
for(int i = 0; i < fromTable.getRowCount(); i++) { for(int i = 0; i < fromTable.getRowCount(); i++) {
String docNo = (String)fromTable.getValueAt(i, 1); String docNo = (String)fromTable.getValueAt(i, Match.I_DocumentNo);
if (receipt.getDocumentNo().equals(docNo)) { if (receipt.getDocumentNo().equals(docNo)) {
int matched = ((Number)fromTable.getValueAt(i, 7)).intValue(); int matched = ((Number)fromTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for Material Receipt line"); assertEquals(0, matched, "Unexpected matched qty for Material Receipt line");
int qty = ((Number)fromTable.getValueAt(i, 6)).intValue(); int qty = ((Number)fromTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line"); assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line");
selectedRow = i; selectedRow = i;
break; break;
@ -664,11 +652,11 @@ public class MatchPOTest extends AbstractTestCase {
assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount()); assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount());
selectedOrderRow = -1; selectedOrderRow = -1;
for(int i = 0; i < toTable.getRowCount(); i++) { for(int i = 0; i < toTable.getRowCount(); i++) {
String docNo = (String)toTable.getValueAt(i, 1); String docNo = (String)toTable.getValueAt(i, Match.I_DocumentNo);
if (order.getDocumentNo().equals(docNo)) { if (order.getDocumentNo().equals(docNo)) {
int matched = ((Number)toTable.getValueAt(i, 7)).intValue(); int matched = ((Number)toTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for PO line"); assertEquals(0, matched, "Unexpected matched qty for PO line");
int qty = ((Number)toTable.getValueAt(i, 6)).intValue(); int qty = ((Number)toTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line"); assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line");
selectedOrderRow = i; selectedOrderRow = i;
break; break;
@ -676,7 +664,7 @@ public class MatchPOTest extends AbstractTestCase {
} }
assertTrue(selectedOrderRow >= 0, "Can't find not matched PO line"); assertTrue(selectedOrderRow >= 0, "Can't find not matched PO line");
IDColumn idColumn = (IDColumn)toTable.getValueAt(selectedOrderRow, 0); IDColumn idColumn = (IDColumn)toTable.getValueAt(selectedOrderRow, Match.I_ID);
idColumn.setSelected(true); idColumn.setSelected(true);
match.cmd_process(fromTable, toTable, Match.MODE_NOTMATCHED, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), new BigDecimal(1)); match.cmd_process(fromTable, toTable, Match.MODE_NOTMATCHED, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), new BigDecimal(1));
@ -769,22 +757,13 @@ public class MatchPOTest extends AbstractTestCase {
newOnHand = MStorageOnHand.getQtyOnHand(product.get_ID(), getM_Warehouse_ID(), 0, getTrxName()).intValue(); newOnHand = MStorageOnHand.getQtyOnHand(product.get_ID(), getM_Warehouse_ID(), 0, getTrxName()).intValue();
assertEquals(initialOnHand+1, newOnHand, "Unexpected qty on hand value"); assertEquals(initialOnHand+1, newOnHand, "Unexpected qty on hand value");
Match match = new Match();
match.setTrxName(getTrxName());
MiniTableImpl fromTable = new MiniTableImpl(); MiniTableImpl fromTable = new MiniTableImpl();
MiniTableImpl toTable = new MiniTableImpl(); MiniTableImpl toTable = new MiniTableImpl();
ColumnInfo[] layout = new ColumnInfo[] { ColumnInfo[] layout = match.getColumnLayout();
new ColumnInfo(" ", ".", IDColumn.class, false, false, ""),
new ColumnInfo(Msg.translate(Env.getCtx(), "DocumentNo"), ".", String.class), // 1
new ColumnInfo(Msg.translate(Env.getCtx(), "Date"), ".", Timestamp.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"),".", KeyNamePair.class, "."), // 3
new ColumnInfo(Msg.translate(Env.getCtx(), "Line"), ".", KeyNamePair.class, "."),
new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class, "."), // 5
new ColumnInfo(Msg.translate(Env.getCtx(), "Qty"), ".", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Matched"), ".", Double.class)
};
fromTable.prepareTable(layout, null, null, false, null); fromTable.prepareTable(layout, null, null, false, null);
toTable.prepareTable(layout, null, null, false, null); toTable.prepareTable(layout, null, null, false, null);
Match match = new Match();
match.setTrxName(getTrxName());
match.cmd_search(fromTable, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), product.get_ID(), bpartner.get_ID(), null, null, false); match.cmd_search(fromTable, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), product.get_ID(), bpartner.get_ID(), null, null, false);
assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount()); assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount());
int selectedRow = -1; int selectedRow = -1;
@ -843,11 +822,11 @@ public class MatchPOTest extends AbstractTestCase {
assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount()); assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount());
selectedRow = -1; selectedRow = -1;
for(int i = 0; i < fromTable.getRowCount(); i++) { for(int i = 0; i < fromTable.getRowCount(); i++) {
String docNo = (String)fromTable.getValueAt(i, 1); String docNo = (String)fromTable.getValueAt(i, Match.I_DocumentNo);
if (receipt.getDocumentNo().equals(docNo)) { if (receipt.getDocumentNo().equals(docNo)) {
int matched = ((Number)fromTable.getValueAt(i, 7)).intValue(); int matched = ((Number)fromTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for Material Receipt line"); assertEquals(0, matched, "Unexpected matched qty for Material Receipt line");
int qty = ((Number)fromTable.getValueAt(i, 6)).intValue(); int qty = ((Number)fromTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line"); assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line");
selectedRow = i; selectedRow = i;
break; break;
@ -859,11 +838,11 @@ public class MatchPOTest extends AbstractTestCase {
assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount()); assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount());
selectedOrderRow = -1; selectedOrderRow = -1;
for(int i = 0; i < toTable.getRowCount(); i++) { for(int i = 0; i < toTable.getRowCount(); i++) {
String docNo = (String)toTable.getValueAt(i, 1); String docNo = (String)toTable.getValueAt(i, Match.I_DocumentNo);
if (order.getDocumentNo().equals(docNo)) { if (order.getDocumentNo().equals(docNo)) {
int matched = ((Number)toTable.getValueAt(i, 7)).intValue(); int matched = ((Number)toTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for PO line"); assertEquals(0, matched, "Unexpected matched qty for PO line");
int qty = ((Number)toTable.getValueAt(i, 6)).intValue(); int qty = ((Number)toTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line"); assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line");
selectedOrderRow = i; selectedOrderRow = i;
break; break;
@ -871,7 +850,7 @@ public class MatchPOTest extends AbstractTestCase {
} }
assertTrue(selectedOrderRow >= 0, "Can't find not matched PO line"); assertTrue(selectedOrderRow >= 0, "Can't find not matched PO line");
IDColumn idColumn = (IDColumn)toTable.getValueAt(selectedOrderRow, 0); IDColumn idColumn = (IDColumn)toTable.getValueAt(selectedOrderRow, Match.I_ID);
idColumn.setSelected(true); idColumn.setSelected(true);
match.cmd_process(fromTable, toTable, Match.MODE_NOTMATCHED, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), new BigDecimal(1)); match.cmd_process(fromTable, toTable, Match.MODE_NOTMATCHED, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), new BigDecimal(1));

View File

@ -0,0 +1,166 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test.form;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import org.compiere.apps.form.Match;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MBPartner;
import org.compiere.model.MInOut;
import org.compiere.model.MInOutLine;
import org.compiere.model.MMatchPO;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MProduct;
import org.compiere.model.MWarehouse;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
import org.compiere.util.Env;
import org.compiere.wf.MWorkflow;
import org.idempiere.test.AbstractTestCase;
import org.idempiere.test.DictionaryIDs;
import org.idempiere.test.ui.MiniTableImpl;
import org.junit.jupiter.api.Test;
public class MatchFormTest extends AbstractTestCase {
public MatchFormTest() {
}
@Test
public void testMatchReceiptToPO() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.TREE_FARM.id);
MProduct product = MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id);
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(bpartner);
order.setIsSOTrx(false);
order.setC_DocTypeTarget_ID();
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
order.saveEx();
BigDecimal orderQty = new BigDecimal("1");
MOrderLine orderLine = new MOrderLine(order);
orderLine.setLine(10);
orderLine.setProduct(product);
orderLine.setQty(orderQty);
orderLine.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
orderLine.load(getTrxName());
assertEquals(1, orderLine.getQtyReserved().intValue(), "Unexpected order line qty ordered value");
assertEquals(0, orderLine.getQtyDelivered().intValue(), "Unexpected order line qty delivered value");
MInOut receipt = new MInOut(Env.getCtx(), 0, getTrxName());
receipt.setBPartner(bpartner);
receipt.setIsSOTrx(false);
receipt.setC_DocType_ID(DictionaryIDs.C_DocType.MM_RECEIPT.id);
receipt.setM_Warehouse_ID(getM_Warehouse_ID());
receipt.saveEx();
MWarehouse wh = MWarehouse.get(Env.getCtx(), receipt.getM_Warehouse_ID());
int M_Locator_ID = wh.getDefaultLocator().getM_Locator_ID();
BigDecimal receiptQty = new BigDecimal("1");
MInOutLine receiptLine = new MInOutLine(receipt);
receiptLine.setProduct(product);
receiptLine.setM_Locator_ID(M_Locator_ID);
receiptLine.setLine(10);
receiptLine.setQty(receiptQty);
receiptLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, receipt.getDocStatus());
orderLine.load(getTrxName());
assertEquals(1, orderLine.getQtyReserved().intValue(), "Unexpected order line qty ordered value");
assertEquals(0, orderLine.getQtyDelivered().intValue(), "Unexpected order line qty delivered value");
Match match = new Match();
match.setTrxName(getTrxName());
ColumnInfo[] columnLayout = match.getColumnLayout();
MiniTableImpl fromTable = new MiniTableImpl();
MiniTableImpl toTable = new MiniTableImpl();
fromTable.prepareTable(columnLayout, null, null, false, null);
toTable.prepareTable(columnLayout, null, null, false, null);
//load not matched shipments
match.cmd_search(fromTable, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), product.get_ID(), bpartner.get_ID(), null, null, false);
assertTrue(fromTable.getRowCount()>0, "Unexpected number of records for not matched Material Receipt: " + fromTable.getRowCount());
int selectedRow = -1;
for(int i = 0; i < fromTable.getRowCount(); i++) {
String docNo = (String)fromTable.getValueAt(i, Match.I_DocumentNo);
if (receipt.getDocumentNo().equals(docNo)) {
int matched = ((Number)fromTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for Material Receipt line");
int qty = ((Number)fromTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(receiptLine.getMovementQty().intValue(), qty, "Unexpected qty for Material Receipt line");
selectedRow = i;
break;
}
}
assertTrue(selectedRow >= 0, "Can't find not matched Material Receipt line");
fromTable.setSelectedRow(selectedRow);
//load not matched orders
match.cmd_searchTo(fromTable, toTable, match.getMatchTypeText(Match.MATCH_ORDER), Match.MATCH_SHIPMENT, true, true, true, false);
assertTrue(toTable.getRowCount()>0, "Unexpected number of records for not matched Order Line: " + fromTable.getRowCount());
int selectedOrderRow = -1;
for(int i = 0; i < toTable.getRowCount(); i++) {
String docNo = (String)toTable.getValueAt(i, Match.I_DocumentNo);
if (order.getDocumentNo().equals(docNo)) {
int matched = ((Number)toTable.getValueAt(i, Match.I_MATCHED)).intValue();
assertEquals(0, matched, "Unexpected matched qty for PO line");
int qty = ((Number)toTable.getValueAt(i, Match.I_QTY)).intValue();
assertEquals(orderLine.getQtyOrdered().intValue(), qty, "Unexpected qty for PO line");
selectedOrderRow = i;
break;
}
}
assertTrue(selectedOrderRow >= 0, "Can't find not matched PO line");
//select and process matching
IDColumn idColumn = (IDColumn)toTable.getValueAt(selectedOrderRow, Match.I_ID);
idColumn.setSelected(true);
match.cmd_process(fromTable, toTable, Match.MODE_NOTMATCHED, Match.MATCH_SHIPMENT, match.getMatchTypeText(Match.MATCH_ORDER), new BigDecimal(1));
orderLine.load(getTrxName());
assertEquals(0, orderLine.getQtyReserved().intValue(), "Unexpected order line qty ordered value");
assertEquals(1, orderLine.getQtyDelivered().intValue(), "Unexpected order line qty delivered value");
receiptLine.load(getTrxName());
assertEquals(orderLine.getC_OrderLine_ID(), receiptLine.getC_OrderLine_ID(), "Unexpected order line ID value for receipt line");
MMatchPO[] matchPOs = MMatchPO.getOrderLine(Env.getCtx(), orderLine.get_ID(), getTrxName());
assertEquals(1, matchPOs.length, "Unexpected number of MatchPO for order line");
}
}