From 09df36a78fb6ff8b6cc7c70f13c2d98ce30f9edf Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 1 Apr 2023 05:18:09 +0200 Subject: [PATCH] IDEMPIERE-5528 IDEMPIERE-5560 Cannot save more than one order line when an _ID field is not displayed (#1763) --- .../org/idempiere/test/AbstractTestCase.java | 10 ++ .../idempiere/test/adwindow/GridTabTest.java | 105 ++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/org.idempiere.test/src/org/idempiere/test/AbstractTestCase.java b/org.idempiere.test/src/org/idempiere/test/AbstractTestCase.java index 2b8792ab33..efffcf2ce8 100644 --- a/org.idempiere.test/src/org/idempiere/test/AbstractTestCase.java +++ b/org.idempiere.test/src/org/idempiere/test/AbstractTestCase.java @@ -34,9 +34,13 @@ import org.adempiere.util.ServerContext; import org.compiere.Adempiere; import org.compiere.model.MAcctSchema; import org.compiere.model.MClientInfo; +import org.compiere.model.MOrg; import org.compiere.model.MRole; +import org.compiere.model.MWarehouse; import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; import org.compiere.util.Language; +import org.compiere.util.Login; import org.compiere.util.Trx; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -144,6 +148,12 @@ public abstract class AbstractTestCase { } } } + KeyNamePair knpo = new KeyNamePair(loginDetails.getOrganizationId(), MOrg.get(loginDetails.getOrganizationId()).getName()); + KeyNamePair knpw = null; + if (loginDetails.getWarehouseId() > 0) + knpw = new KeyNamePair(loginDetails.getWarehouseId(), MWarehouse.get(loginDetails.getWarehouseId()).getName()); + Login login = new Login(Env.getCtx()); + login.loadPreferences(knpo, knpw, loginDetails.getLoginDate(), null); } @AfterEach diff --git a/org.idempiere.test/src/org/idempiere/test/adwindow/GridTabTest.java b/org.idempiere.test/src/org/idempiere/test/adwindow/GridTabTest.java index 464731c00d..73f9888013 100644 --- a/org.idempiere.test/src/org/idempiere/test/adwindow/GridTabTest.java +++ b/org.idempiere.test/src/org/idempiere/test/adwindow/GridTabTest.java @@ -29,14 +29,24 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.adempiere.base.Core; +import org.compiere.model.DataStatusEvent; +import org.compiere.model.DataStatusListener; import org.compiere.model.GridField; import org.compiere.model.GridTab; +import org.compiere.model.GridTable; import org.compiere.model.GridWindow; import org.compiere.model.GridWindowVO; import org.compiere.model.MBPartner; +import org.compiere.model.MField; +import org.compiere.model.MLookup; import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; import org.compiere.model.MQuery; import org.compiere.model.SystemIDs; +import org.compiere.util.CLogger; +import org.compiere.util.CacheMgt; +import org.compiere.util.DB; import org.compiere.util.Env; import org.idempiere.test.AbstractTestCase; import org.idempiere.test.DictionaryIDs; @@ -49,6 +59,8 @@ import org.junit.jupiter.api.Test; */ public class GridTabTest extends AbstractTestCase { + private static final int FIELD_ORDERLINE_SHIPPER = 1135; + public GridTabTest() { } @@ -172,4 +184,97 @@ public class GridTabTest extends AbstractTestCase { assertTrue(updateValue.equals(description), "GridTab Description != Update Value. GridTab.Description="+description); assertTrue(bpartner.getDescription().equals(description), "GridTab Description != MBPartner.getDescription(). GridTab.Description="+description+ " MBPartner.getDescription="+bpartner.getDescription()); } + + @Test + public void testInsert() { + + MField field = new MField(Env.getCtx(), FIELD_ORDERLINE_SHIPPER, getTrxName()); + boolean displayOri = field.isDisplayed(); + boolean displayGridOri = field.isDisplayed(); + try { + /* IDEMPIERE-5560 */ + DB.executeUpdateEx("UPDATE AD_Field SET IsDisplayed='N', IsDisplayedGrid='N' WHERE AD_Field_ID=?", new Object[] {FIELD_ORDERLINE_SHIPPER}, getTrxName()); + // we need to commit here for the test case below to get the update + commit(); + CacheMgt.get().reset(); + + // Sales Order + int AD_Window_ID = SystemIDs.WINDOW_SALES_ORDER; + var gWindowVO = GridWindowVO.create(Env.getCtx(), 1, AD_Window_ID); + var gridWindow = new GridWindow(gWindowVO, true); + int tabCount = gridWindow.getTabCount(); + assertTrue(tabCount > 0, "Tab Count is Zero. AD_Window_ID=" + AD_Window_ID); + + for (int i = 0; i < gridWindow.getTabCount(); i++) { + gridWindow.initTab(i); + GridTab gTab = gridWindow.getTab(i); + if (i == 0) { + gTab.setQuery(null); + gTab.query(false, 7, 0); + } + gTab.addDataStatusListener(new DataStatusListener() { + @Override + public void dataStatusChanged(DataStatusEvent e) { + int col = e.getChangedColumn(); + if (col < 0) + return; + GridTab gridTab = null; + if (e.getSource() != null && e.getSource() instanceof GridTable) { + GridTable gt = (GridTable) e.getSource(); + gridTab = gridWindow.getTab(gt.getTabNo()); + if (gridTab.getAD_Table_ID() != e.AD_Table_ID) + throw new RuntimeException("Table doesn't match with updated tab"); + } + // Process Callout + GridField mField = gridTab.getField(col); + if (mField != null && (mField.getCallout().length() > 0 + || (Core.findCallout(gridTab.getTableName(), mField.getColumnName())).size() > 0 + || gridTab.hasDependants(mField.getColumnName()))) { + gridTab.processFieldChange(mField); // Dependencies & Callout + // Refresh the list on dependant fields + for (GridField dependentField : gridTab.getDependantFields(mField.getColumnName())) { + // if the field has a lookup + if (dependentField != null && dependentField.getLookup() instanceof MLookup) { + MLookup mLookup = (MLookup) dependentField.getLookup(); + // if the lookup is dynamic (i.e. contains this columnName as variable) + if (mLookup.getValidation().indexOf("@" + mField.getColumnName() + "@") != -1) { + mLookup.refresh(); + } + } + } // for all dependent fields + + } + } + }); + } + + // insert new row + GridTab gTab0 = gridWindow.getTab(0); + assertTrue(gTab0.dataNew(false)); + assertTrue(gTab0.isNew(), "Grid Tab dataNew call not working as expected"); + gTab0.setValue(MOrder.COLUMNNAME_C_BPartner_ID, DictionaryIDs.C_BPartner.C_AND_W.id); + assertTrue(gTab0.dataSave(true), CLogger.retrieveWarningString("Could not save order")); + + GridTab gTab1 = gridWindow.getTab(1); + if (!gTab1.getTableModel().isOpen()) + gTab1.getTableModel().open(0); + assertTrue(gTab1.dataNew(false)); + gTab1.setValue(MOrderLine.COLUMNNAME_M_Product_ID, DictionaryIDs.M_Product.AZALEA_BUSH.id); + assertTrue(gTab1.dataSave(true)); + + assertTrue(gTab1.dataNew(false)); + gTab1.setValue(MOrderLine.COLUMNNAME_M_Product_ID, DictionaryIDs.M_Product.SEEDER.id); + assertTrue(gTab1.dataSave(true)); + + } finally { + // rollback the work from the test + rollback(); + DB.executeUpdateEx("UPDATE AD_Field SET IsDisplayed=?, IsDisplayedGrid=? WHERE AD_Field_ID=?", new Object[] {displayOri, displayGridOri, FIELD_ORDERLINE_SHIPPER}, getTrxName()); + // commit the cleanup + commit(); + CacheMgt.get().reset(); + } + + } + }