
# HG changeset patch
# User Adrián Romero <adrianromero@openbravo.com>
# Date 1487066904 -3600
# Node ID 898b94330afe4077733384def84ccb7ef046d1ca
# Parent  f8f499ca7e4679f503e51a0b524c958df2c42ad6
Fixes issue 0035239: [SER-QA 2431] Complementary products does not uses *Remote products* preference
* Adds missing remote filter properties

diff -r f8f499ca7e46 -r 898b94330afe src/org/openbravo/retail/complementary/master/ComplementaryProducts.java
--- a/src/org/openbravo/retail/complementary/master/ComplementaryProducts.java	Mon Feb 13 12:29:17 2017 +0100
+++ b/src/org/openbravo/retail/complementary/master/ComplementaryProducts.java	Tue Feb 14 11:08:24 2017 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -52,6 +52,17 @@
   private Instance<ModelExtension> extensions;
 
   @Override
+  protected List<HQLPropertyList> getHqlProperties(JSONObject jsonsent) {
+    List<HQLPropertyList> propertiesList = new ArrayList<HQLPropertyList>();
+    HQLPropertyList regularBPLocationHQLProperties = ModelExtensionUtils
+        .getPropertyExtensions(extensions);
+
+    propertiesList.add(regularBPLocationHQLProperties);
+
+    return propertiesList;
+  }
+
+  @Override
   protected List<String> getQuery(JSONObject jsonsent) throws JSONException {
 
     List<String> hqlQueries = new ArrayList<String>();
@@ -65,7 +76,8 @@
         + " OBRECP_ComplementaryProduct compprd" + " where product = compprd.complementaryProduct"
         + " and pli.obretcoProductlist.id=:productListId " + " and ppp.product = product"
         + " and pplv.id=:priceListVersionId" + " and pplv.priceList.id=:priceListId"
-        + " and compprd.$readableCriteria" + " and pplv.$activeCriteria order by compprd.id");
+        + " and $filtersCriteria and compprd.$readableCriteria"
+        + " and pplv.$activeCriteria order by compprd.id");
 
     return hqlQueries;
   }
@@ -79,8 +91,8 @@
   protected Map<String, Object> getParameterValues(JSONObject jsonsent) throws JSONException {
 
     String orgId = OBContext.getOBContext().getCurrentOrganization().getId();
-    final Date terminalDate = OBMOBCUtils.calculateServerDate(jsonsent.getJSONObject("parameters")
-        .getString("terminalTime"),
+    final Date terminalDate = OBMOBCUtils.calculateServerDate(
+        jsonsent.getJSONObject("parameters").getString("terminalTime"),
         jsonsent.getJSONObject("parameters").getJSONObject("terminalTimeOffset").getLong("value"));
 
     final OBRETCOProductList productList = POSUtils.getProductListByOrgId(orgId);
diff -r f8f499ca7e46 -r 898b94330afe web/org.openbravo.retail.complementary/js/hooks/hookRenderOrderLine.js
--- a/web/org.openbravo.retail.complementary/js/hooks/hookRenderOrderLine.js	Mon Feb 13 12:29:17 2017 +0100
+++ b/web/org.openbravo.retail.complementary/js/hooks/hookRenderOrderLine.js	Tue Feb 14 11:08:24 2017 +0100
@@ -101,10 +101,22 @@
     var orderline = args.orderline;
 
     if (orderline.model.get('hasComplementary') === undefined) {
-      var product = orderline.model.get("product");
-      OB.Dal.find(OB.Model.ComplementaryProduct, {
-        productId: product.get('forceFilterId') ? product.get('forceFilterId') : product.id
-      }, function (data, args) {
+      var product = orderline.model.get('product');
+      var productId = product.get('forceFilterId') || product.id;
+      var criteria = {};
+
+      if (!OB.MobileApp.model.hasPermission('OBPOS_remote.product', true)) {
+        criteria.productId = productId;
+      } else {
+        criteria.remoteFilters = [{
+          columns: ['productId'],
+          operator: 'equals',
+          value: productId,
+          isId: true
+        }];
+      }
+
+      OB.Dal.find(OB.Model.ComplementaryProduct, criteria, function (data, args) {
         orderline.model.set('hasComplementary', data && data.length > 0);
         orderline.model.set('complementaryViewed', false);
         OBRECP_RenderLine(args, callbacks);

