IDEMPIERE-5528 IDEMPIERE-5560 Cannot save more than one order line when an _ID field is not displayed (#1763)
This commit is contained in:
parent
d01555fa08
commit
09df36a78f
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue