Fixes issue 16769: Filter the warehouses based on the -natural tree-
authorIván Perdomo <ivan.perdomo@openbravo.com>
Tue, 12 Apr 2011 20:26:57 +0200
changeset 11569 ee94070649ad
parent 11568 5976e82afd0b
child 11570 b5630110dd82
Fixes issue 16769: Filter the warehouses based on the -natural tree-
modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java	Tue Apr 12 16:31:51 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/navigationbarcomponents/UserInfoWidgetActionHandler.java	Tue Apr 12 20:26:57 2011 +0200
@@ -42,6 +42,7 @@
 import org.openbravo.client.kernel.StaticResourceComponent;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
@@ -190,15 +191,15 @@
 
   private JSONArray getWarehouses(String clientId) throws JSONException {
     List<JSONObject> orgWarehouseArray = new ArrayList<JSONObject>();
+    final OrganizationStructureProvider osp = OBContext.getOBContext()
+        .getOrganizationStructureProvider(clientId);
     OBCriteria<Organization> orgs = OBDal.getInstance().createCriteria(Organization.class);
     for (Organization org : orgs.list()) {
       JSONObject orgWarehouse = new JSONObject();
       orgWarehouse.put("orgId", org.getId());
-      final OBQuery<Warehouse> warehouses = OBDal
-          .getInstance()
-          .createQuery(Warehouse.class,
-              "ad_isorgincluded(organization.id, :orgId, :clientId)<>-1 and client.id=:clientId order by name");
-      warehouses.setNamedParameter("orgId", org.getId());
+      final OBQuery<Warehouse> warehouses = OBDal.getInstance().createQuery(Warehouse.class,
+          "organization.id in (:orgList) and client.id=:clientId order by name");
+      warehouses.setNamedParameter("orgList", osp.getNaturalTree(org.getId()));
       warehouses.setNamedParameter("clientId", clientId);
       warehouses.setFilterOnReadableClients(false);
       warehouses.setFilterOnReadableOrganization(false);