Fixes issue 34018: Is possible posting a Purchase Invoice with Finance role
authorMark <markmm82@gmail.com>
Mon, 19 Sep 2016 11:33:17 -0400
changeset 30558 9388451efb97
parent 30557 9fe27cd2151e
child 30559 3f07553793a6
Fixes issue 34018: Is possible posting a Purchase Invoice with Finance role

Modified the OrganizationStructureProvider.getPeriodControlAllowedOrganization() method to execute in Admin mode.
src/org/openbravo/dal/security/OrganizationStructureProvider.java
--- a/src/org/openbravo/dal/security/OrganizationStructureProvider.java	Mon Sep 19 14:24:57 2016 +0000
+++ b/src/org/openbravo/dal/security/OrganizationStructureProvider.java	Mon Sep 19 11:33:17 2016 -0400
@@ -465,15 +465,21 @@
    *          Organization to get its period control allowed organization.
    */
   public Organization getPeriodControlAllowedOrganization(final Organization org) {
-    if (org.isAllowPeriodControl()) {
-      return org;
+    // Admin mode needed to get the Organization type.
+    OBContext.setAdminMode(true);
+    try {
+      if (org.isAllowPeriodControl()) {
+        return org;
+      }
+      for (final String orgId : getParentList(org.getId(), false)) {
+        final Organization parentOrg = OBDal.getInstance().get(Organization.class, orgId);
+        if (parentOrg.isAllowPeriodControl()) {
+          return parentOrg;
+        }
+      }
+      return null;
+    } finally {
+      OBContext.restorePreviousMode();
     }
-    for (final String orgId : getParentList(org.getId(), false)) {
-      final Organization parentOrg = OBDal.getInstance().get(Organization.class, orgId);
-      if (parentOrg.isAllowPeriodControl()) {
-        return parentOrg;
-      }
-    }
-    return null;
   }
 }
\ No newline at end of file