fixes issue 40758
authorCarlos Aristu <carlos.aristu@openbravo.com>
Fri, 17 May 2019 15:09:06 +0200
changeset 36310 bbe0c764ef47
parent 36309 1596542c21af
fixes issue 40758
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java
src/org/openbravo/base/model/Property.java
src/org/openbravo/dal/core/OBInterceptor.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java	Fri May 17 11:14:19 2019 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/RemoveImagesEventHandler.java	Fri May 17 15:09:06 2019 +0200
@@ -36,6 +36,7 @@
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.ad.utility.Image;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.plm.Product;
 
 class RemoveImagesEventHandler extends EntityPersistenceEventObserver {
@@ -125,16 +126,18 @@
       return;
     }
 
+    Property orgProperty = event.getTargetInstance().getEntity().getProperty("organization");
+
     // Iterate image properties of the entity
     for (String property : getImageProperties(event.getTargetInstance().getEntity())) {
 
       Property imageProperty = event.getTargetInstance().getEntity().getProperty(property);
+      Image bob = (Image) event.getPreviousState(imageProperty);
 
       // If the old image is different than the new one remove the old image if exists
       if (event.getPreviousState(imageProperty) != null
           && event.getCurrentState(imageProperty) != event.getPreviousState(imageProperty)) {
 
-        Image bob = (Image) event.getPreviousState(imageProperty);
         if (bob != null) {
           String selectedProduct = event.getId();
           if (!checkImageUtilization(selectedProduct, bob)) {
@@ -146,6 +149,9 @@
             }
           }
         }
+      } else if (event.getPreviousState(orgProperty) != null
+          && event.getCurrentState(orgProperty) != event.getPreviousState(orgProperty)) {
+        bob.setOrganization((Organization) event.getCurrentState(orgProperty));
       }
     }
   }
--- a/src/org/openbravo/base/model/Property.java	Fri May 17 11:14:19 2019 +0200
+++ b/src/org/openbravo/base/model/Property.java	Fri May 17 15:09:06 2019 +0200
@@ -1349,4 +1349,11 @@
   public void setAllowedCrossOrgReference(boolean allowedCrossOrgReference) {
     this.allowedCrossOrgReference = allowedCrossOrgReference;
   }
+
+  public boolean isImage() {
+    if (referencedProperty == null) {
+      return false;
+    }
+    return "ADImage".equals(referencedProperty.getEntity().getName());
+  }
 }
--- a/src/org/openbravo/dal/core/OBInterceptor.java	Fri May 17 11:14:19 2019 +0200
+++ b/src/org/openbravo/dal/core/OBInterceptor.java	Fri May 17 15:09:06 2019 +0200
@@ -301,8 +301,10 @@
         }
 
         Property property = bob.getEntity().getProperty(propertyNames[i]);
+
         boolean skipCrossOrgCheck = (obContext.isInCrossOrgAdministratorMode()
-            && property.isAllowedCrossOrgReference()) || property.isAuditInfo();
+            && property.isAllowedCrossOrgReference()) || property.isAuditInfo()
+            || property.isImage();
 
         if (!skipCrossOrgCheck && !obObject.getEntity().isVirtualEntity()
             && !obContext.getOrganizationStructureProvider(o1.getClient().getId())