Skip to content

Commit

Permalink
Issue #421: Added organization natural tree validation
Browse files Browse the repository at this point in the history
Currently the ImportProductInDiscount process only supports the loading of products from organizations equal to that of the discount, however it should be able to import products from natural tree organizations. The process has been modified to support the natural tree of organizations.
  • Loading branch information
jortolanosmf committed Jul 11, 2024
1 parent 1cb3bc1 commit 11bfba3
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;

import org.codehaus.jettison.json.JSONObject;
import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.openbravo.base.provider.OBProvider;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.security.OrganizationStructureProvider;
import org.openbravo.dal.service.OBDal;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.erpCommon.utility.OBMessageUtils;
Expand Down Expand Up @@ -113,12 +115,15 @@ protected UploadResult doProcessFile(JSONObject paramValues, File file) throws E

@SuppressWarnings("unchecked")
protected List<String> getProductIds(String clientId, String orgId, String productKey) {
String sql = "SELECT m_product_id from m_product where ad_client_id=:clientId and ad_org_id=:orgId and value=:value";
String sql = "SELECT m_product_id from m_product where ad_client_id=:clientId and ad_org_id in (:orgs) and value=:value";
Session session = OBDal.getInstance().getSession();
@SuppressWarnings("rawtypes")
NativeQuery qry = session.createNativeQuery(sql);
qry.setParameter("clientId", clientId);
qry.setParameter("orgId", orgId);
OrganizationStructureProvider osp = OBContext.getOBContext()
.getOrganizationStructureProvider(clientId);
Set<String> orgs = osp.getNaturalTree(orgId);
qry.setParameter("orgs", orgs);
qry.setParameter("value", productKey);
// only need max 2 to identify that there is more than one
qry.setMaxResults(2);
Expand Down

0 comments on commit 11bfba3

Please sign in to comment.