diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index 3e87c08998..258121fe44 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -278,8 +278,11 @@ public class GridField */ public boolean refreshLookup() { - // if there is a validation string, the lookup is unstable - if (m_lookup == null || m_lookup.getValidation().length() == 0) + if (m_lookup == null) + return true; + + // if there is a validation string, the lookup is unstable - read-only fields are not loaded initially + if (m_lookup.getValidation().length() == 0 && m_lookup.isLoaded()) return true; // if (log.isLoggable(Level.FINE)) log.fine("(" + m_vo.ColumnName + ")"); @@ -836,7 +839,7 @@ public class GridField // need to re-set invalid values - OK BPartner in PO Line - not OK SalesRep in Invoice if (m_lookup.getDirect(m_value, false, true) == null) { - if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " Serach not valid - set to null"); + if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " Search not valid - set to null"); setValue(null, m_inserting); m_error = true; return false; @@ -845,14 +848,24 @@ public class GridField } // cannot be validated - if (!isLookup() - || m_lookup == null - || m_lookup.containsKeyNoDirect(m_value)) + if (!isLookup() || m_lookup == null) return true; + if (m_lookup.containsKeyNoDirect(m_value)) { + String name = m_lookup.get(m_value).getName(); + if (! ( name.startsWith(MLookup.INACTIVE_S) && name.endsWith(MLookup.INACTIVE_E) ) ) { + return true; + } + } // it's not null, a lookup and does not have the key if (isKey() || isParentValue()) // parents/ket are not validated return true; + // special case for IDEMPIERE-2781 + if ( "AD_Client_ID".equals(m_vo.ColumnName) + && "0".equals(m_value.toString()) + && Env.getAD_Client_ID(Env.getCtx()) == 0) + return true; + if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " - set to null"); setValue(null, m_inserting); m_error = true; @@ -884,7 +897,7 @@ public class GridField // need to re-set invalid values - OK BPartner in PO Line - not OK SalesRep in Invoice if (m_lookup.getDirect(m_value, false, true) == null) { - if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " Serach not valid - set to null"); + if (log.isLoggable(Level.FINEST)) log.finest(m_vo.ColumnName + " Search not valid - set to null"); setValue(null, m_inserting); m_error = true; return false; diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index f03d68a759..c5266477e2 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -1186,10 +1186,9 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable setCurrentRow(m_currentRow + 1, true); // check validity of defaults - for (int i = 0; i < getFieldCount(); i++) - { - getField(i).refreshLookup(); - getField(i).validateValueNoDirect(); + for (GridField field : getFields()) { + field.refreshLookup(); + field.validateValueNoDirect(); } // process all Callouts (no dependency check - assumed that settings are valid) for (int i = 0; i < getFieldCount(); i++) diff --git a/org.adempiere.base/src/org/compiere/model/MLookup.java b/org.adempiere.base/src/org/compiere/model/MLookup.java index 1203477584..7f44ec8928 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLookup.java @@ -528,11 +528,16 @@ public final class MLookup extends Lookup implements Serializable rs = pstmt.executeQuery(); if (rs.next()) { - String name = rs.getString(3); + StringBuilder name = new StringBuilder().append(rs.getString(3)); + boolean isActive = rs.getString(4).equals("Y"); + if (!isActive) + { + name.insert(0, INACTIVE_S).append(INACTIVE_E); + } if (isNumber) { int keyValue = rs.getInt(1); - KeyNamePair p = new KeyNamePair(keyValue, name); + KeyNamePair p = new KeyNamePair(keyValue, name.toString()); if (saveInCache) // save if m_lookup.put(new Integer(keyValue), p); directValue = p; @@ -540,7 +545,7 @@ public final class MLookup extends Lookup implements Serializable else { String value = rs.getString(2); - ValueNamePair p = new ValueNamePair(value, name); + ValueNamePair p = new ValueNamePair(value, name.toString()); if (saveInCache) // save if m_lookup.put(value, p); directValue = p; @@ -855,7 +860,7 @@ public final class MLookup extends Lookup implements Serializable boolean isActive = rs.getString(4).equals("Y"); if (!isActive) { - name = new StringBuilder(INACTIVE_S).append(name).append(INACTIVE_E); + name.insert(0, INACTIVE_S).append(INACTIVE_E); m_hasInactive = true; } // IDEMPIERE 90 diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java index f12cb408f5..7690b12176 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WPAttributeEditor.java @@ -15,6 +15,8 @@ package org.adempiere.webui.editor; +import static org.compiere.model.SystemIDs.COLUMN_M_PRODUCT_M_ATTRIBUTESETINSTANCE_ID; + import java.util.logging.Level; import org.adempiere.webui.apps.AEnv; @@ -29,9 +31,6 @@ import org.adempiere.webui.window.WPAttributeDialog; import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.model.Lookup; -import org.compiere.model.MAttributeSet; -import org.compiere.model.MProduct; -import static org.compiere.model.SystemIDs.*; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.zkoss.zk.ui.event.Event;