[Change Password] Merge with pi
authorAlberto Santos <alberto.santos@openbravo.com>
Tue, 09 Feb 2016 09:45:56 +0100
changeset 28801 60fde1b7c191
parent 28800 75cb35d38d02 (current diff)
parent 28706 fbe443ccf95e (diff)
child 28802 25d249e69d3f
[Change Password] Merge with pi
lib/runtime/barcode4j-fop-ext-0.20.5-complete.jar
lib/runtime/jackson-annotations-2.1.4.jar
lib/runtime/jackson-core-2.1.4.jar
lib/runtime/jackson-databind-2.1.4.jar
modules/org.openbravo.service.json/src/org/openbravo/service/json/UnpagedRequestCachedPreference.java
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_FIELD.xml
--- a/legal/Licensing.txt	Mon Feb 08 16:14:49 2016 +0100
+++ b/legal/Licensing.txt	Tue Feb 09 09:45:56 2016 +0100
@@ -85,7 +85,7 @@
 # avalon-framework-4.1.5.jar
 # axis-ant.jar
 # axis.jar
-# barcode4j-fop-ext-0.20.5-complete.jar 
+# barcode4j-fop-ext-complete.jar 
 # batik-anim.jar
 # batik-awt-util.jar
 # batik-bridge.jar
@@ -119,6 +119,7 @@
 # tika-core-0.9.jar
 # wstx-asl-3.0.2.jar
 # xercesImpl.jar
+# xmlgraphics-commons-1.5.jar
 
 All files under Apache Software License 2.0, available at
 http://www.apache.org/licenses/LICENSE-2.0
@@ -140,9 +141,9 @@
 # itext-pdfa-5.5.0.jar
 Both files under AGPL V3 license with LGPL Exception (included as iTextpdf_license.txt in this folder)
 
-# jackson-core-2.1.4.jar
-# jackson-databind-2.1.4.jar
-# jackson-annotations-2.1.4.jar
+# jackson-core-2.5.1.jar
+# jackson-databind-2.5.1.jar
+# jackson-annotations-2.5.1.jar
 All files under the Apache 2.0 license (included as Apache_license-2.0.txt in this folder)
 
 # jasperreports-6.0.0.jar
Binary file lib/runtime/barcode4j-fop-ext-0.20.5-complete.jar has changed
Binary file lib/runtime/barcode4j-fop-ext-complete.jar has changed
Binary file lib/runtime/fop.jar has changed
Binary file lib/runtime/jackson-annotations-2.1.4.jar has changed
Binary file lib/runtime/jackson-annotations-2.5.1.jar has changed
Binary file lib/runtime/jackson-core-2.1.4.jar has changed
Binary file lib/runtime/jackson-core-2.5.1.jar has changed
Binary file lib/runtime/jackson-databind-2.1.4.jar has changed
Binary file lib/runtime/jackson-databind-2.5.1.jar has changed
Binary file lib/runtime/xmlgraphics-commons-1.5.jar has changed
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -16,7 +16,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) 2010-2015 Openbravo SLU
+* All portions are Copyright (C) 2010-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -1230,6 +1230,36 @@
   SET em_aprm_processinvoice = docaction
   WHERE c_invoice_id = p_record_id;
 
+  -- BEGIN Extension Point
+  SELECT count(*) INTO v_count FROM DUAL
+  WHERE EXISTS (SELECT 1 FROM ad_ep_procedures WHERE ad_extension_points_id = 'E845069AC5724A019D8A5343C396CAE8');
+  IF (v_count=1) THEN
+    DECLARE
+      v_ep_instance VARCHAR2(32);
+      v_extension_point_id VARCHAR2(32) := 'E845069AC5724A019D8A5343C396CAE8';
+    BEGIN
+      v_ep_instance := get_uuid();
+      AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'Record_ID', p_record_id, NULL, NULL, NULL, NULL, NULL, NULL);
+      AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'DocAction', p_docaction, NULL, NULL, NULL, NULL, NULL, NULL);
+      AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'User', p_user, NULL, NULL, NULL, NULL, NULL, NULL);
+      AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'Message', NULL, NULL, NULL, NULL, NULL, NULL, p_message);
+      AD_EP_INSTANCE_PARA_INSERT(v_ep_instance, v_extension_point_id, 'Result', NULL, NULL, p_result, NULL, NULL, NULL, NULL);
+      AD_EXTENSION_POINT_HANDLER(v_ep_instance, v_extension_point_id);
+      SELECT p_number INTO p_result
+      FROM ad_ep_instance_para
+      WHERE ad_ep_instance_id = v_ep_instance
+        AND parametername LIKE 'Result';
+      SELECT p_text INTO p_message
+      FROM ad_ep_instance_para
+      WHERE ad_ep_instance_id = v_ep_instance
+        AND parametername LIKE 'Message';
+
+      DELETE FROM ad_ep_instance_para
+      WHERE ad_ep_instance_id = v_ep_instance;
+    END;
+  END IF;
+  -- END Extension Point
+
 EXCEPTION
 WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE('APRM_GENERATE_PAYMENT_SCHEDULE exception: '|| v_ResultStr);
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_EXTENSION_POINTS.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_EXTENSION_POINTS.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -1,5 +1,15 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <data>
+<!--E845069AC5724A019D8A5343C396CAE8--><AD_EXTENSION_POINTS>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <AD_EXTENSION_POINTS_ID><![CDATA[E845069AC5724A019D8A5343C396CAE8]]></AD_EXTENSION_POINTS_ID>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <NAME><![CDATA[Aprm_Gen_PaymentSchedule_Inv Extension Point End]]></NAME>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <DESCRIPTION><![CDATA[Extension point at the end of Aprm_Gen_PaymentSchedule_Inv for managing migrated orders with debt payments.]]></DESCRIPTION>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--E845069AC5724A019D8A5343C396CAE8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E845069AC5724A019D8A5343C396CAE8--></AD_EXTENSION_POINTS>
+
 <!--F489FE52771F42E5B8CF228F26553726--><AD_EXTENSION_POINTS>
 <!--F489FE52771F42E5B8CF228F26553726-->  <AD_EXTENSION_POINTS_ID><![CDATA[F489FE52771F42E5B8CF228F26553726]]></AD_EXTENSION_POINTS_ID>
 <!--F489FE52771F42E5B8CF228F26553726-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -2302,6 +2302,34 @@
 <!--2224A72A74ED41E8AB02F64BB8C3637E-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--2224A72A74ED41E8AB02F64BB8C3637E--></AD_FIELD>
 
+<!--22EA1A8901F74633A9C8CF1EE262C6CD--><AD_FIELD>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <AD_FIELD_ID><![CDATA[22EA1A8901F74633A9C8CF1EE262C6CD]]></AD_FIELD_ID>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <NAME><![CDATA[Payment Method]]></NAME>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <DESCRIPTION><![CDATA[It is the method by which payment is expected to be made or received.]]></DESCRIPTION>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <AD_TAB_ID><![CDATA[2700A962BC484D4C9B3E30B1C3C66BFB]]></AD_TAB_ID>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <AD_COLUMN_ID><![CDATA[7DC34559B3F1B45BE040007F0100784A]]></AD_COLUMN_ID>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <DISPLAYLENGTH><![CDATA[0]]></DISPLAYLENGTH>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISREADONLY><![CDATA[Y]]></ISREADONLY>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <SEQNO><![CDATA[15]]></SEQNO>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <GRID_SEQNO><![CDATA[15]]></GRID_SEQNO>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--22EA1A8901F74633A9C8CF1EE262C6CD--></AD_FIELD>
+
 <!--233BB14B83864173A87AB9D3F328E0BA--><AD_FIELD>
 <!--233BB14B83864173A87AB9D3F328E0BA-->  <AD_FIELD_ID><![CDATA[233BB14B83864173A87AB9D3F328E0BA]]></AD_FIELD_ID>
 <!--233BB14B83864173A87AB9D3F328E0BA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MENU.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MENU.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -207,7 +207,7 @@
 <!--E6903C6E20814C82BF1CA9C92847A8A5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--E6903C6E20814C82BF1CA9C92847A8A5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--E6903C6E20814C82BF1CA9C92847A8A5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--E6903C6E20814C82BF1CA9C92847A8A5-->  <NAME><![CDATA[Process Price Difference adjustment]]></NAME>
+<!--E6903C6E20814C82BF1CA9C92847A8A5-->  <NAME><![CDATA[Process Price Difference Adjustment]]></NAME>
 <!--E6903C6E20814C82BF1CA9C92847A8A5-->  <ISSUMMARY><![CDATA[N]]></ISSUMMARY>
 <!--E6903C6E20814C82BF1CA9C92847A8A5-->  <ACTION><![CDATA[OBUIAPP_Process]]></ACTION>
 <!--E6903C6E20814C82BF1CA9C92847A8A5-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TREENODE.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TREENODE.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -40,8 +40,8 @@
 <!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <PARENT_ID><![CDATA[0]]></PARENT_ID>
-<!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <SEQNO><![CDATA[999]]></SEQNO>
+<!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <PARENT_ID><![CDATA[800256]]></PARENT_ID>
+<!--2A811D661ACE49AEB0E93419A4A4C2F3-->  <SEQNO><![CDATA[10]]></SEQNO>
 <!--2A811D661ACE49AEB0E93419A4A4C2F3--></AD_TREENODE>
 
 <!--3FD746883F8840E1BED768193D141802--><AD_TREENODE>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java	Tue Feb 09 09:45:56 2016 +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 - 2015 Openbravo SLU
+ * All portions are Copyright (C) 2014 - 2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -74,9 +74,9 @@
     StringBuffer joinClauseInvoice = getJoinClauseInvoice(requestParameters);
     StringBuffer whereClause = getWhereClause(transactionType, requestParameters, selectedPSDs);
     StringBuffer groupByClause = getGroupByClause(transactionType);
-    StringBuffer orderByClause = new StringBuffer();
+    List<String> orderByClauses = new ArrayList<String>();
     if (!justCount) {
-      orderByClause = getOrderByClause(transactionType, selectedPSDs, requestParameters);
+      orderByClauses = getOrderByClauses(transactionType, selectedPSDs, requestParameters);
     }
 
     // grid filters need to be removed from where clause and added as a having criteria.
@@ -103,7 +103,7 @@
     transformedHql = transformedHql.replace("@joinClauseInvoice@", joinClauseInvoice.toString());
     transformedHql = transformedHql.replace("@whereClause@", whereClause.toString());
     transformedHql = transformedHql.replace("@groupByClause@", groupByClause.toString());
-    transformedHql = appendOrderByClause(transformedHql, orderByClause, justCount);
+    transformedHql = appendOrderByClauses(transformedHql, orderByClauses, justCount);
     // Sets parameters
     queryNamedParameters.put("currencyId", requestParameters.get("c_currency_id"));
     queryNamedParameters.put("isSalesTransaction",
@@ -330,46 +330,48 @@
   /**
    * Order by selectedPSDs, scheduled date and document number
    */
-  protected StringBuffer getOrderByClause(String transactionType, List<String> selectedPSDs,
+  private List<String> getOrderByClauses(String transactionType, List<String> selectedPSDs,
       Map<String, String> requestParameters) {
-    StringBuffer orderByClause = new StringBuffer();
+    List<String> orderByClauses = new ArrayList<String>();
     if (selectedPSDs.size() == 0) {
       String strInvoiceId = requestParameters.get("c_invoice_id");
       String strOrderId = requestParameters.get("c_order_id");
       if (strInvoiceId != null) {
-        orderByClause.append(" CASE WHEN MAX(inv.id) = '" + strInvoiceId + "' THEN 0 ELSE 1 END ");
+        orderByClauses.add(" CASE WHEN MAX(inv.id) = '" + strInvoiceId + "' THEN 0 ELSE 1 END ");
       } else if (strOrderId != null) {
-        orderByClause.append(" CASE WHEN MAX(ord.id) = '" + strOrderId + "' THEN 0 ELSE 1 END ");
+        orderByClauses.add(" CASE WHEN MAX(ord.id) = '" + strOrderId + "' THEN 0 ELSE 1 END ");
       } else {
-        orderByClause.append(" CASE WHEN MAX(fp.id) IS NOT NULL THEN 0 ELSE 1 END ");
+        orderByClauses.add(" CASE WHEN MAX(fp.id) IS NOT NULL THEN 0 ELSE 1 END ");
       }
     } else {
+      StringBuffer selectedOrderBy = new StringBuffer();
       String strAggId = getAggregatorFunction("psd.id");
-      orderByClause.append(" CASE WHEN ");
+      selectedOrderBy.append(" CASE WHEN ");
       boolean isFirst = true;
       for (String strPSDId : selectedPSDs) {
         if (!isFirst) {
-          orderByClause.append(" OR ");
+          selectedOrderBy.append(" OR ");
         }
-        orderByClause.append(strAggId + " LIKE '%" + strPSDId + "%'");
+        selectedOrderBy.append(strAggId + " LIKE '%" + strPSDId + "%'");
         isFirst = false;
       }
-      orderByClause.append(" THEN 0 ELSE 1 END ");
+      selectedOrderBy.append(" THEN 0 ELSE 1 END ");
+      orderByClauses.add(selectedOrderBy.toString());
     }
     if ("O".equals(transactionType)) {
-      orderByClause.append(", COALESCE(opriority.priority, ipriority.priority) ");
-      orderByClause.append(", COALESCE(ops.expectedDate, ips.expectedDate) ");
+      orderByClauses.add(", COALESCE(opriority.priority, ipriority.priority) ");
+      orderByClauses.add(", COALESCE(ops.expectedDate, ips.expectedDate) ");
     } else {
-      orderByClause.append(", COALESCE(ipriority.priority, opriority.priority) ");
-      orderByClause.append(", COALESCE(ips.expectedDate, ops.expectedDate) ");
+      orderByClauses.add(", COALESCE(ipriority.priority, opriority.priority) ");
+      orderByClauses.add(", COALESCE(ips.expectedDate, ops.expectedDate) ");
     }
     if ("O".equals(transactionType)) {
-      orderByClause.append(", ord.documentNo ");
+      orderByClauses.add(", ord.documentNo ");
     } else {
-      orderByClause.append(", inv.documentNo ");
+      orderByClauses.add(", inv.documentNo ");
     }
 
-    return orderByClause;
+    return orderByClauses;
   }
 
   protected String removeGridFilters(String _hqlQuery) {
@@ -516,16 +518,23 @@
     return hqlQuery;
   }
 
-  protected String appendOrderByClause(String _hqlQuery, StringBuffer orderByClause,
+  private String appendOrderByClauses(String _hqlQuery, List<String> orderByClauses,
       boolean justCount) {
+    final String orderby = " ORDER BY ";
     String hqlQuery = _hqlQuery;
     if (!justCount) {
-      if (hqlQuery.contains(" ORDER BY ")) {
-        hqlQuery = hqlQuery.concat(", ");
+      if (hqlQuery.contains(orderby)) {
+        int offset = hqlQuery.indexOf(orderby) + orderby.length();
+        StringBuilder sb = new StringBuilder(hqlQuery);
+        sb.insert(offset, orderByClauses.get(0) + ", ");
+        hqlQuery = sb.toString();
+        orderByClauses.remove(0);
       } else {
-        hqlQuery = hqlQuery.concat(" ORDER BY ");
+        hqlQuery = hqlQuery.concat(orderby);
       }
-      hqlQuery = hqlQuery.concat(orderByClause.toString());
+      for (String clause : orderByClauses) {
+        hqlQuery = hqlQuery.concat(clause);
+      }
     }
     return hqlQuery;
   }
@@ -536,7 +545,8 @@
     JSONArray newCriteriaArray = new JSONArray();
     for (int i = 0; i < criteriaArray.length(); i++) {
       JSONObject criteria = criteriaArray.getJSONObject(i);
-      if (criteria.has("fieldName") && criteria.getString("fieldName").equals("id")) {
+      if (criteria.has("fieldName") && criteria.getString("fieldName").equals("id")
+          && criteria.has("value")) {
         String value = criteria.getString("value");
         for (String psdID : value.split(",")) {
           JSONObject newCriteria = criteria;
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java	Tue Feb 09 09:45:56 2016 +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) 2010-2015 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -1358,8 +1358,8 @@
       final StringBuilder whereClause = new StringBuilder();
       whereClause.append(" select pd." + FIN_PaymentDetail.PROPERTY_ID);
       whereClause.append(" from " + FIN_PaymentDetail.ENTITY_NAME + " as pd");
-      whereClause.append(" left join pd." + FIN_PaymentDetail.PROPERTY_FINPAYMENTSCHEDULEDETAILLIST
-          + " as psd");
+      whereClause.append(" inner join pd."
+          + FIN_PaymentDetail.PROPERTY_FINPAYMENTSCHEDULEDETAILLIST + " as psd");
       whereClause
           .append(" where pd." + FIN_PaymentDetail.PROPERTY_FINPAYMENT + ".id = :paymentId ");
       whereClause.append(" and pd." + FIN_PaymentDetail.PROPERTY_ACTIVE + " = true");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/CachedPreference.java	Tue Feb 09 09:45:56 2016 +0100
@@ -0,0 +1,141 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2016 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.businessUtility.Preferences;
+import org.openbravo.erpCommon.utility.PropertyException;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.common.enterprise.Organization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is used as a singleton to keep the value of some preferences in cache during the
+ * application life cycle, avoiding the time spent to compute the preference value. The preference
+ * values that can be cached by this class are those defined at System level.
+ * 
+ * This class it is also used by the
+ * {@link org.openbravo.client.application.event.PreferenceEventHandler} class to detect changes in
+ * the cached preferences values, and it that case it invalidates the stored value. This way the
+ * next time it is requested, the current value will be retrieved from database again.
+ * 
+ * This mechanism for automatic refresh the preference value, only works on environments with a
+ * single JVM. In case of Tomcat clustering environments (multiple JVM) it will be necessary to
+ * restart Tomcat to retrieve the new value of the preference in every JVM.
+ * 
+ */
+@ApplicationScoped
+public class CachedPreference {
+  public static final String ALLOW_UNPAGED_DS_MANUAL_REQUEST = "OBJSON_AllowUnpagedDatasourceManualRequest";
+
+  private static final Logger log = LoggerFactory.getLogger(CachedPreference.class);
+  private List<String> propertyList = new ArrayList<String>(
+      Arrays.asList(ALLOW_UNPAGED_DS_MANUAL_REQUEST));
+  private Map<String, String> cachedPreference = new HashMap<String, String>();
+
+  /**
+   * It returns a String with the value of the preference whose related property name is entered as
+   * parameter. In case the value is not stored in cache, then the value will be retrieved from
+   * database.
+   * 
+   * @param propertyName
+   *          The name of the property related to the preference
+   * 
+   * @return A String with the value of the cached preference
+   */
+  public String getPreferenceValue(String propertyName) {
+    long t = System.nanoTime();
+    if (!cachedPreference.containsKey(propertyName)) {
+      try {
+        OBContext.setAdminMode(false);
+        Client systemClient = OBDal.getInstance().get(Client.class, "0");
+        Organization asterisk = OBDal.getInstance().get(Organization.class, "0");
+        String value = Preferences.getPreferenceValue(propertyName, true, systemClient, asterisk,
+            null, null, null);
+        setPreferenceValue(propertyName, value);
+      } catch (PropertyException ignore) {
+        // Ignore the exception, caused because the preference was not found
+        setPreferenceValue(propertyName, null);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    }
+    log.debug("preference value retrieved in {} ns", (System.nanoTime() - t));
+    return cachedPreference.get(propertyName);
+  }
+
+  /**
+   * Checks if the preference related to the property name entered as parameter is contained in the
+   * list of cached preferences.
+   * 
+   * @param propertyName
+   *          The name of the property related to the preference
+   * @return true if the preference related to the property name is a cached preference, false
+   *         otherwise
+   */
+  public boolean isCachedPreference(String propertyName) {
+    return propertyList.contains(propertyName);
+  }
+
+  /**
+   * Sets the cached value of the preference. This method is defined as synchronized in order to
+   * avoid concurrency problems.
+   * 
+   * @param propertyName
+   *          The name of the property related to the preference
+   * @param preferenceValue
+   *          String with the value assigned to the preference
+   */
+  public synchronized void setPreferenceValue(String propertyName, String preferenceValue) {
+    this.cachedPreference.put(propertyName, preferenceValue);
+  }
+
+  /**
+   * Invalidates the cached value of the preference. This method is defined as synchronized in order
+   * to avoid concurrency problems.
+   * 
+   * @param propertyName
+   *          The name of the property related to the preference
+   */
+  public synchronized void invalidatePreferenceValue(String propertyName) {
+    this.cachedPreference.remove(propertyName);
+  }
+
+  /**
+   * Adds a new preference into the set of preferences whose value is stored in cache.
+   * 
+   * @param propertyName
+   *          The name of the property related to the preference to be cached
+   */
+  public void addCachedPreference(String propertyName) {
+    if (!isCachedPreference(propertyName)) {
+      propertyList.add(propertyName);
+    }
+  }
+}
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/PreferenceEventHandler.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/PreferenceEventHandler.java	Tue Feb 09 09:45:56 2016 +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) 2015 Openbravo SLU
+ * All portions are Copyright (C) 2015-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -25,20 +25,16 @@
 import org.apache.log4j.Logger;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
+import org.openbravo.client.application.CachedPreference;
 import org.openbravo.client.kernel.event.EntityDeleteEvent;
 import org.openbravo.client.kernel.event.EntityNewEvent;
 import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
 import org.openbravo.client.kernel.event.EntityUpdateEvent;
 import org.openbravo.model.ad.domain.Preference;
-import org.openbravo.service.json.UnpagedRequestCachedPreference;
 
 /**
  * Listens to delete, update and save events for the {@link Preference} entity. If it detects a
- * change in the 'OBJSON_AllowUnpagedDatasourceManualRequest' preference it invalidates its cached
- * value by setting it to null.
- * 
- * {@link "https://issues.openbravo.com/view.php?id=30204"}
- * 
+ * change in any of the cached preferences it invalidates its cached value.
  */
 public class PreferenceEventHandler extends EntityPersistenceEventObserver {
 
@@ -46,7 +42,7 @@
       .getEntity(Preference.ENTITY_NAME) };
   protected Logger logger = Logger.getLogger(this.getClass());
   @Inject
-  private UnpagedRequestCachedPreference unpagedRequestPreference;
+  private CachedPreference cachedPreference;
 
   @Override
   protected Entity[] getObservedEntities() {
@@ -58,9 +54,7 @@
       return;
     }
     final Preference preference = (Preference) event.getTargetInstance();
-    if (unpagedRequestPreference.getProperty().equals(preference.getProperty())) {
-      unpagedRequestPreference.setPreferenceValue(null);
-    }
+    invalidateCachedPreferenceValue(preference.getProperty());
   }
 
   public void onUpdate(@Observes EntityUpdateEvent event) {
@@ -68,9 +62,7 @@
       return;
     }
     final Preference preference = (Preference) event.getTargetInstance();
-    if (unpagedRequestPreference.getProperty().equals(preference.getProperty())) {
-      unpagedRequestPreference.setPreferenceValue(null);
-    }
+    invalidateCachedPreferenceValue(preference.getProperty());
   }
 
   public void onDelete(@Observes EntityDeleteEvent event) {
@@ -78,8 +70,12 @@
       return;
     }
     final Preference preference = (Preference) event.getTargetInstance();
-    if (unpagedRequestPreference.getProperty().equals(preference.getProperty())) {
-      unpagedRequestPreference.setPreferenceValue(null);
+    invalidateCachedPreferenceValue(preference.getProperty());
+  }
+
+  private void invalidateCachedPreferenceValue(String property) {
+    if (cachedPreference.isCachedPreference(property)) {
+      cachedPreference.invalidatePreferenceValue(property);
     }
   }
 }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TreeTablesEventHandler.java	Tue Feb 09 09:45:56 2016 +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) 2013-2014 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -37,6 +37,7 @@
 import org.openbravo.client.kernel.event.EntityDeleteEvent;
 import org.openbravo.client.kernel.event.EntityNewEvent;
 import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
+import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
@@ -62,7 +63,7 @@
 
   private static final String TREENODE_STRUCTURE = "ADTree";
   private static final String LINKTOPARENT_STRUCTURE = "LinkToParent";
-  // private static final String CUSTOM_STRUCTURE = "Custom";
+  private static final String CUSTOM_STRUCTURE = "Custom";
   private static Logger logger = LoggerFactory.getLogger(TreeTablesEventHandler.class);
 
   @Inject
@@ -128,6 +129,10 @@
       dataSource = dataSourceServiceProvider.getDataSource(TREENODE_DATASOURCE);
     } else if (LINKTOPARENT_STRUCTURE.equals(mainTableTree.getTreeStructure())) {
       dataSource = dataSourceServiceProvider.getDataSource(LINKTOPARENT_DATASOURCE);
+    } else if (CUSTOM_STRUCTURE.equals(mainTableTree.getTreeStructure())
+        && mainTableTree.getDatasource() != null) {
+      String customDataSourceId = (String) DalUtil.getId(mainTableTree.getDatasource());
+      dataSource = dataSourceServiceProvider.getDataSource(customDataSourceId);
     }
     return dataSource;
   }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js	Tue Feb 09 09:45:56 2016 +0100
@@ -45,8 +45,7 @@
   // for precision, the textual value is sent to the server
   // which can be transferred to a bigdecimal there
   changed: function (form, item, value) {
-    if (this.form.setTextualValue) {
-      this.form.setTextualValue(this.name, this.getEnteredValue(), this.typeInstance);
+    if (item && item.setValue) {
       item.setValue(this.getEnteredValue());
     }
     this.Super('changed', arguments);
@@ -441,9 +440,6 @@
         isFormula = true;
       }
       this.setValue(OB.Utilities.Number.OBMaskedToJS(value, this.typeInstance.decSeparator, this.typeInstance.groupSeparator));
-      if (this.form.setTextualValue) {
-        this.form.setTextualValue(this.name, value, this.typeInstance);
-      }
     } else {
       value = this.roundJsNumberUsingTypeInstance(this.getValue(), this.typeInstance);
       this.setValue(value);
@@ -470,10 +466,6 @@
       if (isFormula) {
         // the formula is evaluated in the validate function, so until then it is not possible to round it, do it now
         value = this.roundJsNumberUsingTypeInstance(value, this.typeInstance);
-        if (this.form.setTextualValue) {
-          textRoundedValue = OB.Utilities.Number.JSToOBMasked(value, this.typeInstance.maskNumeric, this.typeInstance.decSeparator, this.typeInstance.groupSeparator, OB.Format.defaultGroupingSize);
-          this.form.setTextualValue(this.name, textRoundedValue, this.typeInstance);
-        }
         this.setValue(value);
       }
       // first check if the number is valid
@@ -518,9 +510,6 @@
     if (OB.Utilities.Number.IsValidValueString(type, value)) {
       validator.resultingValue = OB.Utilities.Number.OBMaskedToJS(value, type.decSeparator, type.groupSeparator);
       item.storeValue(validator.resultingValue);
-      if (item.form && item.form.setTextualValue) {
-        item.form.setTextualValue(item.name, value, item.typeInstance);
-      }
       return true;
     } else {
       // don't loose illegal values
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-search.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-search.js	Tue Feb 09 09:45:56 2016 +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) 2011-2012 Openbravo SLU
+ * All portions are Copyright (C) 2011-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -70,7 +70,11 @@
         targetFld.form.focusInNextItem(targetFld.name);
       }
     }
-    isc.OBSearchItem.openedWindow.close();
+    if (isc.OBSearchItem.openedWindow.closeClick) {
+      isc.OBSearchItem.openedWindow.closeClick();
+    } else {
+      isc.OBSearchItem.openedWindow.close();
+    }
     isc.OBSearchItem.openSearchItem = null;
   };
 }(this)); // window
@@ -198,7 +202,11 @@
     left = parseInt((screen.width - width) / 2, 10);
 
     if (isc.OBSearchItem.openedWindow) {
-      isc.OBSearchItem.openedWindow.close();
+      if (isc.OBSearchItem.openedWindow.closeClick) {
+        isc.OBSearchItem.openedWindow.closeClick();
+      } else {
+        isc.OBSearchItem.openedWindow.close();
+      }
       this.clearUnloadEventHandling();
     }
     isc.OBSearchItem.openedWindow = null;
@@ -224,12 +232,9 @@
       }
     }
 
-    if (navigator.appName.indexOf('Netscape')) {
-      complementsNS4 = 'alwaysRaised=1, dependent=1, directories=0, hotkeys=0, menubar=0, ';
-    }
-    var complements = complementsNS4 + 'height=' + height + ', width=' + width + ', left=' + left + ', top=' + top + ', screenX=' + left + ', screenY=' + top + ', location=0, resizable=1, scrollbars=1, status=0, toolbar=0, titlebar=0, modal=\'yes\'';
-    isc.OBSearchItem.openedWindow = window.open(OB.Utilities.applicationUrl(url) + ((auxField === '') ? '' : '?' + auxField), 'SELECTOR', complements);
+    isc.OBSearchItem.openedWindow = OB.Layout.ClassicOBCompatibility.Popup.open('SELECTOR', width, height, OB.Utilities.applicationUrl(url) + ((auxField === '') ? '' : '?' + auxField), '', window, true, true, true, null, true);
     if (isc.OBSearchItem.openedWindow) {
+      isc.OBSearchItem.openedWindow.name = 'SELECTOR';
       isc.OBSearchItem.openedWindow.focus();
       this.setUnloadEventHandling();
     }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Tue Feb 09 09:45:56 2016 +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) 2010-2015 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -1192,11 +1192,6 @@
     if (field.compareValues && !field.compareValues(oldValue, this.getValue(field.name))) {
       field._changedByFic = true;
     }
-
-    // store the textualvalue so that it is correctly send back to the server
-    if ((columnValue.classicValue || columnValue.classicValue === '') && typeInstance.decSeparator) {
-      this.setTextualValue(field.name, assignClassicValue, typeInstance);
-    }
   },
 
   setColumnValuesInEditValues: function (columnName, columnValue, gridEditInformation) {
@@ -1268,19 +1263,11 @@
       // Look in the complete fields, the column might be hidden
       field = this.grid.getFieldFromColumnName(columnName);
     }
-
-    // store the textualvalue so that it is correctly send back to the server
-    if (field) {
-      // Adjust to formatting if exists value and classicValue.
-      assignClassicValue = (field.typeInstance && field.typeInstance.parseInput && field.typeInstance.editFormatter) ? field.typeInstance.editFormatter(field.typeInstance.parseInput(columnValue.classicValue)) : columnValue.classicValue;
-      typeInstance = isc.SimpleType.getType(field.type);
-      if ((columnValue.classicValue || columnValue.classicValue === '') && typeInstance.decSeparator) {
-        this.setTextualValue(field.name, assignClassicValue, typeInstance, gridEditInformation);
-      }
-    }
   },
 
   // note textValue is in user format using users decimal and group separator
+  // this method is deprecated as textual representation of decimals is no longer used
+  // see issue https://issues.openbravo.com/view.php?id=31901
   setTextualValue: function (fldName, textValue, type, gridEditInformation) {
     if (!textValue || textValue.trim() === '') {
       textValue = '';
@@ -2198,5 +2185,15 @@
       }
     }
     return true;
+  },
+
+  updateAlwaysTakeSpaceInSections: function () {
+    var i, item, length = this.getItems().length;
+    for (i = 0; i < length; i++) {
+      item = this.getItems()[i];
+      if (isc.isA.SectionItem(item) && item.isExpanded()){
+        item.updateAlwaysTakeSpace(true);
+      }
+    }
   }
 };
\ No newline at end of file
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Tue Feb 09 09:45:56 2016 +0100
@@ -1378,6 +1378,8 @@
     if (!this.isShowingForm) {
       if (!this.viewForm.getDataSource()) {
         this.prepareViewForm();
+      } else {
+        this.viewForm.updateAlwaysTakeSpaceInSections();
       }
       if (this.treeGrid) {
         if (this.isShowingTree) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Tue Feb 09 09:45:56 2016 +0100
@@ -185,6 +185,11 @@
       if (me.view && me.view.buttonOwnerView && me.view.buttonOwnerView.tabId) {
         dsRequest.params.buttonOwnerViewTabId = me.view.buttonOwnerView.tabId;
       }
+      // Add selected records (if any) when there is not criteria by id field present in the request
+      if (me.selectedIds.length > 0 && dsRequest.originalData && !me.isCriteriaWithIdField(dsRequest.originalData.criteria)) {
+        isc.addProperties(dsRequest.originalData, me.addSelectedIDsToCriteria());
+      }
+      dsRequest.params[OB.Constants.IS_PICK_AND_EDIT] = true;
       return this.Super('transformRequest', arguments);
     };
     filterableProperties = this.getFields().findAll('canFilter', true);
@@ -507,6 +512,13 @@
     this.Super('handleFilterEditorSubmit', [crit, context]);
   },
 
+  isCriteriaWithIdField: function (criteria) {
+    if (criteria && criteria.find('fieldName', 'id')) {
+      return true;
+    }
+    return false;
+  },
+
   isDataLoaded: function () {
     // When the data is being loaded, every element in the localData array is set with the "loading" value
     // So we just need to check the first position of the array
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-action-def.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-action-def.js	Tue Feb 09 09:45:56 2016 +0100
@@ -93,11 +93,12 @@
 // * {{{command}}}: The command with which the view to be opened
 // * {{{wait}}}: If true, the thread in which this action was called (if there is any) will be paused until the view be opened.
 OB.Utilities.Action.set('openDirectTab', function (paramObj) {
-  var processIndex, tabPosition;
+  var processIndex, tabPosition, isTabOpened = false;
   if (!paramObj.newTabPosition) {
     tabPosition = OB.Utilities.getTabNumberById(paramObj.tabId); // Search if the tab has been opened before
     if (tabPosition !== -1) {
       paramObj.newTabPosition = tabPosition;
+      isTabOpened = true;
     } else {
       processIndex = OB.Utilities.getProcessTabBarPosition(paramObj._processView);
       if (processIndex === -1) {
@@ -113,7 +114,7 @@
     OB.Utilities.openDirectTab(paramObj.tabId, paramObj.recordId, paramObj.command, paramObj.newTabPosition, paramObj.criteria);
   }
   if ((paramObj.wait === true || paramObj.wait === 'true') && paramObj.threadId) {
-    if (!OB.MainView.TabSet.getTabObject(paramObj.newTabPosition) || OB.MainView.TabSet.getTabObject(paramObj.newTabPosition).pane.isLoadingTab === true) {
+    if (!OB.MainView.TabSet.getTabObject(paramObj.newTabPosition) || OB.MainView.TabSet.getTabObject(paramObj.newTabPosition).pane.isLoadingTab === true || isTabOpened) {
       OB.Utilities.Action.pauseThread(paramObj.threadId);
       paramObj.isOpening = true;
       OB.Utilities.Action.execute('openDirectTab', paramObj, 100); //Call this action again with a 100ms delay
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js	Tue Feb 09 09:45:56 2016 +0100
@@ -627,7 +627,11 @@
     var index = url.indexOf('/', 1);
     url = url.substring(index + 1);
   }
-  OB.TestRegistry.register('org.openbravo.classicpopup.' + url, obj);
+  if (url.indexOf('?') !== -1 && url.indexOf('Command') === -1) {
+    OB.TestRegistry.register('org.openbravo.classicpopup.' + url.substring(0, url.indexOf('?')), obj);
+  } else {
+    OB.TestRegistry.register('org.openbravo.classicpopup.' + url, obj);
+  }
 };
 
 // ** {{{ OB.Utilities.isNonEmptyString(/*String*/ strValue }}} **
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl	Tue Feb 09 09:45:56 2016 +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) 2009-2013 Openbravo SLU
+ * All portions are Copyright (C) 2009-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -72,7 +72,8 @@
         TEXT_MATCH_PARAMETER_OVERRIDE: '_textMatchStyleOverride',
         SUCCESS : 'success',
         DBL_CLICK_DELAY: 300,
-        ERROR : 'error'
+        ERROR : 'error',
+        IS_PICK_AND_EDIT : '_isPickAndEdit'
     },
 
     Styles : {
--- a/modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -539,6 +539,17 @@
 <!--8747F91C31704FD0A9EC0C35237158BE-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--8747F91C31704FD0A9EC0C35237158BE--></AD_TEXTINTERFACES>
 
+<!--893CD872390148E99FCCAC1714D937A5--><AD_TEXTINTERFACES>
+<!--893CD872390148E99FCCAC1714D937A5-->  <AD_TEXTINTERFACES_ID><![CDATA[893CD872390148E99FCCAC1714D937A5]]></AD_TEXTINTERFACES_ID>
+<!--893CD872390148E99FCCAC1714D937A5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--893CD872390148E99FCCAC1714D937A5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--893CD872390148E99FCCAC1714D937A5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--893CD872390148E99FCCAC1714D937A5-->  <TEXT><![CDATA[Include payments with Base Amount 0]]></TEXT>
+<!--893CD872390148E99FCCAC1714D937A5-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--893CD872390148E99FCCAC1714D937A5-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--893CD872390148E99FCCAC1714D937A5-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--893CD872390148E99FCCAC1714D937A5--></AD_TEXTINTERFACES>
+
 <!--8A613E8D2A304FEF9545C2852FC06EF0--><AD_TEXTINTERFACES>
 <!--8A613E8D2A304FEF9545C2852FC06EF0-->  <AD_TEXTINTERFACES_ID><![CDATA[8A613E8D2A304FEF9545C2852FC06EF0]]></AD_TEXTINTERFACES_ID>
 <!--8A613E8D2A304FEF9545C2852FC06EF0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html	Tue Feb 09 09:45:56 2016 +0100
@@ -997,8 +997,12 @@
                     </select>
                   </td>
                   <td class="ContentCell"></td>
-                  <td class="ContentCell"></td>
-                  <td class="ContentCell"></td>
+                  <td class="TitleCell"><span class="LabelText">Include payments with Base Amount 0</span></td>
+                  <td class="Radio_Check_ContentCell">
+                    <span class="Checkbox_container_NOT_Focused">
+                      <input type="checkbox" name="inpBAZero" id="paramBAZero" value="Y"></input>
+                    </span>
+                  </td>
                 </tr>
                 
                 <tr>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.java	Tue Feb 09 09:45:56 2016 +0100
@@ -124,6 +124,7 @@
       String strPaymType = vars.getGlobalVariable("inpPaymType", "PaymentReport|PaymentType",
           "FINPR_RecPay");
       String strOverdue = vars.getGlobalVariable("inpOverdue", "PaymentReport|Overdue", "");
+      String strBAZero = vars.getGlobalVariable("inpBAZero", "PaymentReport|BAZero", "Y");
       String strGroupCrit = vars.getGlobalVariable("inpGroupCrit", "PaymentReport|GroupCrit", "");
       String strOrdCrit = vars.getInGlobalVariable("inpShown", "PaymentReport|OrdCrit", "",
           new ValueListFilter("Date", "APRM_FATS_BPARTNER", "Project", "INS_CURRENCY",
@@ -134,8 +135,8 @@
           strExpectedDateFrom, strExpectedDateTo, strAmountFrom, strAmountTo, strDocumentDateFrom,
           strDocumentDateTo, strcBPartnerIdIN, strcBPGroupIdIN, strcNoBusinessPartner,
           strcProjectIdIN, strfinPaymSt, strPaymentMethodId, strFinancialAccountId, strcCurrency,
-          strConvertCurrency, strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
-          strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
+          strConvertCurrency, strConversionDate, strPaymType, strOverdue, strBAZero, strGroupCrit,
+          strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
       // DIRECT is used when coming from Aging Balance Report
     } else if (vars.commandIn("FIND", "DIRECT")) {
       String strOrg = vars.getRequestGlobalVariable("inpOrg", "PaymentReport|Organization");
@@ -201,6 +202,7 @@
       String strPaymType = vars
           .getRequestGlobalVariable("inpPaymType", "PaymentReport|PaymentType");
       String strOverdue = vars.getRequestGlobalVariable("inpOverdue", "PaymentReport|Overdue");
+      String strBAZero = vars.getRequestGlobalVariable("inpBAZero", "PaymentReport|BAZero");
       String strGroupCrit = vars
           .getRequestGlobalVariable("inpGroupCrit", "PaymentReport|GroupCrit");
       String strOrdCrit = vars.getRequestInGlobalVariable("inpShown", "PaymentReport|OrdCrit",
@@ -213,8 +215,8 @@
           strExpectedDateFrom, strExpectedDateTo, strAmountFrom, strAmountTo, strDocumentDateFrom,
           strDocumentDateTo, strcBPartnerIdIN, strcBPGroupIdIN, strcNoBusinessPartner,
           strcProjectIdIN, strfinPaymSt, strPaymentMethodId, strFinancialAccountId, strcCurrency,
-          strConvertCurrency, strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
-          strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
+          strConvertCurrency, strConversionDate, strPaymType, strOverdue, strBAZero, strGroupCrit,
+          strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
     } else if (vars.commandIn("PDF", "XLS")) {
       String strOrg = vars.getRequestGlobalVariable("inpOrg", "PaymentReport|Organization");
       String strInclSubOrg = vars.getRequestGlobalVariable("inpInclSubOrg",
@@ -263,6 +265,7 @@
       String strPaymType = vars
           .getRequestGlobalVariable("inpPaymType", "PaymentReport|PaymentType");
       String strOverdue = vars.getRequestGlobalVariable("inpOverdue", "PaymentReport|Overdue");
+      String strBAZero = vars.getRequestGlobalVariable("inpBAZero", "PaymentReport|BAZero");
       String strGroupCrit = vars
           .getRequestGlobalVariable("inpGroupCrit", "PaymentReport|GroupCrit");
       String strOrdCrit = vars.getRequestInGlobalVariable("inpShown", "PaymentReport|OrdCrit",
@@ -281,8 +284,8 @@
           strExpectedDateFrom, strExpectedDateTo, strAmountFrom, strAmountTo, strDocumentDateFrom,
           strDocumentDateTo, strcBPartnerIdIN, strcBPGroupIdIN, strcNoBusinessPartner,
           strcProjectIdIN, strfinPaymSt, strPaymentMethodId, strFinancialAccountId, strcCurrency,
-          strConvertCurrency, strConversionDate, strPaymType, strOverdue, strOutput, strGroupCrit,
-          strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
+          strConvertCurrency, strConversionDate, strPaymType, strOverdue, strBAZero, strOutput,
+          strGroupCrit, strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
 
     } else if (vars.commandIn("LINK")) {
       String strTableId = vars.getRequiredStringParameter("inpAdTableId", IsIDFilter.instance);
@@ -312,9 +315,9 @@
       String strcBPartnerIdIN, String strcBPGroupIdIN, String strcNoBusinessPartner,
       String strcProjectIdIN, String strfinPaymSt, String strPaymentMethodId,
       String strFinancialAccountId, String strcCurrency, String strConvertCurrency,
-      String strConversionDate, String strPaymType, String strOverdue, String strGroupCrit,
-      String strOrdCrit, String strInclPaymentUsingCredit, String strPaymentDateFrom,
-      String strPaymentDateTo) throws IOException, ServletException {
+      String strConversionDate, String strPaymType, String strOverdue, String strBAZero,
+      String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit,
+      String strPaymentDateFrom, String strPaymentDateTo) throws IOException, ServletException {
     if (log4j.isDebugEnabled())
       log4j.debug("Output: dataSheet");
     XmlDocument xmlDocument = null;
@@ -330,7 +333,7 @@
             strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
             strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
             strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
-            strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
+            strConversionDate, strPaymType, strOverdue, strBAZero, strGroupCrit, strOrdCrit,
             strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo, strExpectedDateFrom,
             strExpectedDateTo, "HTML");
       } catch (OBException e) {
@@ -632,7 +635,8 @@
 
     xmlDocument.setData("reportPaymType", "liststructure", objectListData);
 
-    xmlDocument.setParameter("paramOver", !strOverdue.equals("Y") ? "0" : "1");
+    xmlDocument.setParameter("paramOver", strOverdue);
+    xmlDocument.setParameter("paramZero", strBAZero);
 
     xmlDocument.setParameter("groupCrit", strGroupCrit);
 
@@ -752,8 +756,9 @@
       String strcNoBusinessPartner, String strcProjectIdIN, String strfinPaymSt,
       String strPaymentMethodId, String strFinancialAccountId, String strcCurrency,
       String strConvertCurrency, String strConversionDate, String strPaymType, String strOverdue,
-      String strOutput, String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit,
-      String strPaymentDateFrom, String strPaymentDateTo) throws IOException, ServletException {
+      String strBAZero, String strOutput, String strGroupCrit, String strOrdCrit,
+      String strInclPaymentUsingCredit, String strPaymentDateFrom, String strPaymentDateTo)
+      throws IOException, ServletException {
 
     response.setContentType("text/html; charset=UTF-8");
 
@@ -764,7 +769,7 @@
           strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
           strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
           strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
-          strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
+          strConversionDate, strPaymType, strOverdue, strBAZero, strGroupCrit, strOrdCrit,
           strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo, strExpectedDateFrom,
           strExpectedDateTo, strOutput);
     } catch (OBException e) {
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -115,6 +115,8 @@
   </SUBREPORT>
   <PARAMETER id="parameterOver" name="all" default="1"/>
   <PARAMETER id="paramOverdue" name="paramOver" boolean="checked" withId="parameterOver" default="0"/>
+  <PARAMETER id="parameterBAZero" name="all" default="Y"/>
+  <PARAMETER id="paramBAZero" name="paramZero" boolean="checked" withId="parameterBAZero" default="Y"/>
   <PARAMETER id="paramGroupCrit" name="groupCrit" attribute="value"/>
   <SUBREPORT id="reportGroupCrit" name="reportGroupCrit" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramGroupCrit"/>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Tue Feb 09 09:45:56 2016 +0100
@@ -196,10 +196,12 @@
         strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
         strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
         strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
-        strOverdue, strGroupCrit, strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom,
+        strOverdue, "Y", strGroupCrit, strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom,
         strPaymentDateTo, strExpectedDateFrom, strExpectedDateTo, "dummy");
   }
 
+  @Deprecated
+  // Deprecated when adding filter for payments with amount 0
   FieldProvider[] getPaymentReport(VariablesSecureApp vars, String strOrg, String strInclSubOrg,
       String strDueDateFrom, String strDueDateTo, String strAmountFrom, String strAmountTo,
       String strDocumentDateFrom, String strDocumentDateTo, String strcBPartnerIdIN,
@@ -209,6 +211,23 @@
       String strOverdue, String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit,
       String strPaymentDateFrom, String strPaymentDateTo, String strExpectedDateFrom,
       String strExpectedDateTo, String strOutput) throws OBException {
+    return getPaymentReport(vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
+        strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
+        strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
+        strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
+        strOverdue, "Y", strGroupCrit, strOrdCrit, strInclPaymentUsingCredit, strPaymentDateFrom,
+        strPaymentDateTo, strExpectedDateFrom, strExpectedDateTo, strOutput);    
+  }
+
+  FieldProvider[] getPaymentReport(VariablesSecureApp vars, String strOrg, String strInclSubOrg,
+      String strDueDateFrom, String strDueDateTo, String strAmountFrom, String strAmountTo,
+      String strDocumentDateFrom, String strDocumentDateTo, String strcBPartnerIdIN,
+      String strcBPGroupIdIN, String strcNoBusinessPartner, String strcProjectIdIN,
+      String strfinPaymSt, String strPaymentMethodId, String strFinancialAccountId,
+      String strcCurrency, String strConvertCurrency, String strConversionDate, String strPaymType,
+      String strOverdue, String strBAZero, String strGroupCrit, String strOrdCrit,
+      String strInclPaymentUsingCredit, String strPaymentDateFrom, String strPaymentDateTo,
+      String strExpectedDateFrom, String strExpectedDateTo, String strOutput) throws OBException {
 
     StringBuilder hsqlScript = new StringBuilder();
     final java.util.List<Object> parameters = new ArrayList<Object>();
@@ -515,6 +534,12 @@
         parameters.add(DateUtils.truncate(new Date(), Calendar.DATE));
       }
 
+      if (!"Y".equals(strBAZero)) {
+        hsqlScript.append(" and not (pay.");
+        hsqlScript.append(FIN_Payment.PROPERTY_AMOUNT);
+        hsqlScript.append(" = 0 )");
+      }
+
       if ("HTML".equals(strOutput)) {
         int maxRecords = 1000;
         final Session sessionCount = OBDal.getInstance().getSession();
--- a/modules/org.openbravo.service.datasource/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.datasource/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -14,4 +14,18 @@
 <!--15E4FE4F91BF4776AA326FA798CC9F53-->  <IDFKFILTERING><![CDATA[Y]]></IDFKFILTERING>
 <!--15E4FE4F91BF4776AA326FA798CC9F53--></OBSERDS_DATASOURCE>
 
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF--><OBSERDS_DATASOURCE>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <OBSERDS_DATASOURCE_ID><![CDATA[D2F94DC86DEC48D69E4BFCE59DC670CF]]></OBSERDS_DATASOURCE_ID>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <AD_MODULE_ID><![CDATA[A44B9BA75C354D8FB2E3F7D6EB6BFDC4]]></AD_MODULE_ID>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <NAME><![CDATA[Tree Datasource for Account Tree]]></NAME>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <DESCRIPTION><![CDATA[Tree Datasource for Account Tree]]></DESCRIPTION>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <CLASSNAME><![CDATA[org.openbravo.service.datasource.AccountTreeDatasourceService]]></CLASSNAME>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <OBCLKER_TEMPLATE_ID><![CDATA[2BAD445C2A0343C58E455F9BD379C690]]></OBCLKER_TEMPLATE_ID>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <USEASTABLEDATAORIGIN><![CDATA[N]]></USEASTABLEDATAORIGIN>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF-->  <IDFKFILTERING><![CDATA[Y]]></IDFKFILTERING>
+<!--D2F94DC86DEC48D69E4BFCE59DC670CF--></OBSERDS_DATASOURCE>
+
 </data>
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ADTreeDatasourceService.java	Tue Feb 09 09:45:56 2016 +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) 2013-2015 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -144,7 +144,7 @@
    *          table whose ADTree TableTree will be returned
    * @return the ADTree TableTree associated with the given table
    */
-  private TableTree getTableTree(Table table) {
+  protected TableTree getTableTree(Table table) {
     TableTree tableTree = null;
     OBCriteria<TableTree> criteria = OBDal.getInstance().createCriteria(TableTree.class);
     criteria.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table));
@@ -172,7 +172,11 @@
   }
 
   /**
-   * 
+   * @param parameters
+   *          a map with the parameters of the request
+   * @param datasourceParameters
+   *          specific datasource parameters obtained using method
+   *          {@link #getDatasourceSpecificParams(Map)}
    * @param parentId
    *          id of the node whose children are to be retrieved
    * @param hqlWhereClause
@@ -503,7 +507,7 @@
   }
 
   /**
-   * Returns a Tree given the referencedTableId and the parentRecordId
+   * Returns a Tree given the referencedTableId
    */
   private Tree getTree(String referencedTableId) {
     Table referencedTable = OBDal.getInstance().get(Table.class, referencedTableId);
@@ -589,7 +593,8 @@
       }
     }
 
-    Tree tree = this.getTree(tableId);
+    Map<String, Object> datasourceParameters = this.getDatasourceSpecificParams(parameters);
+    Tree tree = (Tree) datasourceParameters.get("tree");
     boolean isOrdered = this.isOrdered(tree);
     Long seqNo = null;
     if (isOrdered) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/AccountTreeDatasourceService.java	Tue Feb 09 09:45:56 2016 +0100
@@ -0,0 +1,78 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2016 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.service.datasource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.datamodel.Table;
+import org.openbravo.model.ad.utility.TableTree;
+import org.openbravo.model.ad.utility.Tree;
+import org.openbravo.model.financialmgmt.accounting.coa.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tree Datasource for Account Tree
+ * 
+ */
+public class AccountTreeDatasourceService extends ADTreeDatasourceService {
+  private static final Logger logger = LoggerFactory.getLogger(AccountTreeDatasourceService.class);
+  private static final String DATASOURCE_ID = "D2F94DC86DEC48D69E4BFCE59DC670CF";
+  private static final String C_ELEMENTVALUE_TABLE_ID = "188";
+  private static final String FINANCIALMGMTELEMENT_ID = "@FinancialMgmtElement.id@";
+  private static final String CUSTOM_STRUCTURE = "Custom";
+
+  @Override
+  protected Map<String, Object> getDatasourceSpecificParams(Map<String, String> parameters) {
+    Map<String, Object> datasourceParams = new HashMap<String, Object>();
+    String accountTreeId = parameters.get(FINANCIALMGMTELEMENT_ID);
+    if (accountTreeId == null) {
+      return datasourceParams;
+    }
+    Element element = OBDal.getInstance().get(Element.class, accountTreeId);
+    Tree tree = element.getTree();
+    if (tree.getTable() == null) {
+      // In case the table is not defined, the C_ElementValue table is assigned to the account tree
+      // This prevents a NullPointerException when fetching the account tree nodes
+      Table cElementValueTable = OBDal.getInstance().get(Table.class, C_ELEMENTVALUE_TABLE_ID);
+      tree.setTable(cElementValueTable);
+    }
+    datasourceParams.put("tree", tree);
+    logger.debug("Retrieved tree for Account Element with id = {}", accountTreeId);
+    return datasourceParams;
+  }
+
+  @Override
+  protected TableTree getTableTree(Table table) {
+    TableTree tableTree = null;
+    DataSource accountTreeDatasource = OBDal.getInstance().get(DataSource.class, DATASOURCE_ID);
+    OBCriteria<TableTree> criteria = OBDal.getInstance().createCriteria(TableTree.class);
+    criteria.add(Restrictions.eq(TableTree.PROPERTY_TABLE, table));
+    criteria.add(Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, CUSTOM_STRUCTURE));
+    criteria.add(Restrictions.eq(TableTree.PROPERTY_DATASOURCE, accountTreeDatasource));
+    criteria.setMaxResults(1);
+    tableTree = (TableTree) criteria.uniqueResult();
+    return tableTree;
+  }
+}
\ No newline at end of file
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java	Tue Feb 09 09:45:56 2016 +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) 2013-2015 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -439,6 +439,7 @@
   /**
    * Updates the parent of a given node a returns its definition in a JSONObject
    */
+  @Override
   protected JSONObject moveNode(Map<String, String> parameters, String nodeId, String newParentId,
       String prevNodeId, String nextNodeId) throws Exception {
 
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java	Tue Feb 09 09:45:56 2016 +0100
@@ -11,19 +11,19 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.service.datasource;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -35,6 +35,8 @@
 import org.openbravo.service.json.DefaultJsonDataService.QueryResultWriter;
 import org.openbravo.service.json.JsonConstants;
 import org.openbravo.service.json.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The SimpleDataSourceService provides a simple way of returning data in the correct format for a
@@ -43,7 +45,11 @@
  * @author mtaal
  */
 public abstract class ReadOnlyDataSourceService extends DefaultDataSourceService {
-  private static final Logger log = Logger.getLogger(ReadOnlyDataSourceService.class);
+  private static final Logger log = LoggerFactory.getLogger(ReadOnlyDataSourceService.class);
+  private static final int DATA_PAGE_SIZE = 100;
+  private static final int MAX_PAGE_SIZE_INCREASE = 3;
+  private static final String NEW_END_ROW = "_newEndRow";
+  private static final String IS_PICK_AND_EDIT = "_isPickAndEdit";
 
   /*
    * (non-Javadoc)
@@ -55,6 +61,7 @@
     final String startRowStr = parameters.get(JsonConstants.STARTROW_PARAMETER);
     final String endRowStr = parameters.get(JsonConstants.ENDROW_PARAMETER);
     int startRow = 0;
+    int newEndRow = 0;
     boolean doCount = false;
     if (startRowStr != null) {
       startRow = Integer.parseInt(startRowStr);
@@ -66,7 +73,9 @@
     boolean preventCountOperation = "true".equals(parameters.get(JsonConstants.NOCOUNT_PARAMETER));
 
     List<JSONObject> jsonObjects = fetchJSONObject(parameters);
-
+    if (parameters.get(NEW_END_ROW) != null) {
+      newEndRow = Integer.parseInt(parameters.get(NEW_END_ROW));
+    }
     // now jsonfy the data
     try {
       final JSONObject jsonResult = new JSONObject();
@@ -76,7 +85,7 @@
       if (doCount && !preventCountOperation) {
         count = getCount(parameters);
         if (count == -1) {
-          int endRow = Integer.parseInt(endRowStr);
+          int endRow = newEndRow == 0 ? Integer.parseInt(endRowStr) : newEndRow;
           count = (endRow + 2);
           if ((endRow - startRow) > jsonObjects.size()) {
             count = startRow + jsonObjects.size();
@@ -85,7 +94,7 @@
       } else {
         count = jsonObjects.size() + startRow;
         if (endRowStr != null) {
-          int endRow = Integer.parseInt(endRowStr);
+          int endRow = newEndRow == 0 ? Integer.parseInt(endRowStr) : newEndRow;
           // computedMaxResults is one too much, if we got one to much then correct
           // the result and up the count so that the grid knows that there are more
           int computedMaxResults = endRow - startRow + 1;
@@ -132,7 +141,15 @@
     if (tableId != null) {
       entity = ModelProvider.getInstance().getEntityByTableId(tableId);
     }
-    final List<Map<String, Object>> data = getData(parameters, startRow, endRow);
+    final String isPickAndEditParam = parameters.get(IS_PICK_AND_EDIT);
+    final boolean isPickAndEdit = isPickAndEditParam != null ? Boolean.valueOf(isPickAndEditParam)
+        : Boolean.FALSE;
+    final List<Map<String, Object>> data;
+    if (startRow == 0 && endRow != -1 && isPickAndEdit) {
+      data = getSelectedData(parameters, startRow, endRow);
+    } else {
+      data = getData(parameters, startRow, endRow);
+    }
     final DataToJsonConverter toJsonConverter = OBProvider.getInstance().get(
         DataToJsonConverter.class);
     toJsonConverter.setAdditionalProperties(JsonUtils.getAdditionalProperties(parameters));
@@ -140,6 +157,73 @@
     return toJsonConverter.convertToJsonObjects(data);
   }
 
+  private List<Map<String, Object>> getSelectedData(Map<String, String> parameters, int startRow,
+      int endRow) {
+    List<Map<String, Object>> data;
+    int pageSizeIncreaseCount = 0;
+    int selectedRecords = getNumberOfSelectedRecords(parameters);
+    if (selectedRecords > DATA_PAGE_SIZE) {
+      data = getData(parameters, startRow, selectedRecords);
+      parameters.put(NEW_END_ROW, Integer.toString(selectedRecords));
+    } else {
+      data = getData(parameters, startRow, endRow);
+      while (isLastRecordSelected(data) && pageSizeIncreaseCount < MAX_PAGE_SIZE_INCREASE) {
+        pageSizeIncreaseCount++;
+        log.debug(
+            "The amount of selected records is higher than the page size, increasing page size x{}",
+            pageSizeIncreaseCount + 1);
+        data = getData(parameters, startRow, endRow * (pageSizeIncreaseCount + 1));
+      }
+      if (pageSizeIncreaseCount >= 1) {
+        parameters.put(NEW_END_ROW, Integer.toString(endRow * (pageSizeIncreaseCount + 1)));
+        if (pageSizeIncreaseCount == MAX_PAGE_SIZE_INCREASE) {
+          log.warn("The amount of selected records is higher than the maximum page size allowed.");
+        }
+      }
+    }
+    return data;
+  }
+
+  private int getNumberOfSelectedRecords(Map<String, String> parameters) {
+    List<String> selectedRecords = new ArrayList<String>();
+    boolean hasCriteria = parameters.containsKey("criteria");
+    if (hasCriteria) {
+      try {
+        selectedRecords = getSelectedRecordsFromCriteria(JsonUtils.buildCriteria(parameters));
+      } catch (JSONException jsonex) {
+        log.error("Error retrieving number of selected records", jsonex);
+      }
+    }
+    return selectedRecords.size();
+  }
+
+  private List<String> getSelectedRecordsFromCriteria(JSONObject buildCriteria)
+      throws JSONException {
+    List<String> selectedRecords = new ArrayList<String>();
+    JSONArray criteriaArray = buildCriteria.getJSONArray("criteria");
+    for (int i = 0; i < criteriaArray.length(); i++) {
+      JSONObject criteria = criteriaArray.getJSONObject(i);
+      if (criteria.has("fieldName") && criteria.getString("fieldName").equals("id")
+          && criteria.has("value")) {
+        String value = criteria.getString("value");
+        for (String recordId : value.split(",")) {
+          selectedRecords.add(recordId.trim());
+        }
+      }
+    }
+    return selectedRecords;
+  }
+
+  private boolean isLastRecordSelected(List<Map<String, Object>> data) {
+    if (data.size() == 0) {
+      return false;
+    }
+    Map<String, Object> lastRecord = data.get(data.size() - 1);
+    Object obSelected = lastRecord.get("obSelected");
+    Boolean isLastRecordSelected = obSelected == null ? Boolean.FALSE : (Boolean) obSelected;
+    return isLastRecordSelected.booleanValue();
+  }
+
   /**
    * Returns the count of objects based on the passed parameters.
    * 
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/TreeDatasourceService.java	Tue Feb 09 09:45:56 2016 +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) 2013-2015 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -760,7 +760,12 @@
 
   /**
    * @param parameters
+   *          a map with the parameters of the request
+   * @param datasourceParameters
+   *          specific datasource parameters obtained using method
+   *          {@link #getDatasourceSpecificParams(Map)}
    * @param nodeId
+   *          id of the tree node
    * @return returns a json object with the definition of a node give its record id
    */
   protected abstract JSONObject getJSONObjectByRecordId(Map<String, String> parameters,
@@ -768,7 +773,12 @@
 
   /**
    * @param parameters
+   *          a map with the parameters of the request
+   * @param datasourceParameters
+   *          specific datasource parameters obtained using method
+   *          {@link #getDatasourceSpecificParams(Map)}
    * @param nodeId
+   *          id of the tree node
    * @return returns a json object with the definition of a node give its node id
    */
   protected abstract JSONObject getJSONObjectByNodeId(Map<String, String> parameters,
@@ -777,6 +787,9 @@
   /**
    * 
    * @param parameters
+   *          a map with the parameters of the request
+   * @param datasourceParameters
+   *          specific datasource parameters
    * @param parentId
    *          id of the node whose children are to be retrieved
    * @param hqlWhereClause
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Tue Feb 09 09:45:56 2016 +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) 2009-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -42,6 +42,7 @@
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.util.Check;
 import org.openbravo.base.weld.WeldUtils;
+import org.openbravo.client.application.CachedPreference;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
@@ -74,7 +75,7 @@
   private static final String ADD_FLAG = "_doingAdd";
 
   @Inject
-  private UnpagedRequestCachedPreference unpagedRequestPreference;
+  private CachedPreference cachedPreference;
 
   private static DefaultJsonDataService instance = WeldUtils
       .getInstanceFromStaticBeanManager(DefaultJsonDataService.class);
@@ -473,7 +474,8 @@
 
         // for standard tab and selector datasources pagination is mandatory
         throw new OBException(OBMessageUtils.messageBD("OBJSON_NoPagedFetch"));
-      } else if (!"Y".equals(unpagedRequestPreference.getPreferenceValue()) && !isWsCall) {
+      } else if (!"Y".equals(cachedPreference
+          .getPreferenceValue(CachedPreference.ALLOW_UNPAGED_DS_MANUAL_REQUEST)) && !isWsCall) {
         throw new OBException(OBMessageUtils.messageBD("OBJSON_NoPagedFetchManual"));
       }
     }
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java	Tue Feb 09 09:45:56 2016 +0100
@@ -43,7 +43,6 @@
 import org.openbravo.base.model.Property;
 import org.openbravo.base.model.domaintype.AbsoluteDateTimeDomainType;
 import org.openbravo.base.model.domaintype.AbsoluteTimeDomainType;
-import org.openbravo.base.model.domaintype.BigDecimalDomainType;
 import org.openbravo.base.model.domaintype.BinaryDomainType;
 import org.openbravo.base.model.domaintype.EncryptedStringDomainType;
 import org.openbravo.base.model.domaintype.HashedStringDomainType;
@@ -194,7 +193,7 @@
         }
         return Boolean.parseBoolean((String) value);
       } else if (value instanceof Double) {
-        return new BigDecimal((Double) value);
+        return BigDecimal.valueOf((Double) value);
       } else if (value instanceof Integer && property.getPrimitiveObjectType() == Long.class) {
         return new Long((Integer) value);
       } else if (value instanceof Integer && property.getPrimitiveObjectType() == Float.class) {
@@ -435,19 +434,6 @@
           } else {
             // no _cleartext value found -> skipping field
           }
-        } else if (property.getDomainType() instanceof BigDecimalDomainType
-            && jsonObject.has(keyName + "_textualValue")) {
-          final String strValue = (String) jsonObject.get(keyName + "_textualValue");
-          try {
-            if (strValue == null || strValue.trim().length() == 0) {
-              setValue(obObject, property, null);
-            } else {
-              setValue(obObject, property, new BigDecimal(strValue));
-            }
-          } catch (Exception e) {
-            throw new OBException("Exception while trying to convert value:-->" + strValue + "<-- "
-                + e.getMessage(), e);
-          }
         } else {
           setValue(obObject, property, jsonObject.get(keyName));
         }
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/UnpagedRequestCachedPreference.java	Mon Feb 08 16:14:49 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-/*
- *************************************************************************
- * The contents of this file are subject to the Openbravo  Public  License
- * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
- * Version 1.1  with a permitted attribution clause; you may not  use this
- * file except in compliance with the License. You  may  obtain  a copy of
- * the License at http://www.openbravo.com/legal/license.html 
- * Software distributed under the License  is  distributed  on  an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific  language  governing  rights  and  limitations
- * under the License. 
- * The Original Code is Openbravo ERP. 
- * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2015 Openbravo SLU 
- * All Rights Reserved. 
- * Contributor(s):  ______________________________________.
- ************************************************************************
- */
-package org.openbravo.service.json;
-
-import javax.enterprise.context.ApplicationScoped;
-
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.businessUtility.Preferences;
-import org.openbravo.erpCommon.utility.PropertyException;
-import org.openbravo.model.ad.system.Client;
-import org.openbravo.model.common.enterprise.Organization;
-
-/**
- * This class is used as a singleton by the {@link DefaultJsonDataService} to keep the value of the
- * 'Allow Unpaged Datasource Manual Request' preference in cache during the application life cycle,
- * avoiding the time spent to compute the preference value.
- * 
- * This class it is also used by the
- * {@link org.openbravo.client.application.event.PreferenceEventHandler} class to detect changes in
- * the preference value, and it that case it invalidates the stored value. This way the next time it
- * is requested, the current value will be retrieved from database again.
- * 
- * This mechanism for automatic refresh the preference value, only works on environments with a
- * single JVM. In case of Tomcat clustering environments (multiple JVM) it will be necessary to
- * restart Tomcat to retrieve the new value of the preference in every JVM.
- * 
- * {@link "https://issues.openbravo.com/view.php?id=30204"}
- */
-@ApplicationScoped
-public class UnpagedRequestCachedPreference {
-  private final String property = "OBJSON_AllowUnpagedDatasourceManualRequest";
-  private String preferenceValue;
-
-  /**
-   * It returns a String with the preference value. In case this value is not stored in cache,i.e.,
-   * it is null then the value will be retrieved from database.
-   * 
-   * @return A String with the value of the OBJSON_AllowUnpagedDatasourceManualRequest preference
-   */
-  public String getPreferenceValue() {
-    if (preferenceValue == null) {
-      try {
-        OBContext.setAdminMode(false);
-        Client systemClient = OBDal.getInstance().get(Client.class, "0");
-        Organization asterisk = OBDal.getInstance().get(Organization.class, "0");
-        setPreferenceValue(Preferences.getPreferenceValue(property, true, systemClient, asterisk,
-            null, null, null));
-      } catch (PropertyException ignore) {
-        // Ignore the exception, caused because the preference was not found
-        setPreferenceValue("N");
-      } finally {
-        OBContext.restorePreviousMode();
-      }
-    }
-    return preferenceValue;
-  }
-
-  /**
-   * It returns a String with the property name of the preference.
-   * 
-   * @return A String with the OBJSON_AllowUnpagedDatasourceManualRequest property name
-   */
-  public String getProperty() {
-    return property;
-  }
-
-  /**
-   * Sets the cached value of the preference. This method is defined as synchronized in order to
-   * avoid concurrency problems.
-   * 
-   * @param preferenceValue
-   *          String with the value assigned to the preference
-   */
-  public synchronized void setPreferenceValue(String preferenceValue) {
-    this.preferenceValue = preferenceValue;
-  }
-}
--- a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js	Mon Feb 08 16:14:49 2016 +0100
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js	Tue Feb 09 09:45:56 2016 +0100
@@ -626,6 +626,12 @@
     // only do the identifier actions when clearing
     // in all other cases pickValue is called
     if (!newValue) {
+      if (this.getElementValue() === '' && this.pickList && this.pickList.getSelectedRecord() && this.pickList.getSelectedRecord().id) {
+        // handle special case: after selecting a value, a redraw is fired in the form.
+        // due to asynchrony problems, the redraw flow was able to access to _value before setting it with the current value.
+        // if we are in this case, then we do not need to continue setting the value because 'null' is not the value to be assigned.
+        return;
+      }
       this.setValueFromRecord(null);
     }
     if (OB.Utilities.isUUID(newValue)) {
--- a/referencedata/sampledata/QA_Testing/AD_SEQUENCE.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/referencedata/sampledata/QA_Testing/AD_SEQUENCE.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -2046,7 +2046,7 @@
   <ISAUTOSEQUENCE><![CDATA[Y]]></ISAUTOSEQUENCE>
   <INCREMENTNO><![CDATA[1]]></INCREMENTNO>
   <STARTNO><![CDATA[50000]]></STARTNO>
-  <CURRENTNEXT><![CDATA[50013]]></CURRENTNEXT>
+  <CURRENTNEXT><![CDATA[50016]]></CURRENTNEXT>
   <CURRENTNEXTSYS><![CDATA[5000]]></CURRENTNEXTSYS>
   <ISTABLEID><![CDATA[N]]></ISTABLEID>
   <STARTNEWYEAR><![CDATA[N]]></STARTNEWYEAR>
--- a/src-core/src/org/openbravo/base/ConfigParameters.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-core/src/org/openbravo/base/ConfigParameters.java	Tue Feb 09 09:45:56 2016 +0100
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2015 Openbravo S.L.U.
+ * Copyright (C) 2001-2016 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -24,8 +24,6 @@
 
 import javax.servlet.ServletContext;
 
-import org.apache.avalon.framework.logger.Log4JLogger;
-import org.apache.fop.messaging.MessageHandler;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -59,7 +57,6 @@
 
   private static final Logger log4j = Logger.getLogger(ConfigParameters.class);
 
-  private Log4JLogger fopLogger;
   public final String strServletSinIdentificar;
   private final String strServletGoBack;
   public final String strFTPDirectory;
@@ -87,7 +84,6 @@
 
     strBaseConfigPath = getResolvedParameter(context, "BaseConfigPath");
     configureLog4j(context, strBaseConfigPath);
-    configureFop();
 
     log4j.debug("context: " + strContext);
     log4j.debug("************************prefix: " + prefix);
@@ -168,12 +164,6 @@
     }
   }
 
-  private void configureFop() {
-    MessageHandler.setQuiet(true);
-    fopLogger = new Log4JLogger(log4j);
-    MessageHandler.setScreenLogger(fopLogger);
-  }
-
   private void configureLog4j(ServletContext context, String _strBaseConfigPath) {
     String file = getResolvedParameter(context, "log4j-init-file");
 
@@ -276,10 +266,6 @@
     return prefix + "/" + strBaseConfigPath + "/Format.xml";
   }
 
-  public Log4JLogger getFopLogger() {
-    return fopLogger;
-  }
-
   public boolean havePeriodicBackgroundTime() {
     return periodicBackgroundTime != null;
   }
--- a/src-core/src/org/openbravo/base/HttpBaseServlet.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-core/src/org/openbravo/base/HttpBaseServlet.java	Tue Feb 09 09:45:56 2016 +0100
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2015 Openbravo S.L.U.
+ * Copyright (C) 2001-2016 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -32,8 +32,21 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
 
-import org.apache.fop.apps.Driver;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FormattingResults;
+import org.apache.fop.events.Event;
+import org.apache.fop.events.EventFormatter;
+import org.apache.fop.events.EventListener;
+import org.apache.fop.events.model.EventSeverity;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 import org.openbravo.database.ConnectionProvider;
@@ -41,7 +54,6 @@
 import org.openbravo.exception.NoConnectionAvailableException;
 import org.openbravo.exception.PoolNotFoundException;
 import org.openbravo.xmlEngine.XmlEngine;
-import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
 import rmi.RenderFoI;
@@ -64,6 +76,8 @@
   private static String prefix = null;
   protected Logger log4j = Logger.getLogger(this.getClass());
 
+  private FopFactory fopFactory;
+
   protected ConfigParameters globalParameters;
 
   /**
@@ -543,6 +557,13 @@
 
   }
 
+  protected FopFactory getFopFactory() {
+    if (fopFactory == null) {
+      fopFactory = FopFactory.newInstance();
+    }
+    return fopFactory;
+  }
+
   /**
    * Renders the FO input source into a PDF file which is then written directly to OutputStream.
    * 
@@ -590,13 +611,11 @@
     try {
       if (log4j.isDebugEnabled())
         log4j.debug("Beginning of renderFO");
+      FopFactory fopFactoryInstance = getFopFactory();
       if (globalParameters.haveFopConfig()) {
+        // Take FOP Configuration using userconfig.xml file
         File fopFile = new File(globalParameters.getFopConfigPath());
-        if (fopFile.exists()) {
-          @SuppressWarnings("unused")
-          // external implementation
-          org.apache.fop.apps.Options options = new org.apache.fop.apps.Options(fopFile);
-        }
+        fopFactoryInstance.setUserConfig(fopFile);
       }
 
       final String foTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + strFo;
@@ -607,34 +626,33 @@
         if (log4j.isDebugEnabled())
           log4j.debug(strFo);
 
-        StringReader sr = new StringReader(foTemplate);
+        Source sr = new StreamSource(new StringReader(foTemplate));
 
         if (log4j.isDebugEnabled())
           log4j.debug(sr.toString());
 
-        InputSource inputFO = new InputSource(sr);
+        // Configure FOP for PDF output. Define a user agent with a listener used to log information
+        // along the rendering the process
+        FOUserAgent foUserAgent = fopFactoryInstance.newFOUserAgent();
+        foUserAgent.getEventBroadcaster().addEventListener(new FopEventListener());
+        Fop fop = fopFactoryInstance.newFop("application/pdf", foUserAgent, out);
 
-        if (log4j.isDebugEnabled())
-          log4j.debug("Beginning of driver");
+        // Setup JAXP using identity transformer
+        TransformerFactory factory = TransformerFactory.newInstance();
+        Transformer transformer = factory.newTransformer();
 
-        Driver driver = new Driver();
-        driver.setLogger(globalParameters.getFopLogger());
-        driver.setRenderer(Driver.RENDER_PDF);
-        driver.setInputSource(inputFO);
+        // Resulting SAX events (the generated FO) must be piped through to FOP
+        Result res = new SAXResult(fop.getDefaultHandler());
 
-        driver.setOutputStream(out);
+        // Start XSLT transformation and FOP processing
+        transformer.transform(sr, res);
 
-        if (log4j.isDebugEnabled())
-          log4j.debug("driver.run()");
+        if (log4j.isDebugEnabled()) {
+          FormattingResults foResults = fop.getResults();
+          log4j.debug("Generated " + foResults.getPageCount() + " pages in total.");
+          log4j.debug("End of renderFO");
+        }
 
-        driver.run();
-
-        if (log4j.isDebugEnabled())
-          log4j.debug("End of renderFO");
-
-        sr.close();
-        driver.reset();
-        driver = null;
       } else {
 
         RenderFoI render = (RenderFoI) Naming.lookup("rmi://"
@@ -713,4 +731,21 @@
     return "This servlet adds some functions (connection to the database, xmlEngine, logging) over HttpServlet";
   }
 
+  private class FopEventListener implements EventListener {
+
+    public void processEvent(Event event) {
+      String msg = EventFormatter.format(event);
+      EventSeverity severity = event.getSeverity();
+      if (severity == EventSeverity.INFO) {
+        log4j.info(msg);
+      } else if (severity == EventSeverity.WARN) {
+        log4j.warn(msg);
+      } else if (severity == EventSeverity.ERROR) {
+        log4j.error(msg);
+      } else if (severity == EventSeverity.FATAL) {
+        log4j.error(msg);
+      }
+    }
+  }
+
 }
Binary file src-db/database/lib/dbsourcemanager.jar has changed
--- a/src-db/database/model/functions/C_INVOICE_CREATE.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/model/functions/C_INVOICE_CREATE.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -25,7 +25,7 @@
   * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
   * All Rights Reserved.
   * Contributor(s): Openbravo SLU
-  * Contributions are Copyright (C) 2001-2015 Openbravo, S.L.U.
+  * Contributions are Copyright (C) 2001-2016 Openbravo, S.L.U.
   *
   * Specifically, this derivative work is based upon the following Compiere
   * file and version.
@@ -90,6 +90,8 @@
     v_defplantype_inv C_InvoiceLine.DefPlanType%TYPE;
     v_periodnumber_inv C_InvoiceLine.periodnumber%TYPE;
     v_period_inv C_InvoiceLine.c_period_id%TYPE;
+    v_InOutLine_ID C_InvoiceLine.M_InOutLine_ID%TYPE;
+
 
     Cur_Bpblocked RECORD;
     
@@ -582,6 +584,19 @@
                     Next_O_Line:=TRUE;
                   END IF;
                   IF(NOT Next_O_Line) THEN
+                    v_InOutLine_ID:=NULL;
+                    -- In case of POS Order get M_InOutLine_ID for OrderLine
+                    -- Making sure exactly one record is retreived using Max
+                    -- Qty compared to get full shipped line reference only
+                    -- There could a case where Order Line is split into two
+                    -- based on available stock in different storage bins
+                    -- in that no reference would be set in Invoice Line
+                    IF(v_DocSubTypeSO = 'WR') THEN
+                      SELECT MAX(sl.M_INOUTLINE_ID) INTO v_InOutLine_ID
+                        FROM M_INOUTLINE sl
+                        WHERE sl.C_ORDERLINE_ID = ptr_ol.C_OrderLine_ID
+                          AND ptr_ol.QtyOrdered = sl.MovementQty;
+                    END IF;
                     --
                     Ad_Sequence_Next('C_InvoiceLine', Cur_Order.C_Order_ID, v_NextNo) ;
                     v_LineNo:=v_LineNo + 10;
@@ -643,7 +658,7 @@
                       (
                         v_NextNo, ptr_ol.AD_Client_ID, ptr_ol.AD_Org_ID, 'Y',
                         now(), v_ADUserId, now(), v_ADUserId,
-                        p_Invoice_ID, ptr_ol.C_OrderLine_ID, NULL, v_LineNo,
+                        p_Invoice_ID, ptr_ol.C_OrderLine_ID, v_InOutLine_ID, v_LineNo,
                         ptr_ol.Description, ptr_ol.M_Product_ID, v_Qty, ptr_ol.PriceList,
                         ptr_ol.PriceActual, ptr_ol.PriceLimit, C_Currency_Round(v_Qty*ptr_ol.PriceActual, Cur_Order.C_Currency_ID, NULL), ptr_ol.C_Charge_ID,
                         ptr_ol.ChargeAmt, ptr_ol.C_UOM_ID,
--- a/src-db/database/model/functions/M_INVENTORY_LISTCREATE.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/model/functions/M_INVENTORY_LISTCREATE.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -19,7 +19,7 @@
   * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
   * All Rights Reserved.
   * Contributor(s): Openbravo SLU
-  * Contributions are Copyright (C) 2001-2015 Openbravo, S.L.U.
+  * Contributions are Copyright (C) 2001-2016 Openbravo, S.L.U.
   *
   * Specifically, this derivative work is based upon the following Compiere
   * file and version.
@@ -238,7 +238,7 @@
           AND l.M_Attributesetinstance_ID=s.M_Attributesetinstance_ID
         )
         AND (NOT (coalesce(p.attrsetvaluetype, '-') <> 'F'
-		 AND aset.isoneattrsetvalrequired = 'Y'
+		 AND COALESCE(aset.isoneattrsetvalrequired, '-') = 'Y'
 		 AND COALESCE(s.m_attributesetinstance_id, '0') = '0'
 		 AND QTYONHAND = 0
 		 AND COALESCE(QTYORDERONHAND,0) = 0
--- a/src-db/database/model/views/M_RM_SHIPMENT_PICK_EDIT.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/model/views/M_RM_SHIPMENT_PICK_EDIT.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -1,4 +1,4 @@
 <?xml version="1.0"?>
   <database name="VIEW M_RM_SHIPMENT_PICK_EDIT">
-    <view name="M_RM_SHIPMENT_PICK_EDIT"><![CDATA[SELECT COALESCE(sd.m_storage_detail_id, '') || ol.c_orderline_id AS m_rm_shipment_pick_edit_id, ol.ad_client_id, COALESCE(iol.ad_org_id, ol.ad_org_id) AS ad_org_id, ol.isactive, ol.createdby, ol.created, ol.updatedby, ol.updated, o.documentno AS returnorderno, ol.m_product_id, ol.m_attributesetinstance_id, ol.c_uom_id, (-1) * ol.qtyordered AS returned, (-1) * iol.movementqty AS movementqty, sd.m_locator_id, CASE WHEN sd.m_locator_id IS NULL THEN (-1) * ol.qtyordered ELSE COALESCE(sd.qtyonhand, 0) END AS availableqty, (-1) * (ol.qtyordered - to_number(COALESCE((SELECT to_char(sum(COALESCE(iol3.movementqty, 0))) AS sum FROM m_inoutline iol3 JOIN m_inout io3 ON iol3.m_inout_id = io3.m_inout_id AND io3.processed = 'Y' WHERE iol3.c_orderline_id = ol.c_orderline_id), '0'))) AS pendingqty, iol.m_inout_id, CASE WHEN iol.m_inout_id IS NOT NULL THEN 'Y' ELSE 'N' END AS ob_selected, ol.c_orderline_id, ol.line, iol.m_inoutline_id, p.isstocked FROM c_orderline ol JOIN c_order o ON o.c_order_id = ol.c_order_id AND o.processed = 'Y' AND o.issotrx = 'N' LEFT JOIN m_storage_detail sd ON sd.m_product_id = ol.m_product_id AND COALESCE(sd.m_attributesetinstance_id, '0') = COALESCE(ol.m_attributesetinstance_id, '0') AND sd.qtyonhand > 0 LEFT JOIN m_locator l ON sd.m_locator_id = l.m_locator_id JOIN m_product p ON p.m_product_id = ol.m_product_id JOIN c_doctype dt ON o.c_doctypetarget_id = dt.c_doctype_id AND dt.isreturn = 'Y' LEFT JOIN (SELECT iol2.m_inoutline_id, iol2.m_inout_id, iol2.movementqty, iol2.c_orderline_id, iol2.ad_org_id, iol2.m_locator_id FROM m_inoutline iol2 JOIN m_inout io2 ON iol2.m_inout_id = io2.m_inout_id AND io2.processed = 'N') iol ON iol.c_orderline_id = ol.c_orderline_id AND iol.m_locator_id = sd.m_locator_id WHERE o.docstatus = 'CO']]></view>
+    <view name="M_RM_SHIPMENT_PICK_EDIT"><![CDATA[SELECT COALESCE(sd.m_storage_detail_id, '') || ol.c_orderline_id AS m_rm_shipment_pick_edit_id, ol.ad_client_id, COALESCE(iol.ad_org_id, ol.ad_org_id) AS ad_org_id, ol.isactive, ol.createdby, ol.created, ol.updatedby, ol.updated, o.documentno AS returnorderno, ol.m_product_id, ol.m_attributesetinstance_id, ol.c_uom_id, (-1) * ol.qtyordered AS returned, (-1) * iol.movementqty AS movementqty, sd.m_locator_id, CASE WHEN sd.m_locator_id IS NULL THEN (-1) * ol.qtyordered ELSE COALESCE(sd.qtyonhand, 0) END AS availableqty, (-1) * (ol.qtyordered - to_number(COALESCE((SELECT to_char(sum(COALESCE(iol3.movementqty, 0))) AS sum FROM m_inoutline iol3 JOIN m_inout io3 ON iol3.m_inout_id = io3.m_inout_id AND io3.processed = 'Y' WHERE iol3.c_orderline_id = ol.c_orderline_id), '0'))) AS pendingqty, iol.m_inout_id, CASE WHEN iol.m_inout_id IS NOT NULL THEN 'Y' ELSE 'N' END AS ob_selected, ol.c_orderline_id, ol.line, iol.m_inoutline_id, p.isstocked, o.c_bpartner_id FROM c_orderline ol JOIN c_order o ON o.c_order_id = ol.c_order_id AND o.processed = 'Y' AND o.issotrx = 'N' LEFT JOIN m_storage_detail sd ON sd.m_product_id = ol.m_product_id AND COALESCE(sd.m_attributesetinstance_id, '0') = COALESCE(ol.m_attributesetinstance_id, '0') AND sd.qtyonhand > 0 LEFT JOIN m_locator l ON sd.m_locator_id = l.m_locator_id JOIN m_product p ON p.m_product_id = ol.m_product_id JOIN c_doctype dt ON o.c_doctypetarget_id = dt.c_doctype_id AND dt.isreturn = 'Y' LEFT JOIN (SELECT iol2.m_inoutline_id, iol2.m_inout_id, iol2.movementqty, iol2.c_orderline_id, iol2.ad_org_id, iol2.m_locator_id FROM m_inoutline iol2 JOIN m_inout io2 ON iol2.m_inout_id = io2.m_inout_id AND io2.processed = 'N') iol ON iol.c_orderline_id = ol.c_orderline_id AND iol.m_locator_id = sd.m_locator_id WHERE o.docstatus = 'CO']]></view>
   </database>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -251440,6 +251440,44 @@
 <!--3585B480A13011DD9CA97FE6868E2BF3-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
 <!--3585B480A13011DD9CA97FE6868E2BF3--></AD_COLUMN>
 
+<!--35913A1C7B8740AA98B72349580C0268--><AD_COLUMN>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_COLUMN_ID><![CDATA[35913A1C7B8740AA98B72349580C0268]]></AD_COLUMN_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--35913A1C7B8740AA98B72349580C0268-->  <NAME><![CDATA[Business Partner]]></NAME>
+<!--35913A1C7B8740AA98B72349580C0268-->  <DESCRIPTION><![CDATA[Anyone who takes part in daily business operations by acting as a customer, employee, etc.]]></DESCRIPTION>
+<!--35913A1C7B8740AA98B72349580C0268-->  <HELP><![CDATA[A Business Partner is anyone with whom you transact.  This can include a customer, vendor, employee or any combination of these.]]></HELP>
+<!--35913A1C7B8740AA98B72349580C0268-->  <COLUMNNAME><![CDATA[C_Bpartner_ID]]></COLUMNNAME>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_TABLE_ID><![CDATA[347B0AA5C3CD4D18910D2FE4990B790E]]></AD_TABLE_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_REFERENCE_ID><![CDATA[30]]></AD_REFERENCE_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_REFERENCE_VALUE_ID><![CDATA[800057]]></AD_REFERENCE_VALUE_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--35913A1C7B8740AA98B72349580C0268-->  <SEQNO><![CDATA[240]]></SEQNO>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_ELEMENT_ID><![CDATA[187]]></AD_ELEMENT_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--35913A1C7B8740AA98B72349580C0268-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--35913A1C7B8740AA98B72349580C0268-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--35913A1C7B8740AA98B72349580C0268-->  <POSITION><![CDATA[24]]></POSITION>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--35913A1C7B8740AA98B72349580C0268-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--35913A1C7B8740AA98B72349580C0268-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ALLOWSORTING><![CDATA[Y]]></ALLOWSORTING>
+<!--35913A1C7B8740AA98B72349580C0268-->  <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
+<!--35913A1C7B8740AA98B72349580C0268--></AD_COLUMN>
+
 <!--35AFD634B5AF4661937238C63AB1E683--><AD_COLUMN>
 <!--35AFD634B5AF4661937238C63AB1E683-->  <AD_COLUMN_ID><![CDATA[35AFD634B5AF4661937238C63AB1E683]]></AD_COLUMN_ID>
 <!--35AFD634B5AF4661937238C63AB1E683-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -341151,6 +341189,7 @@
 <!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <POSITION><![CDATA[23]]></POSITION>
 <!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--C0D9A7D1D5B043A4B8AE9F6AC683FD50-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -259677,6 +259677,34 @@
 <!--9C834BED1A174B57AEE41A6160110B7D-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--9C834BED1A174B57AEE41A6160110B7D--></AD_FIELD>
 
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--><AD_FIELD>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <AD_FIELD_ID><![CDATA[9C9343FFB9CF4050AB1EBB65CE87BBA6]]></AD_FIELD_ID>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <NAME><![CDATA[Table]]></NAME>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <DESCRIPTION><![CDATA[A dictionary table used for this tab that points to the database table.]]></DESCRIPTION>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <HELP><![CDATA[The Table indicates the table in which a field or fields reside.]]></HELP>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <AD_TAB_ID><![CDATA[243]]></AD_TAB_ID>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <AD_COLUMN_ID><![CDATA[2D852A64DD7D4758AAA80AFB90FB5A84]]></AD_COLUMN_ID>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <SEQNO><![CDATA[80]]></SEQNO>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--9C9343FFB9CF4050AB1EBB65CE87BBA6--></AD_FIELD>
+
 <!--9CA351D4BB3443C2A6E1B6F782DDAA63--><AD_FIELD>
 <!--9CA351D4BB3443C2A6E1B6F782DDAA63-->  <AD_FIELD_ID><![CDATA[9CA351D4BB3443C2A6E1B6F782DDAA63]]></AD_FIELD_ID>
 <!--9CA351D4BB3443C2A6E1B6F782DDAA63-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_TAB.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/sourcedata/AD_TAB.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -17355,9 +17355,9 @@
 <!--9195CC43B5A4419195030A4DB17D8737-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--9195CC43B5A4419195030A4DB17D8737-->  <UIPATTERN><![CDATA[STD]]></UIPATTERN>
 <!--9195CC43B5A4419195030A4DB17D8737-->  <HQLWHERECLAUSE><![CDATA[COALESCE(e.goodsShipment.id, @MaterialMgmtShipmentInOut.id@) = @MaterialMgmtShipmentInOut.id@
-AND @MaterialMgmtShipmentInOut.businessPartner@ = e.orderLine.salesOrder.businessPartner.id
+AND @MaterialMgmtShipmentInOut.businessPartner@ = e.businessPartner.id
 AND e.pending <> 0 AND (e.storageBin is null OR ad_org_isinnaturaltree(@MaterialMgmtShipmentInOut.organization@, (select organization.id from Locator a where a.id = e.storageBin.id), @MaterialMgmtShipmentInOut.client@) = 'Y')]]></HQLWHERECLAUSE>
-<!--9195CC43B5A4419195030A4DB17D8737-->  <HQLORDERBYCLAUSE><![CDATA[obSelected DESC, rMOrderNo, product]]></HQLORDERBYCLAUSE>
+<!--9195CC43B5A4419195030A4DB17D8737-->  <HQLORDERBYCLAUSE><![CDATA[obSelected DESC, rMOrderNo, lineNo]]></HQLORDERBYCLAUSE>
 <!--9195CC43B5A4419195030A4DB17D8737-->  <SHOWPARENTBUTTONS><![CDATA[Y]]></SHOWPARENTBUTTONS>
 <!--9195CC43B5A4419195030A4DB17D8737-->  <DISABLE_PARENT_KEY_PROPERTY><![CDATA[N]]></DISABLE_PARENT_KEY_PROPERTY>
 <!--9195CC43B5A4419195030A4DB17D8737-->  <ISREADONLYTREE><![CDATA[N]]></ISREADONLYTREE>
--- a/src-db/database/sourcedata/AD_TABLE_TREE.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/sourcedata/AD_TABLE_TREE.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -128,7 +128,8 @@
 <!--8E70E92119184AB69AE031A72BF6BF9E-->  <NAME><![CDATA[Element Value]]></NAME>
 <!--8E70E92119184AB69AE031A72BF6BF9E-->  <ISPARENTSELECTIONALLOWED><![CDATA[Y]]></ISPARENTSELECTIONALLOWED>
 <!--8E70E92119184AB69AE031A72BF6BF9E-->  <ISORDERED><![CDATA[Y]]></ISORDERED>
-<!--8E70E92119184AB69AE031A72BF6BF9E-->  <TREESTRUCTURE><![CDATA[ADTree]]></TREESTRUCTURE>
+<!--8E70E92119184AB69AE031A72BF6BF9E-->  <TREESTRUCTURE><![CDATA[Custom]]></TREESTRUCTURE>
+<!--8E70E92119184AB69AE031A72BF6BF9E-->  <OBSERDS_DATASOURCE_ID><![CDATA[D2F94DC86DEC48D69E4BFCE59DC670CF]]></OBSERDS_DATASOURCE_ID>
 <!--8E70E92119184AB69AE031A72BF6BF9E-->  <ISHANDLENODESMANUALLY><![CDATA[Y]]></ISHANDLENODESMANUALLY>
 <!--8E70E92119184AB69AE031A72BF6BF9E-->  <ISMAINTREE><![CDATA[Y]]></ISMAINTREE>
 <!--8E70E92119184AB69AE031A72BF6BF9E-->  <NODEDELETIONPOLICY><![CDATA[RCN]]></NODEDELETIONPOLICY>
--- a/src-db/database/sourcedata/OBUIAPP_PROCESS.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/sourcedata/OBUIAPP_PROCESS.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -457,7 +457,9 @@
 <!--B05273730AA14DAEA91EAC7A828C8026-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--B05273730AA14DAEA91EAC7A828C8026-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--B05273730AA14DAEA91EAC7A828C8026-->  <VALUE><![CDATA[PriceDifferenceByDateProcess]]></VALUE>
-<!--B05273730AA14DAEA91EAC7A828C8026-->  <NAME><![CDATA[Process Price Difference adjustment]]></NAME>
+<!--B05273730AA14DAEA91EAC7A828C8026-->  <NAME><![CDATA[Process Price Difference Adjustment]]></NAME>
+<!--B05273730AA14DAEA91EAC7A828C8026-->  <DESCRIPTION><![CDATA[This process allows to adjust the cost of a transaction, caused by a price difference between the order and the corresponding invoice.]]></DESCRIPTION>
+<!--B05273730AA14DAEA91EAC7A828C8026-->  <HELP><![CDATA[Price difference adjustments can be performed "automatically" by scheduling the "Price Correction Background Process" or manually for a given product or set of products by running this process.]]></HELP>
 <!--B05273730AA14DAEA91EAC7A828C8026-->  <ACCESSLEVEL><![CDATA[3]]></ACCESSLEVEL>
 <!--B05273730AA14DAEA91EAC7A828C8026-->  <CLASSNAME><![CDATA[org.openbravo.costing.PriceDifferenceByDateProcess]]></CLASSNAME>
 <!--B05273730AA14DAEA91EAC7A828C8026-->  <ISBACKGROUND><![CDATA[N]]></ISBACKGROUND>
--- a/src-db/database/sourcedata/OBUISEL_SELECTOR_FIELD.xml	Mon Feb 08 16:14:49 2016 +0100
+++ b/src-db/database/sourcedata/OBUISEL_SELECTOR_FIELD.xml	Tue Feb 09 09:45:56 2016 +0100
@@ -2037,6 +2037,27 @@
 <!--6AA3521F6AF347338CAD9B9DE8268DE2-->  <SHOWINPICKLIST><![CDATA[N]]></SHOWINPICKLIST>
 <!--6AA3521F6AF347338CAD9B9DE8268DE2--></OBUISEL_SELECTOR_FIELD>
 
+<!--6B6056EB2EEF445EBCAA81E82FF19D75--><OBUISEL_SELECTOR_FIELD>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <OBUISEL_SELECTOR_FIELD_ID><![CDATA[6B6056EB2EEF445EBCAA81E82FF19D75]]></OBUISEL_SELECTOR_FIELD_ID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <OBUISEL_SELECTOR_ID><![CDATA[A1024EFED9AF41F39C374ACD0EC1D733]]></OBUISEL_SELECTOR_ID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <AD_COLUMN_ID><![CDATA[7DC34559B3F1B45BE040007F0100784A]]></AD_COLUMN_ID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <NAME><![CDATA[Payment Method]]></NAME>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <DESCRIPTION><![CDATA[It is the method by which payment is expected to be made or received.]]></DESCRIPTION>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <PROPERTY><![CDATA[paymentMethod]]></PROPERTY>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <SORT><![CDATA[Y]]></SORT>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <FILTER><![CDATA[Y]]></FILTER>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <SEARCHINSUGGESTIONBOX><![CDATA[Y]]></SEARCHINSUGGESTIONBOX>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <SHOWINGRID><![CDATA[Y]]></SHOWINGRID>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <SORTNO><![CDATA[9]]></SORTNO>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <ISOUTFIELD><![CDATA[N]]></ISOUTFIELD>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75-->  <SHOWINPICKLIST><![CDATA[N]]></SHOWINPICKLIST>
+<!--6B6056EB2EEF445EBCAA81E82FF19D75--></OBUISEL_SELECTOR_FIELD>
+
 <!--6BA326C1B94B4D8189D860F01C6E00E8--><OBUISEL_SELECTOR_FIELD>
 <!--6BA326C1B94B4D8189D860F01C6E00E8-->  <OBUISEL_SELECTOR_FIELD_ID><![CDATA[6BA326C1B94B4D8189D860F01C6E00E8]]></OBUISEL_SELECTOR_FIELD_ID>
 <!--6BA326C1B94B4D8189D860F01C6E00E8-->  <OBUISEL_SELECTOR_ID><![CDATA[5D8307CE8322429DBED98ADC8E8361E6]]></OBUISEL_SELECTOR_ID>
--- a/src/org/openbravo/common/actionhandler/ManageReservationActionHandler.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/common/actionhandler/ManageReservationActionHandler.java	Tue Feb 09 09:45:56 2016 +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) 2013-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -75,11 +75,24 @@
         final String strOrderLineId = jsonRequest.getString("C_OrderLine_ID");
         final OrderLine sol = OBDal.getInstance().get(OrderLine.class, strOrderLineId);
         reservation = ReservationUtils.getReservationFromOrder(sol);
-
-        OBDal.getInstance().refresh(reservation);
         processReservation = reservation.getRESStatus().equals("DR");
       }
-
+      // Process reservation before managing stock reservations to avoid reserve all available stock
+      // Issue 28051: https://issues.openbravo.com/view.php?id=28051
+      if (processReservation) {
+        OBError result = ReservationUtils.processReserve(reservation, "PR");
+        if (result.getType().equals("Error")) {
+          JSONObject errorMessage = new JSONObject();
+          errorMessage.put("severity", result.getType().toLowerCase());
+          errorMessage.put("text", result.getMessage());
+          jsonRequest.put("message", errorMessage);
+        } else {
+          // Force status to completed in case it was kept as draft because no stock reservation was
+          // created when processing reservation
+          reservation.setRESStatus("CO");
+          reservation.setRESProcess("HO");
+        }
+      }
       if (reservation != null) {
         // FIXME: Replace with OBDao method when handler is merged with latest pi.
         // List<String> idList = OBDao.getIDListFromOBObject(reservation
@@ -89,15 +102,10 @@
           idList.add(resStock.getId());
         }
         manageReservedStockLines(jsonRequest, reservation, idList);
-
-        if (processReservation) {
-          OBError result = ReservationUtils.processReserve(reservation, "PR");
-          if (result.getType().equals("Error")) {
-            JSONObject errorMessage = new JSONObject();
-            errorMessage.put("severity", result.getType().toLowerCase());
-            errorMessage.put("text", result.getMessage());
-            jsonRequest.put("message", errorMessage);
-          }
+        // Force status to draft in case reservation has no lines
+        if (reservation.getMaterialMgmtReservationStockList().isEmpty()) {
+          reservation.setRESStatus("DR");
+          reservation.setRESProcess("PR");
         }
       }
 
--- a/src/org/openbravo/costing/CostingMigrationProcess.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/costing/CostingMigrationProcess.java	Tue Feb 09 09:45:56 2016 +0100
@@ -528,6 +528,7 @@
         trx.setTransactionCost(trxCost);
         trx.setCostCalculated(true);
         trx.setCostingStatus("CC");
+        trx.setProcessed(true);
         OBDal.getInstance().save(trx);
         Currency legalEntityCur = FinancialUtils.getLegalEntityCurrency(trx.getOrganization());
         BigDecimal cost = BigDecimal.ZERO;
@@ -734,6 +735,7 @@
         trx.setCurrency(cost.getCurrency());
         trx.setCostCalculated(true);
         trx.setCostingStatus("CC");
+        trx.setProcessed(true);
 
         if ((i % 100) == 0) {
           OBDal.getInstance().flush();
@@ -782,6 +784,7 @@
         trx.setCurrency((Currency) OBDal.getInstance().getProxy(Currency.ENTITY_NAME, curId));
         trx.setCostCalculated(true);
         trx.setCostingStatus("CC");
+        trx.setProcessed(true);
         OBDal.getInstance().save(trx);
 
         if ((i % 100) == 0) {
@@ -863,13 +866,12 @@
     insert.append(", t." + MaterialTransaction.PROPERTY_TRANSACTIONCOST);
     insert.append(", t." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE);
     insert.append(", t." + MaterialTransaction.PROPERTY_CURRENCY);
-    insert.append(", case when t." + MaterialTransaction.PROPERTY_GOODSSHIPMENTLINE
-        + " is null then t." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " else t."
-        + MaterialTransaction.PROPERTY_GOODSSHIPMENTLINE + "."
-        + ShipmentInOutLine.PROPERTY_SHIPMENTRECEIPT + "." + ShipmentInOut.PROPERTY_ACCOUNTINGDATE
-        + " end");
+    insert.append(", coalesce(io." + ShipmentInOut.PROPERTY_ACCOUNTINGDATE + ", t."
+        + MaterialTransaction.PROPERTY_MOVEMENTDATE + ")");
     insert.append(" from  " + TransactionCost.ENTITY_NAME + " as tc ");
     insert.append("   right join tc." + TransactionCost.PROPERTY_INVENTORYTRANSACTION + " as t");
+    insert.append("   left join t." + MaterialTransaction.PROPERTY_GOODSSHIPMENTLINE + " as iol");
+    insert.append("   left join iol." + ShipmentInOutLine.PROPERTY_SHIPMENTRECEIPT + " as io");
     insert.append(", " + User.ENTITY_NAME + " as u");
     insert.append("  where t." + MaterialTransaction.PROPERTY_TRANSACTIONCOST + " is not null");
     insert.append("    and tc.id is null");
--- a/src/org/openbravo/costing/CostingRuleProcess.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/costing/CostingRuleProcess.java	Tue Feb 09 09:45:56 2016 +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) 2012-2015 Openbravo SLU
+ * All portions are Copyright (C) 2012-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -534,6 +534,7 @@
         trx.setCostingStatus("CC");
         trx.setCurrency(cur);
         trx.setTransactionCost(trxCost);
+        trx.setProcessed(true);
         OBDal.getInstance().save(trx);
         icl = OBDal.getInstance().get(InventoryCountLine.class, icl.getId());
         InventoryCountLine initICL = getInitIcl(cri.getInitInventory(), icl);
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Tue Feb 09 09:45:56 2016 +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) 2010-2015 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,6 +29,7 @@
 
 import javax.servlet.ServletException;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
@@ -116,8 +117,8 @@
     FIN_Payment payment = transaction.getFinPayment();
     List<String> paymentDetails = FIN_Utility.getOrderedPaymentDetailList(payment.getId());
     FieldProviderFactory[] data = new FieldProviderFactory[paymentDetails.size()];
-    FIN_PaymentSchedule ps = null;
-    FIN_PaymentDetail pd = null;
+    String psId = null;
+    String pdId = null;
     OBContext.setAdminMode();
     try {
       for (int i = 0; i < data.length; i++) {
@@ -133,10 +134,10 @@
         }
 
         // If the Payment Detail has already been processed, skip it
-        if (paymentDetail.equals(pd)) {
+        if (StringUtils.equals(paymentDetail.getId(), pdId)) {
           continue;
         }
-        pd = paymentDetail;
+        pdId = paymentDetail.getId();
 
         data[i] = new FieldProviderFactory(null);
         FIN_PaymentSchedule psi = paymentDetail.getFINPaymentScheduleDetailList().get(0)
@@ -155,17 +156,18 @@
           paymentDetailPreviousId = paymentDetails.get(i - 1);
         }
         HashMap<String, BigDecimal> amountAndWriteOff = getPaymentDetailWriteOffAndAmount(
-            paymentDetail, paymentDetailNextId, paymentDetailPreviousId, ps, psi, pso, data[i]);
+            paymentDetail, paymentDetailNextId, paymentDetailPreviousId, psId != null ? OBDal
+                .getInstance().get(FIN_PaymentSchedule.class, psId) : null, psi, pso, data[i]);
         BigDecimal amount = amountAndWriteOff.get("amount");
         BigDecimal writeOff = amountAndWriteOff.get("writeoff");
         if (amount == null) {
           data[i] = null;
-          ps = psi;
+          psId = psi != null ? psi.getId() : null;
           continue;
         } else {
           FieldProviderFactory.setField(data[i], "Amount", amount.toString());
         }
-        ps = psi;
+        psId = psi != null ? psi.getId() : null;
 
         FieldProviderFactory.setField(data[i], "FIN_Finacc_Transaction_ID", transaction.getId());
         FieldProviderFactory.setField(data[i], "AD_Client_ID", paymentDetail.getClient().getId());
@@ -204,6 +206,8 @@
         FieldProviderFactory.setField(data[i], "adOrgId", paymentDetail.getOrganization().getId());
         FieldProviderFactory.setField(data[i], "description", transaction.getDescription());
         FieldProviderFactory.setField(data[i], "cCurrencyId", transaction.getCurrency().getId());
+        FieldProviderFactory.setField(data[i], "cInvoiceId", psi != null
+            && psi.getInvoice() != null ? psi.getInvoice().getId() : null);
         FieldProviderFactory.setField(data[i], "cProjectId", paymentDetail
             .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != null
             && paymentDetail.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule()
@@ -294,6 +298,9 @@
             paymentDetail.isPrepayment() ? (pso != null ? pso.getId() : "") : (psi != null ? psi
                 .getId() : ""));
 
+        if (i % 100 == 0) {
+          OBDal.getInstance().getSession().clear();
+        }
       }
     } finally {
       OBContext.restorePreviousMode();
@@ -368,14 +375,7 @@
         if (strPaymentId != null && !strPaymentId.equals("")) {
           docLine.setFinPaymentId(strPaymentId);
           // docLine.m_Record_Id2 = strPaymentId;
-          FIN_PaymentDetail detail = OBDal.getInstance().get(FIN_PaymentDetail.class,
-              paymentDetail_ID);
-          docLine
-              .setInvoice(detail.getFINPaymentScheduleDetailList() != null
-                  && detail.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != null ? detail
-                  .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule()
-                  .getInvoice()
-                  : null);
+          docLine.setInvoiceId(data[i].getField("cInvoiceId"));
           docLine.setDoubtFulDebtAmount(new BigDecimal(data[i].getField("DoubtFulDebtAmount")));
 
           docLine.setInvoiceTaxCashVAT_V(paymentDetail_ID);
@@ -631,6 +631,10 @@
             }
           }
         }
+
+        if (i % 100 == 0) {
+          OBDal.getInstance().getSession().clear();
+        }
       }
       // Pre-payment is consumed when Used Credit Amount not equals Zero. When consuming Credit no
       // credit is generated
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java	Tue Feb 09 09:45:56 2016 +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) 2010-2015 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,6 +27,7 @@
 
 import javax.servlet.ServletException;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
@@ -91,8 +92,8 @@
       return null;
 
     FieldProviderFactory[] data = new FieldProviderFactory[paymentDetails.size()];
-    FIN_PaymentSchedule ps = null;
-    FIN_PaymentDetail pd = null;
+    String psId = null;
+    String pdId = null;
     OBContext.setAdminMode();
     try {
       for (int i = 0; i < data.length; i++) {
@@ -106,10 +107,10 @@
         }
 
         // If the Payment Detail has already been processed, skip it
-        if (paymentDetail.equals(pd)) {
+        if (StringUtils.equals(paymentDetail.getId(), pdId)) {
           continue;
         }
-        pd = paymentDetail;
+        pdId = paymentDetail.getId();
 
         data[i] = new FieldProviderFactory(null);
         FIN_PaymentSchedule psi = paymentDetail.getFINPaymentScheduleDetailList().get(0)
@@ -128,17 +129,18 @@
           paymentDetailPreviousId = paymentDetails.get(i - 1);
         }
         HashMap<String, BigDecimal> amountAndWriteOff = getPaymentDetailWriteOffAndAmount(
-            paymentDetail, paymentDetailNextId, paymentDetailPreviousId, ps, psi, pso, data[i]);
+            paymentDetail, paymentDetailNextId, paymentDetailPreviousId, psId != null ? OBDal
+                .getInstance().get(FIN_PaymentSchedule.class, psId) : null, psi, pso, data[i]);
         BigDecimal amount = amountAndWriteOff.get("amount");
         BigDecimal writeOff = amountAndWriteOff.get("writeoff");
         if (amount == null) {
           data[i] = null;
-          ps = psi;
+          psId = psi != null ? psi.getId() : null;
           continue;
         } else {
           FieldProviderFactory.setField(data[i], "Amount", amount.toString());
         }
-        ps = psi;
+        psId = psi != null ? psi.getId() : null;
 
         FieldProviderFactory.setField(data[i], "AD_Client_ID", paymentDetail.getClient().getId());
         FieldProviderFactory
@@ -169,6 +171,8 @@
             : (isPaymentDatePriorToInvoiceDate ? "Y" : "N"));
         FieldProviderFactory.setField(data[i], "isPaymentDatePriorToInvoiceDate",
             isPaymentDatePriorToInvoiceDate && !paymentDetail.isPrepayment() ? "Y" : "N");
+        FieldProviderFactory.setField(data[i], "cInvoiceId", psi != null
+            && psi.getInvoice() != null ? psi.getInvoice().getId() : null);
         FieldProviderFactory.setField(data[i], "cProjectId", paymentDetail
             .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != null
             && paymentDetail.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule()
@@ -258,6 +262,9 @@
             paymentDetail.isPrepayment() ? (pso != null ? pso.getId() : "") : (psi != null ? psi
                 .getId() : ""));
 
+        if (i % 100 == 0) {
+          OBDal.getInstance().getSession().clear();
+        }
       }
     } finally {
       OBContext.restorePreviousMode();
@@ -276,7 +283,6 @@
       String Line_ID = data[i].getField("FIN_Payment_Detail_ID");
       OBContext.setAdminMode();
       try {
-        FIN_PaymentDetail detail = OBDal.getInstance().get(FIN_PaymentDetail.class, Line_ID);
         DocLine_FINPayment docLine = new DocLine_FINPayment(DocumentType, Record_ID, Line_ID);
         docLine.loadAttributes(data[i], this);
         docLine.setAmount(data[i].getField("Amount"));
@@ -286,11 +292,7 @@
         docLine.setC_GLItem_ID(data[i].getField("C_GLItem_ID"));
         docLine.setPrepaymentAgainstInvoice("Y".equals(data[i]
             .getField("isPaymentDatePriorToInvoiceDate")) ? true : false);
-        docLine
-            .setInvoice(detail.getFINPaymentScheduleDetailList() != null
-                && detail.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != null ? detail
-                .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule().getInvoice()
-                : null);
+        docLine.setInvoiceId(data[i].getField("cInvoiceId"));
         docLine.m_Record_Id2 = data[i].getField("recordId2");
         docLine.setInvoiceTaxCashVAT_V(Line_ID);
         docLine.setInvoiceTaxCashVAT_V(data[i].getField("MergedPaymentDetailId"));
@@ -472,6 +474,10 @@
                   isReceipt, conn), C_Currency_ID, (isReceipt ? "" : bpAmount),
               (isReceipt ? bpAmount : ""), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
         }
+
+        if (i % 100 == 0) {
+          OBDal.getInstance().getSession().clear();
+        }
       }
       FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, Record_ID);
       if (BigDecimal.ZERO.compareTo(new BigDecimal(Amounts[AMTTYPE_Gross])) != 0) {
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINFinAccTransaction.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINFinAccTransaction.java	Tue Feb 09 09:45:56 2016 +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) 2010-2013 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -20,11 +20,14 @@
 
 import java.math.BigDecimal;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.common.invoice.Invoice;
 
-public class DocLine_FINFinAccTransaction extends DocLineCashVATReady_PaymentTransactionReconciliation {
+public class DocLine_FINFinAccTransaction extends
+    DocLineCashVATReady_PaymentTransactionReconciliation {
   static Logger log4jDocLine_FINFinAccTransaction = Logger
       .getLogger(DocLine_FINFinAccTransaction.class);
 
@@ -37,7 +40,10 @@
   String WriteOffAmt = "";
   boolean isPrepaymentAgainstInvoice = false;
   BigDecimal doubtFulDebtAmount = BigDecimal.ZERO;
+
+  @Deprecated
   Invoice invoice = null;
+  private String invoiceId;
 
   public String getcGlItemId() {
     return cGlItemId;
@@ -48,18 +54,35 @@
   }
 
   public Invoice getInvoice() {
-    return invoice;
+    if (invoice != null) {
+      return invoice;
+    } else if (StringUtils.isNotBlank(invoiceId)) {
+      try {
+        OBContext.setAdminMode(false);
+        return OBDal.getInstance().get(Invoice.class, invoiceId);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    } else {
+      return null;
+    }
   }
 
+  /**
+   * @deprecated Use {@link #setInvoiceId(String)} instead, which avoids to store a object in memory
+   *             so we can control from outside when to flush and/or clear the session to avoid Out
+   *             Of Memory errors
+   */
   public void setInvoice(Invoice invoice) {
     this.invoice = invoice;
   }
 
-  @Deprecated
-  public String getInvoiceId() {
-    return invoice.getId();
-  }
-
+  /**
+   * @deprecated Use {@link #setInvoiceId(String)} instead, which avoids to store a object in memory
+   *             so we can control from outside when to flush and/or clear the session to avoid Out
+   *             Of Memory errors
+   * 
+   */
   @Deprecated
   public void setInvoice_ID(String invoiceId) {
     this.invoice = OBDal.getInstance().get(Invoice.class, invoiceId);
@@ -193,6 +216,14 @@
     this.doubtFulDebtAmount = doubtFulDebtAmount;
   }
 
+  public String getInvoiceId() {
+    return invoiceId;
+  }
+
+  public void setInvoiceId(String invoiceId) {
+    this.invoiceId = invoiceId;
+  }
+
   public DocLine_FINFinAccTransaction(String DocumentType, String TrxHeader_ID, String TrxLine_ID) {
     super(DocumentType, TrxHeader_ID, TrxLine_ID);
     Line_ID = TrxLine_ID;
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java	Tue Feb 09 09:45:56 2016 +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) 2010-2013 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -20,6 +20,9 @@
 
 import java.math.BigDecimal;
 
+import org.apache.commons.lang.StringUtils;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.order.Order;
 
@@ -32,22 +35,59 @@
   String C_GLItem_ID = "";
   String isPrepayment = "";
   boolean isPrepaymentAgainstInvoice = false;
+  BigDecimal doubtFulDebtAmount = BigDecimal.ZERO;
+
+  @Deprecated
   Invoice invoice = null;
-  BigDecimal doubtFulDebtAmount = BigDecimal.ZERO;
+  private String invoiceId;
+  @Deprecated
   Order order = null;
+  private String orderId;
 
   public Invoice getInvoice() {
-    return invoice;
+    if (invoice != null) {
+      return invoice;
+    } else if (StringUtils.isNotBlank(invoiceId)) {
+      try {
+        OBContext.setAdminMode(false);
+        return OBDal.getInstance().get(Invoice.class, invoiceId);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    } else {
+      return null;
+    }
   }
 
+  /**
+   * @deprecated Use {@link #setInvoiceId(String)} instead, which avoids to store a object in memory
+   *             so we can control from outside when to flush and/or clear the session to avoid Out
+   *             Of Memory errors
+   */
   public void setInvoice(Invoice invoice) {
     this.invoice = invoice;
   }
 
   public Order getOrder() {
-    return order;
+    if (order != null) {
+      return order;
+    } else if (StringUtils.isNotBlank(orderId)) {
+      try {
+        OBContext.setAdminMode(false);
+        return OBDal.getInstance().get(Order.class, orderId);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+    } else {
+      return null;
+    }
   }
 
+  /**
+   * @deprecated Use {@link #setOrderId(String)} instead, which avoids to store a object in memory
+   *             so we can control from outside when to flush and/or clear the session to avoid Out
+   *             Of Memory errors
+   */
   public void setOrder(Order order) {
     this.order = order;
   }
@@ -175,4 +215,20 @@
   public String getServletInfo() {
     return "Servlet for accounting";
   } // end of getServletInfo() method
+
+  public String getInvoiceId() {
+    return invoiceId;
+  }
+
+  public void setInvoiceId(String invoiceId) {
+    this.invoiceId = invoiceId;
+  }
+
+  public String getOrderId() {
+    return orderId;
+  }
+
+  public void setOrderId(String orderId) {
+    this.orderId = orderId;
+  }
 }
--- a/src/org/openbravo/erpCommon/ad_reports/ReportPricelist.fo	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportPricelist.fo	Tue Feb 09 09:45:56 2016 +0100
@@ -12,7 +12,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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,7 +28,7 @@
 			<fo:block text-align="center" font-weight="bold" font-size="11pt">&#160;</fo:block>
 			<fo:block text-align="center" font-weight="bold" font-size="20pt">SALE ORDER REPORT</fo:block>
 			<fo:block text-align="center" font-weight="bold" font-size="11pt" id="fieldValid"/>
-			<fo:table space-before.optimum="20pt">
+			<fo:table table-layout="fixed" width="100%" space-before.optimum="20pt">
 				<fo:table-column column-width="24mm"/>
 				<fo:table-column column-width="90mm"/>
 				<fo:table-column column-width="24mm"/>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportRefundSalesDimensionalAnalyses.fo	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportRefundSalesDimensionalAnalyses.fo	Tue Feb 09 09:45:56 2016 +0100
@@ -12,7 +12,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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -20,12 +20,12 @@
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 	<fo:layout-master-set>
 		<fo:simple-page-master master-name="first" page-height="21cm" page-width="29.7cm" margin-top="1cm" margin-bottom="0.25cm" margin-left="0.5cm" margin-right="0.5cm">
+			<fo:region-body margin-top="2cm"/>
 			<fo:region-before extent="2cm"/>
-			<fo:region-body margin-top="2cm"/>
 		</fo:simple-page-master>
 		<fo:simple-page-master master-name="rest" page-height="21cm" page-width="29.7cm" margin-top="1cm" margin-bottom="0.25cm" margin-left="0.5cm" margin-right="0.5cm">
+			<fo:region-body margin-top="2cm"/>
 			<fo:region-before extent="2cm"/>
-			<fo:region-body margin-top="2cm"/>
 		</fo:simple-page-master>
 		<fo:page-sequence-master master-name="basicPSM">
 			<fo:repeatable-page-master-alternatives>
--- a/src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java	Tue Feb 09 09:45:56 2016 +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) 2010-2012 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -81,6 +81,7 @@
 import org.openbravo.model.financialmgmt.calendar.Calendar;
 import org.openbravo.model.financialmgmt.calendar.Year;
 import org.openbravo.model.financialmgmt.gl.GLCategory;
+import org.openbravo.service.datasource.DataSource;
 import org.openbravo.service.db.DataImportService;
 import org.openbravo.service.db.ImportResult;
 
@@ -326,7 +327,15 @@
    */
   public static List<TableTree> tableTreeRelation() throws Exception {
     final OBCriteria<TableTree> obcTableTree = OBDal.getInstance().createCriteria(TableTree.class);
-    obcTableTree.add(Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, "ADTree"));
+    // Together with those trees that use the ADTree tree structure, we also include in the list the
+    // tree for account elements because it makes use of a custom extension of the ADTree structure.
+    // See issue https://issues.openbravo.com/view.php?id=31856
+    DataSource accountTreeDatasource = OBDal.getInstance().get(DataSource.class,
+        "D2F94DC86DEC48D69E4BFCE59DC670CF");
+    obcTableTree.add(Restrictions.or(
+        //
+        Restrictions.eq(TableTree.PROPERTY_TREESTRUCTURE, "ADTree"),
+        Restrictions.eq(TableTree.PROPERTY_DATASOURCE, accountTreeDatasource)));
     obcTableTree.addOrder(Order.asc(TableTree.PROPERTY_NAME));
     return obcTableTree.list();
   }
--- a/src/org/openbravo/erpCommon/info/Account.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Account.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -85,13 +85,13 @@
   }
   
   function validateSelector(action) {
-  	var keys; var key; var text;
+  	var keys; var key; var text; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == 'SAVE') {
 	  	keys = getSelectdText().split("@_##_@"); 
 	  	key = keys[0];
 		text = keys[1];
 	}
-	parent.opener.closeSearch(action, key, text, null);
+	theOpener.closeSearch(action, key, text, null);
   }
   
   function disableSaveButton(a) {
--- a/src/org/openbravo/erpCommon/info/Account.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Account.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -183,7 +183,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].cValidcombinationId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].combination, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text, null);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text, null);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/AccountElementValue.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/AccountElementValue.html	Tue Feb 09 09:45:56 2016 +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) 2009-2010 Openbravo SLU
+ * All portions are Copyright (C) 2009-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -61,7 +61,7 @@
 </script>
 <script type="text/javascript">
   function validateSelector(action) {
-    var pos; var keys;  var key; var text; var parameter;
+    var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
     if(action == "SAVE") {
         pos = getSelectedPos();
         keys = getSelectedValues().split("@_##_@")
@@ -70,7 +70,7 @@
         parameter = new Array(
         );
     }
-    parent.opener.closeSearch(action, key, text, parameter);
+    theOpener.closeSearch(action, key, text, parameter);
   }
 </script>
 <script language="JavaScript" type="text/javascript">
--- a/src/org/openbravo/erpCommon/info/AccountElementValue.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/AccountElementValue.java	Tue Feb 09 09:45:56 2016 +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) 2009-2015 Openbravo SLU
+ * All portions are Copyright (C) 2009-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -151,7 +151,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].cElementvalueId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].name, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text, null);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text, null);\n");
     html.append("}\n");
     return html.toString();
   }
@@ -319,15 +320,15 @@
           data = AccountElementValueData.select(this, "ROWNUM", strAcctSchema, strValue, strName,
               strOrganization, strAccountElementValue,
               Utility.getContext(this, vars, "#User_Client", "AccountElementValue"),
-              Utility.getContext(this, vars, "#AccessibleOrgTree", "AccountElementValue"), strOrderBy,
-              oraLimit, "");
+              Utility.getContext(this, vars, "#AccessibleOrgTree", "AccountElementValue"),
+              strOrderBy, oraLimit, "");
         } else {
           String pgLimit = pageSize + " OFFSET " + offset;
           data = AccountElementValueData.select(this, "1", strAcctSchema, strValue, strName,
               strOrganization, strAccountElementValue,
               Utility.getContext(this, vars, "#User_Client", "AccountElementValue"),
-              Utility.getContext(this, vars, "#AccessibleOrgTree", "AccountElementValue"), strOrderBy, "",
-              pgLimit);
+              Utility.getContext(this, vars, "#AccessibleOrgTree", "AccountElementValue"),
+              strOrderBy, "", pgLimit);
         }
       } catch (ServletException e) {
         log4j.error("Error in print page data: " + e);
--- a/src/org/openbravo/erpCommon/info/AttributeSetInstance.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/AttributeSetInstance.html	Tue Feb 09 09:45:56 2016 +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) 2001-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -48,7 +48,8 @@
     if (msg!=null && msg != "") alert(msg);
     var key = document.frmMain.inpInstance.value;
     var text = document.frmMain.inpDescription.value;
-    top.opener.closeSearch("SAVE", key, text, null);
+    var theOpener = top.opener || getFrame('LayoutMDI');
+    theOpener.closeSearch("SAVE", key, text, null);
     return true;
 }
 </script>
@@ -59,11 +60,13 @@
 </script>
 <script language="JavaScript" type="text/javascript">
 function validateSelector(action) {
+    var theOpener = top.opener || getFrame('LayoutMDI');
     if (action=="SAVE") {
         if (validate()) {
             submitCommandForm("SAVE");
         }
-    } else top.opener.closeSearch(action, "", "", null);
+    } else theOpener.closeSearch(action, "", "", null);
+
     return true;
 }
 function validate() {
--- a/src/org/openbravo/erpCommon/info/BusinessPartner.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/BusinessPartner.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -51,7 +51,7 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
@@ -62,7 +62,7 @@
 		    new SearchElements("_CON", true, keys[1])
 		);
     }    
-  	parent.opener.closeSearch(action, key, text, parameter);
+  	theOpener.closeSearch(action, key, text, parameter);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/BusinessPartner.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/BusinessPartner.java	Tue Feb 09 09:45:56 2016 +0100
@@ -227,7 +227,8 @@
     html.append("new SearchElements(\"_LOC\", true, \"" + data[0].cBpartnerLocationId + "\"),\n");
     html.append("new SearchElements(\"_CON\", true, \"" + data[0].cBpartnerContactId + "\")\n");
     html.append(");\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text, parameter);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text, parameter);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/DebtPayment.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/DebtPayment.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -48,14 +48,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/ImageInfo.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ImageInfo.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -57,7 +57,8 @@
   function validateSelector(action) {
     var clave = radioValue(document.frmSelector.inpClave);
     var texto = document.frmSelector.inpTexto.value;
-    parent.opener.closeSearch(action, clave, texto);
+    var theOpener = parent.opener || getFrame('LayoutMDI');
+    theOpener.closeSearch(action, clave, texto);
   }
   </script>
 
--- a/src/org/openbravo/erpCommon/info/ImageInfoBLOB.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ImageInfoBLOB.html	Tue Feb 09 09:45:56 2016 +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) 2009-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -52,7 +52,8 @@
   function validateSelector(action) {
     var key = radioValue(document.frmSelector.inpKey);
     var text = document.frmSelector.inpText.value;
-    parent.opener.closeSearch(action, key, text);
+    var theOpener = parent.opener || getFrame('LayoutMDI');
+    theOpener.closeSearch(action, key, text);
   }
   </script>
 
--- a/src/org/openbravo/erpCommon/info/Invoice.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Invoice.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -48,14 +48,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/Invoice.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Invoice.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -244,7 +244,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].cInvoiceId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].name, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/InvoiceLine.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/InvoiceLine.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -47,14 +47,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/InvoiceLine.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/InvoiceLine.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -37,10 +37,10 @@
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.SQLReturnObject;
+import org.openbravo.erpCommon.utility.TableSQLData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.Replace;
 import org.openbravo.xmlEngine.XmlDocument;
-import org.openbravo.erpCommon.utility.TableSQLData;
 
 public class InvoiceLine extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
@@ -119,8 +119,7 @@
       String issotrx = vars.getStringParameter("inpIssotrx", "N");
       data = InvoiceLineData.selectKey(this,
           Utility.getContext(this, vars, "#User_Client", "InvoiceLine"),
-          Utility.getSelectorOrgs(this, vars, strOrg), strKeyValue + "%",
-	  issotrx);
+          Utility.getSelectorOrgs(this, vars, strOrg), strKeyValue + "%", issotrx);
 
       if (data != null && data.length == 1)
         printPageKey(response, vars, data);
@@ -191,7 +190,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].cInvoicelineId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].lineText, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/Location.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Location.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -139,7 +139,8 @@
     html.append("var key = \"" + data.cLocationId + "\";\n");
     html.append("var text = \""
         + Replace.replace(Replace.replace(data.name, "\\", "\\\\"), "\"", "\\\\\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/Location_F1.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Location_F1.html	Tue Feb 09 09:45:56 2016 +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) 2001-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -37,6 +37,11 @@
 	fillCombo(document.forms[0].inpCRegionId, dataArray, true);
 }
 
+function getOpener() {
+  var theOpener = parent.opener || getFrame('LayoutMDI');
+  return theOpener;
+}
+
 function onloadFunctions() {
 }
 </script>
@@ -202,7 +207,7 @@
                 <button type="button" 
                   id="buttonCancel" 
                   class="ButtonLink" 
-                  onclick="parent.opener.closeSearch('CLEAR', '', '');return false;" 
+                  onclick="getOpener().closeSearch('CLEAR', '', '');return false;" 
                   onfocus="buttonEvent('onfocus', this); window.status='Cancel'; return true;" 
                   onblur="buttonEvent('onblur', this);" 
                   onkeyup="buttonEvent('onkeyup', this);" 
--- a/src/org/openbravo/erpCommon/info/Location_FS.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Location_FS.html	Tue Feb 09 09:45:56 2016 +0100
@@ -21,6 +21,7 @@
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Location selector</title>
 <link rel="shortcut icon" href="../../../../../web/images/favicon.ico" type="image/x-icon" />
+<script language="JavaScript" src="../../../../../web/js/utils.js" type="text/javascript"></script>
 </head>
 <frameset rows="100%,*" frameborder="no" border="0" framespacing="0" cols="*">
 <frame name="superior" scrolling="no" noresize="" src="Location_F1.html?Command=FRAME1"></frame>
--- a/src/org/openbravo/erpCommon/info/Locator.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Locator.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -50,14 +50,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-    var pos; var keys;  var key; var text; var parameter;
+    var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
     if(action == "SAVE") {
       pos = getSelectedPos();
       keys = getSelectedValues().split("@_##_@")
       key = keys[0];
       text = keys[1];
     }    
-    parent.opener.closeSearch(action, key, text);
+    theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/Locator.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Locator.java	Tue Feb 09 09:45:56 2016 +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) 2001-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -202,7 +202,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].mLocatorId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].value, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/Product.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Product.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -50,7 +50,7 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-    var pos; var keys;  var key; var text; var parameter;
+    var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
     if(action == "SAVE") {
       pos = getSelectedPos();
       keys = getSelectedValues().split("@_##_@")
@@ -64,7 +64,7 @@
         new SearchElements("_CURR", true, keys[6])
       );
     }    
-  	parent.opener.closeSearch(action, key, text, parameter);
+  	theOpener.closeSearch(action, key, text, parameter);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/Product.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Product.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -308,7 +308,8 @@
     html.append("new SearchElements(\"_PLIST\", true, \""
         + df.format(new BigDecimal(data[0].pricelist)) + "\")\n");
     html.append(");\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text, parameter);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text, parameter);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/ProductComplete.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ProductComplete.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -50,7 +50,7 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
@@ -65,7 +65,7 @@
         new SearchElements("_UOM", true, keys[7])
 		);
     }    
-  	parent.opener.closeSearch(action, key, text, parameter);
+  	theOpener.closeSearch(action, key, text, parameter);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/ProductComplete.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ProductComplete.java	Tue Feb 09 09:45:56 2016 +0100
@@ -288,7 +288,8 @@
         + "\"),\n");
     html.append("new SearchElements(\"_UOM\", true, \"" + data[0].cUom1Id + "\")\n");
     html.append(");\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text, parameter);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text, parameter);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/Project.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Project.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -53,14 +53,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/Project.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/Project.java	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -179,7 +179,8 @@
     html.append("var key = \"" + data[0].cProjectId + "\";\n");
     html.append("var text = \""
         + Replace.replace((data[0].value + " - " + data[0].name), "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/SalesOrder.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/SalesOrder.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -60,14 +60,14 @@
 
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/SalesOrder.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/SalesOrder.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -174,7 +174,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].cOrderId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].documentno, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/SalesOrderLine.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/SalesOrderLine.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -61,14 +61,14 @@
 
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/SalesOrderLine.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/SalesOrderLine.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -263,7 +263,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].cOrderlineId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].lineText, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/SearchUniqueKeyResponse.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/SearchUniqueKeyResponse.html	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -33,7 +33,8 @@
 	new SearchElements("_LOC", true, "\"" + parent.medio.document.frmSelector.inpLocation.value + "\""),
 	new SearchElements("_CON", true, "\"" + parent.medio.document.frmSelector.inpContact.value + "\"")
 	);
-	parent.opener.closeSearch(action, key, text, parameter);
+	var theOpener = parent.opener || getFrame('LayoutMDI');
+	theOpener.closeSearch(action, key, text, parameter);
 }
 //-->
 </script>
--- a/src/org/openbravo/erpCommon/info/ShipmentReceipt.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ShipmentReceipt.html	Tue Feb 09 09:45:56 2016 +0100
@@ -55,14 +55,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/ShipmentReceipt.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ShipmentReceipt.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -181,7 +181,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].clave + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].documentno, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpCommon/info/ShipmentReceiptLine.html	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ShipmentReceiptLine.html	Tue Feb 09 09:45:56 2016 +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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -62,14 +62,14 @@
 </script>
 <script type="text/javascript">    
   function validateSelector(action) {
-  	var pos; var keys;  var key; var text; var parameter;
+  	var pos; var keys;  var key; var text; var parameter; var theOpener = parent.opener || getFrame('LayoutMDI');
   	if(action == "SAVE") {
 	    pos = getSelectedPos();
 	    keys = getSelectedValues().split("@_##_@")
 	    key = keys[0];
 	    text = keys[1];
     }    
-  	parent.opener.closeSearch(action, key, text);
+  	theOpener.closeSearch(action, key, text);
   }
 </script>
 <script language="JavaScript" type="text/javascript" id="selectedColumn">
--- a/src/org/openbravo/erpCommon/info/ShipmentReceiptLine.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpCommon/info/ShipmentReceiptLine.java	Tue Feb 09 09:45:56 2016 +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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -247,7 +247,8 @@
     html.append("\nfunction validateSelector() {\n");
     html.append("var key = \"" + data[0].mInoutlineId + "\";\n");
     html.append("var text = \"" + Replace.replace(data[0].lineText, "\"", "\\\"") + "\";\n");
-    html.append("parent.opener.closeSearch(\"SAVE\", key, text);\n");
+    html.append("var theOpener = parent.opener || getFrame('LayoutMDI');\n");
+    html.append("theOpener.closeSearch(\"SAVE\", key, text);\n");
     html.append("}\n");
     return html.toString();
   }
--- a/src/org/openbravo/erpReports/RptMA_CCP_Group.fo	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpReports/RptMA_CCP_Group.fo	Tue Feb 09 09:45:56 2016 +0100
@@ -12,7 +12,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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -20,9 +20,9 @@
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
     <fo:simple-page-master master-name="first" page-height="29.7cm" page-width="21cm" margin-top="1.5cm" margin-bottom="0.25cm" margin-left="1cm" margin-right="1cm">
+      <fo:region-body margin-top="3cm" margin-bottom="1.25cm"/>
       <fo:region-before extent="3cm"/>
       <fo:region-after extent="1cm"/>
-      <fo:region-body margin-top="3cm" margin-bottom="1.25cm"/>
     </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="first">
--- a/src/org/openbravo/erpReports/RptMA_CCP_Measures.fo	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpReports/RptMA_CCP_Measures.fo	Tue Feb 09 09:45:56 2016 +0100
@@ -12,7 +12,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) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -20,9 +20,9 @@
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
     <fo:simple-page-master master-name="first" page-height="29.7cm" page-width="21cm" margin-top="1.5cm" margin-bottom="0.25cm" margin-left="1cm" margin-right="1cm">
+      <fo:region-body margin-top="3cm" margin-bottom="1.25cm"/>
       <fo:region-before extent="3cm"/>
       <fo:region-after extent="1cm"/>
-      <fo:region-body margin-top="3cm" margin-bottom="1.25cm"/>
     </fo:simple-page-master>
   </fo:layout-master-set>
   <DIVFO id="sectionShiftid">
--- a/src/org/openbravo/erpReports/RptM_Inout.fo	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/erpReports/RptM_Inout.fo	Tue Feb 09 09:45:56 2016 +0100
@@ -12,7 +12,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) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -21,8 +21,8 @@
 	<!-- defines the layout master -->
 	<fo:layout-master-set>
 		<fo:simple-page-master master-name="first" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="0.25cm" margin-left="2cm" margin-right="1cm">
+			<fo:region-body margin-top="10cm"/>
 			<fo:region-before extent="10cm"/>
-			<fo:region-body margin-top="10cm"/>
 		</fo:simple-page-master>
 	</fo:layout-master-set>
 	<DIVFO id="sectionDetail">
--- a/src/org/openbravo/materialmgmt/actionhandler/ManageVariants.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/materialmgmt/actionhandler/ManageVariants.java	Tue Feb 09 09:45:56 2016 +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) 2013 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -106,6 +106,9 @@
 
   private void createVariant(JSONObject variantProperties, Product generic) throws JSONException {
     Product variant = (Product) DalUtil.copy(generic);
+    if (generic.getClient().isMultilingualDocuments()) {
+      variant.getProductTrlList().clear();
+    }
 
     variant.setGenericProduct(generic);
     variant.setProductAccountsList(Collections.<ProductAccounts> emptyList());
--- a/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java	Tue Feb 09 09:45:56 2016 +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) 2015 Openbravo SLU
+ * All portions are Copyright (C) 2015-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -104,7 +104,6 @@
 
     @Override
     public void run() {
-
       Thread.currentThread().setName("Import Entry Archiver");
 
       // don't start right away at startup, give the system time to
@@ -116,6 +115,11 @@
       }
       log.debug("Run loop started");
 
+      if (manager.isShutDown) {
+        // don't even start, the import entry manager has been shut down
+        return;
+      }
+
       // make ourselves an admin
       OBContext.setOBContext("0", "0", "0", "0");
       Date lastCreated = null;
--- a/src/org/openbravo/service/importprocess/ImportEntryManager.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/service/importprocess/ImportEntryManager.java	Tue Feb 09 09:45:56 2016 +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) 2015 Openbravo SLU
+ * All portions are Copyright (C) 2015-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -161,6 +161,10 @@
 
   private boolean isShutDown = false;
 
+  public boolean isShutDown() {
+    return isShutDown;
+  }
+
   public ImportEntryManager() {
     instance = this;
     importBatchSize = ImportProcessUtils.getCheckIntProperty(log, "import.batch.size",
@@ -195,6 +199,7 @@
     managerThread = new ImportEntryManagerThread(this);
     executorService.submit(managerThread);
     importEntryArchiveManager.start();
+    isShutDown = false;
   }
 
   public long getNumberOfQueuedTasks() {
@@ -502,6 +507,9 @@
         Thread.sleep(manager.initialWaitTime);
       } catch (Exception ignored) {
       }
+      if (manager.isShutDown) {
+        return;
+      }
       log.debug("Run loop started");
       try {
         List<String> typesOfData = null;
--- a/src/org/openbravo/service/importprocess/ImportEntryProcessor.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/service/importprocess/ImportEntryProcessor.java	Tue Feb 09 09:45:56 2016 +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) 2015 Openbravo SLU
+ * All portions are Copyright (C) 2015-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -286,6 +286,9 @@
       try {
         while (true) {
           try {
+            if (importEntryManager.isShutDown()) {
+              return;
+            }
             doRunCycle();
           } catch (Throwable logIt) {
             // prevent the loop from exiting, only log the exception
@@ -331,6 +334,9 @@
       QueuedEntry queuedImportEntry;
       while ((queuedImportEntry = importEntries.poll()) != null) {
         try {
+          if (importEntryManager.isShutDown()) {
+            return;
+          }
           final long t0 = System.currentTimeMillis();
 
           // set the same obcontext as was being used for the original
--- a/src/org/openbravo/service/system/SystemService.java	Mon Feb 08 16:14:49 2016 +0100
+++ b/src/org/openbravo/service/system/SystemService.java	Tue Feb 09 09:45:56 2016 +0100
@@ -492,10 +492,20 @@
    * applying the exclude filters
    */
   public Database getModelFromDatabase(Platform platform) {
+    boolean doPlSqlStandardization = true;
+    return getModelFromDatabase(platform, doPlSqlStandardization);
+  }
+
+  /**
+   * Given a org.apache.ddlutils.Platform, builds a org.apache.ddlutils.model.Database after
+   * applying the exclude filters. It is possible to specify whether the PLSQL code standardization
+   * should be done
+   */
+  public Database getModelFromDatabase(Platform platform, boolean doPlSqlStandardization) {
     ExcludeFilter excludeFilter = DBSMOBUtil.getInstance().getExcludeFilter(
         new File(OBPropertiesProvider.getInstance().getOpenbravoProperties()
             .getProperty("source.path")));
-    return platform.loadModelFromDatabase(excludeFilter);
+    return platform.loadModelFromDatabase(excludeFilter, doPlSqlStandardization);
   }
 
   private void enableConstraints(Platform platform) {