Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0046217Openbravo ERPA. Platformpublic2021-04-06 13:472022-02-01 07:24
vmromanos 
Triage Platform Base 
normalminoralways
newopen 
5
 
 
Core
No
0046217: Organization entity and OBCriteria.setFilterOnReadableOrganization(true) won't work
In OBCriteria.initialize() we have the following code:

    if (isFilterOnReadableOrganization() && e.isOrganizationPartOfKey()) {
      add(Restrictions.in("id." + PROPERTY_ORGANIZATION + ".id",
          (Object[]) obContext.getReadableOrganizations()));

    } else if (isFilterOnReadableOrganization() && e.isOrganizationEnabled()) {
      add(Restrictions.in(PROPERTY_ORGANIZATION + ".id",
          (Object[]) obContext.getReadableOrganizations()));
    }

In order to add the readable organizations filter the entity should either isOrganizationPartOfKey() or isOrganizationEnabled().


Both methods depend on variables set at Property.initializeName() method:
   
    if (getName().equals("organization")) {
      setClientOrOrganization(true);
      getEntity().setOrganizationEnabled(true);
      if (isId() || isPartOfCompositeId()) {
        getEntity().setOrganizationPartOfKey(true);
      }
    }

In the case of the Organization entity we don't have a property called "organization" because it's actually the entity's "id", so Organization is never set as organizationEnabled or organizationPartOfKey, so the OBCriteria never adds the filter over the readable organizations.


Note this is a corner case that should only happen when querying the Organization entity using the OBCriteria. Any other entity should be safe.

Right now any OBCriteria over the Organization entity doesn't add any filter to readable organizations, which means the query is run for every organization (unless the OBCriteria instance adds an explicit filter over the organization's ids).
Create a simple OBCriteria over Organization entity. Example:

OBCriteria<Organization> orgCriteria = OBDal.getInstance().createCriteria(Organization.class);
orgCriteria.setMaxResults(1);
orgCriteria.uniqueResult();

Set a breakpoint at OBCriteria.initialize() [in the above code].
Verify isFilterOnReadableOrganization() is true, but the Restriction over the readable organizations is not added.
No tags attached.
related to defect 0046178 closed markmm82 Avoid trying to find the general ledger configuration if it is not configured in any organization 
Issue History
2021-04-06 13:47vmromanosNew Issue
2021-04-06 13:47vmromanosAssigned To => platform
2021-04-06 13:47vmromanosModules => Core
2021-04-06 13:47vmromanosTriggers an Emergency Pack => No
2021-04-06 14:24vmromanosRelationship addedrelated to 0046178
2022-02-01 07:24alostaleAssigned Toplatform => Triage Platform Base

There are no notes attached to this issue.