Fixed issue-44579: Product should be filtered before Import in M_Offer_Product table
authorRanjith S R <ranjith@qualiantech.com>
Fri, 17 Jul 2020 09:54:31 +0530
changeset 37496 48ebda2c4c42
parent 37495 adf4b4ee2ad5
child 37497 99a12fb6e02e
Fixed issue 44579: Product should be filtered before Import in M_Offer_Product table
* Before importing product in M_Offer_Product table, product should be filtered with Client and Org
modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/ImportProductInDiscount.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/ImportProductInDiscount.java	Wed Jul 15 17:36:22 2020 +0530
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/ImportProductInDiscount.java	Fri Jul 17 09:54:31 2020 +0530
@@ -73,7 +73,8 @@
 
         uploadResult.incTotalCount();
 
-        final List<String> productIds = getProductIds(productKey);
+        final List<String> productIds = getProductIds(discount.getClient().getId(),
+            discount.getOrganization().getId(), productKey);
         if (productIds.size() == 0) {
           uploadResult.incErrorCount();
           uploadResult.addErrorMessage(productKey + " --> " + errorMsgProductNotFound + "\n");
@@ -111,11 +112,14 @@
   }
 
   @SuppressWarnings("unchecked")
-  protected List<String> getProductIds(String productKey) {
-    String sql = "SELECT m_product_id from m_product where value=:value";
+  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";
     Session session = OBDal.getInstance().getSession();
     @SuppressWarnings("rawtypes")
-    NativeQuery qry = session.createNativeQuery(sql).setParameter("value", productKey);
+    NativeQuery qry = session.createNativeQuery(sql);
+    qry.setParameter("clientId", clientId);
+    qry.setParameter("orgId", orgId);
+    qry.setParameter("value", productKey);
     // only need max 2 to identify that there is more than one
     qry.setMaxResults(2);
     return (List<String>) qry.list();