details:   /erp/devel/pi/rev/d30629de0a4f
changeset: 11173:d30629de0a4f
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Mar 10 12:37:35 2011 +0100
summary:   Fixes issue 16199: Process plan window:Tab version is not working

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
 |  43 ++++++---
 1 files changed, 26 insertions(+), 17 deletions(-)

diffs (71 lines):

diff -r d5ed03e73444 -r d30629de0a4f 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
       Thu Mar 10 11:57:03 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
       Thu Mar 10 12:37:35 2011 +0100
@@ -27,7 +27,6 @@
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
-import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
@@ -108,33 +107,43 @@
    * @return the parentproperty in the source entity pointing to the parent
    */
   public static String getParentProperty(Tab tab, Tab parentTab) {
-    String parentProperty = "";
     final Entity thisEntity = 
ModelProvider.getInstance().getEntity(tab.getTable().getName());
     final Entity parentEntity = ModelProvider.getInstance().getEntity(
         parentTab.getTable().getName());
-    if (tab.getColumn() != null) {
-      final String columnId = (String) DalUtil.getId(tab.getColumn());
+    Property returnProperty = null;
+    // first try the real parent properties
+    for (Property property : thisEntity.getProperties()) {
+      if (property.isPrimitive() || property.isOneToMany()) {
+        continue;
+      }
+      if (property.isParent() && property.getTargetEntity() == parentEntity) {
+        returnProperty = property;
+        break;
+      }
+    }
+    // not found try any property
+    if (returnProperty == null) {
       for (Property property : thisEntity.getProperties()) {
-        if (property.isPrimitive() || property.isOneToMany() || 
property.isId()) {
-          continue;
-        }
-        if (property.getColumnId() != null && 
property.getColumnId().equals(columnId)) {
-          parentProperty = property.getName();
-          break;
-        }
-      }
-    } else {
-      for (Property property : thisEntity.getProperties()) {
-        if (property.isPrimitive() || property.isOneToMany() || 
property.isId()) {
+        if (property.isPrimitive() || property.isOneToMany()) {
           continue;
         }
         if (property.getTargetEntity() == parentEntity) {
-          parentProperty = property.getName();
+          returnProperty = property;
           break;
         }
       }
     }
-    return parentProperty;
+    // handle a special case, the property is an id, in that case
+    // use the related foreign key column to the parent
+    if (returnProperty.isId()) {
+      for (Property property : thisEntity.getProperties()) {
+        if (property.isOneToOne() && property.getTargetEntity() == 
parentEntity) {
+          returnProperty = property;
+          break;
+        }
+      }
+    }
+    return (returnProperty != null ? returnProperty.getName() : "");
   }
 
   public static boolean isClientAdmin() {

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to