[pi-process-multi-record] Merge with latest pi
authorNaroa Iriarte <naroa.iriarte@openbravo.com>
Tue, 22 Nov 2016 13:14:49 +0100
changeset 31470 26c591b1863d
parent 31469 81a5a62b5ad8 (current diff)
parent 30975 64b44ea14896 (diff)
child 31471 0264118a76fa
[pi-process-multi-record] Merge with latest pi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/FundsTransferPostProcessHook.java	Tue Nov 22 13:14:49 2016 +0100
@@ -0,0 +1,40 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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.advpaymentmngt;
+
+import java.util.List;
+
+import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
+
+/**
+ * Interface to be used to extend the Funds Transfer functionality.
+ * 
+ * @author Daniel Martins
+ * 
+ */
+public interface FundsTransferPostProcessHook {
+
+  /**
+   * Method to implement in extension classes. This method will be called to extend functionality.
+   * 
+   * @param transactions
+   *          A list of all transactions created by Funds Transfer
+   */
+  public void exec(List<FIN_FinaccTransaction> transactions) throws Exception;
+}
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/FundsTransferActionHandler.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/FundsTransferActionHandler.java	Tue Nov 22 13:14:49 2016 +0100
@@ -20,7 +20,6 @@
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -34,6 +33,7 @@
 import org.openbravo.advpaymentmngt.process.FIN_TransactionProcess;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
+import org.openbravo.base.weld.WeldUtils;
 import org.openbravo.client.application.process.BaseProcessActionHandler;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
@@ -115,13 +115,7 @@
       log.error(ERROR_IN_PROCESS, e);
 
       return createPopUpError(e.getMessage(), true);
-    } catch (JSONException e) {
-      log.error(ERROR_IN_PROCESS, e);
-
-      return createResponse(JsonConstants.RESPONSE_ERROR,
-          OBMessageUtils.messageBD("OBUIAPP_Error"), OBMessageUtils.messageBD("APRM_UnknownError"),
-          false);
-    } catch (ParseException e) {
+    } catch (Exception e) {
       log.error(ERROR_IN_PROCESS, e);
 
       return createResponse(JsonConstants.RESPONSE_ERROR,
@@ -190,9 +184,13 @@
 
       OBDal.getInstance().flush();
       processTransactions(transactions);
-    } catch (OBException obe) {
-      String message = OBMessageUtils.parseTranslation(obe.getMessage());
-      throw new OBException(message, obe);
+
+      WeldUtils.getInstanceFromStaticBeanManager(FundsTransferHookCaller.class).executeHook(
+          transactions);
+
+    } catch (Exception e) {
+      String message = OBMessageUtils.parseTranslation(e.getMessage());
+      throw new OBException(message, e);
     }
   }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/FundsTransferHookCaller.java	Tue Nov 22 13:14:49 2016 +0100
@@ -0,0 +1,48 @@
+/*
+ *************************************************************************
+ * 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.advpaymentmngt.actionHandler;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.openbravo.advpaymentmngt.FundsTransferPostProcessHook;
+import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
+
+public class FundsTransferHookCaller {
+
+  @Inject
+  @Any
+  private Instance<FundsTransferPostProcessHook> hooks;
+
+  public void executeHook(List<FIN_FinaccTransaction> transactions) throws Exception {
+    executeHooks(transactions);
+  }
+
+  private void executeHooks(List<FIN_FinaccTransaction> transactions) throws Exception {
+    for (Iterator<FundsTransferPostProcessHook> procIter = hooks.iterator(); procIter.hasNext();) {
+      FundsTransferPostProcessHook proc = procIter.next();
+      proc.exec(transactions);
+    }
+  }
+
+}
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Tue Nov 22 13:14:49 2016 +0100
@@ -325,7 +325,7 @@
           // Execution Process
           if (!isPosOrder
               && dao.isAutomatedExecutionPayment(payment.getAccount(), payment.getPaymentMethod(),
-                  payment.isReceipt())) {
+                  payment.isReceipt()) && payment.getAmount().compareTo(BigDecimal.ZERO) != 0) {
             try {
               payment.setStatus("RPAE");
 
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachImplementationManager.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachImplementationManager.java	Tue Nov 22 13:14:49 2016 +0100
@@ -92,6 +92,9 @@
   @Inject
   private ApplicationDictionaryCachedStructures adcs;
 
+  private static final int DATA_TYPE_MAX_LENGTH = ModelProvider.getInstance()
+      .getEntity(Attachment.class).getProperty(Attachment.PROPERTY_DATATYPE).getFieldLength();
+
   /**
    * Method to upload files. This method calls needed handler class
    * 
@@ -152,7 +155,10 @@
         strDataType = new Tika().detect(file);
       } catch (IOException ignore) {
       }
-      attachment.setDataType(strDataType);
+
+      if (strDataType != null && strDataType.length() <= DATA_TYPE_MAX_LENGTH) {
+        attachment.setDataType(strDataType);
+      }
 
       OBDal.getInstance().save(attachment);
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Wed Nov 16 15:20:19 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Tue Nov 22 13:14:49 2016 +0100
@@ -2280,7 +2280,6 @@
   },
 
   getFetchRequestParams: function (params, isExporting) {
-    var i, len, first, selectedProperties;
     params = params || {};
 
     if (this.targetRecordId) {
@@ -2321,28 +2320,34 @@
     }
 
     if (!isExporting) {
-      first = true;
-      selectedProperties = '';
-      len = this.requiredGridProperties.length;
-      for (i = 0; i < len; i++) {
-        if (first) {
-          first = false;
-          selectedProperties = selectedProperties + this.requiredGridProperties[i];
-        } else {
-          selectedProperties = selectedProperties + ',' + this.requiredGridProperties[i];
-        }
+      params._selectedProperties = this.getSelectedProperties();
+    }
+    return params;
+  },
+
+  getSelectedProperties: function () {
+    var i, len, selectedProperties = '',
+        first = true;
+
+    len = this.requiredGridProperties.length;
+    for (i = 0; i < len; i++) {
+      if (first) {
+        first = false;
+        selectedProperties = selectedProperties + this.requiredGridProperties[i];
+      } else {
+        selectedProperties = selectedProperties + ',' + this.requiredGridProperties[i];
       }
-
-      len = this.fields.length;
-      for (i = 0; i < len; i++) {
-        if (this.fields[i].name[0] !== '_') {
-          selectedProperties = selectedProperties + ',';
-          selectedProperties = selectedProperties + this.fields[i].name;
-        }
+    }
+
+    len = this.fields.length;
+    for (i = 0; i < len; i++) {
+      if (this.fields[i].name[0] !== '_') {
+        selectedProperties = selectedProperties + ',';
+        selectedProperties = selectedProperties + this.fields[i].name;
       }
-      params._selectedProperties = selectedProperties;
-    }
-    return params;
+    }
+
+    return selectedProperties;
   },
 
   createNew: function () {
@@ -3152,7 +3157,7 @@
     }
   },
 
-  // Checks if there are changes in the other other than a field changing from undefined to not undefined
+  // Checks if there are changes other than a field changing from undefined to not undefined
   // Those kind of changes happen when a row is opened in edit mode, they should not be detected as an actual change
   recordHasActualChanges: function (rowNum, colNum, checkEditor) {
     var newValues, oldValues, changes = false,
@@ -4108,7 +4113,7 @@
   },
 
   processColumnValue: function (rowNum, columnName, columnValue) {
-    var field, newValue;
+    var field;
     if (!columnValue) {
       return;
     }
@@ -4116,10 +4121,6 @@
     if (!field) {
       return;
     }
-    newValue = {};
-    if (field) {
-      newValue[field.property] = columnValue.value;
-    }
     this.setEditValue(rowNum, field.property, columnValue.value);
   },
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Wed Nov 16 15:20:19 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Tue Nov 22 13:14:49 2016 +0100
@@ -2041,7 +2041,8 @@
 
   refreshCurrentRecord: function (callBackFunction) {
     var me = this,
-        criteria, callback;
+        criteria, callback, requestProperties = {},
+        params = {};
 
     if (!this.viewGrid.getSelectedRecord()) {
       return;
@@ -2077,7 +2078,11 @@
     } else {
       // Make a request to refresh the grid
       criteria = this.buildCriteriaToRefreshSelectedRecord();
-      this.getDataSource().fetchData(criteria, callback);
+      // Include grid selected properties in the request
+      // This way we retrieve the same record information which is obtained when refreshing the whole grid
+      params._selectedProperties = this.viewGrid.getSelectedProperties();
+      requestProperties.params = params;
+      this.getDataSource().fetchData(criteria, callback, requestProperties);
     }
     this.refreshParentRecord(callBackFunction);
   },
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Tue Nov 22 13:14:49 2016 +0100
@@ -1626,8 +1626,13 @@
             joinDefinitions.add(joinDefinition);
           }
         }
-
-        sb.append(createIdentifierLeftClause(newIdentifierProperties, newPrefix + DalUtil.DOT));
+        if (prop.isMandatory()) {
+          sb.append(createIdentifierLeftClause(newIdentifierProperties, newPrefix + DalUtil.DOT));
+        } else {
+          sb.append("COALESCE(to_char("
+              + createIdentifierLeftClause(newIdentifierProperties, newPrefix + DalUtil.DOT)
+              + "),'')");
+        }
       }
     }
 
Binary file src-db/database/lib/dbsourcemanager.jar has changed
--- a/src-db/database/model/views/C_INVOICE_CANDIDATE_V.xml	Wed Nov 16 15:20:19 2016 +0100
+++ b/src-db/database/model/views/C_INVOICE_CANDIDATE_V.xml	Tue Nov 22 13:14:49 2016 +0100
@@ -1,4 +1,4 @@
 <?xml version="1.0"?>
   <database name="VIEW C_INVOICE_CANDIDATE_V">
-    <view name="C_INVOICE_CANDIDATE_V"><![CDATA[SELECT o.ad_client_id, o.ad_org_id, o.c_bpartner_id, o.c_order_id, o.documentno, o.dateordered, o.c_doctype_id, o.totallines AS amountlines, o.grandtotal AS amountlinesgross, sum(round((l.qtyordered - l.qtyinvoiced) * l.priceactual, c.stdprecision)) AS notinvoicedlines, round(sum(round((l.qtyordered - l.qtyinvoiced) * l.priceactual, c.stdprecision) * (1 + t.rate / 100)), c.stdprecision) AS notinvoicedlinesgross, o.invoicerule AS term, sum(round((l.qtydelivered - l.qtyinvoiced) * l.priceactual, c.stdprecision)) AS pendinglines, round(sum(round((l.qtydelivered - l.qtyinvoiced) * l.priceactual, c.stdprecision) * (1 + t.rate / 100)), c.stdprecision) AS pendinglinesgross, sum(abs(l.qtyordered)) AS qtyordered, sum(abs(l.qtydelivered)) AS qtydelivered FROM c_order o JOIN c_doctype dt ON o.c_doctype_id = dt.c_doctype_id JOIN c_bpartner bp ON o.c_bpartner_id = bp.c_bpartner_id JOIN c_currency c ON o.c_currency_id = c.c_currency_id JOIN c_orderline l ON o.c_order_id = l.c_order_id JOIN c_tax t ON t.c_tax_id = l.c_tax_id LEFT JOIN c_invoiceschedule si ON bp.c_invoiceschedule_id = si.c_invoiceschedule_id WHERE (o.docstatus = 'CO' OR o.docstatus = 'CL' OR o.docstatus = 'IP') AND (o.invoicerule = 'I' OR o.invoicerule = 'O' OR o.invoicerule = 'N' OR o.invoicerule = 'D' OR o.invoicerule = 'S') AND dt.docbasetype = 'SOO' AND (dt.docsubtypeso <> 'ON' OR dt.docsubtypeso <> 'OB' OR dt.docsubtypeso <> 'WR') AND (si.invoicefrequency IS NULL OR (si.invoicefrequency = 'D' OR si.invoicefrequency = 'W' OR si.invoicefrequency = 'T') AND trunc(o.dateordered) <= (trunc(now(), 'MM') + si.invoicedaycutoff - 1) AND trunc(now()) >= (trunc(o.dateordered, 'MM') + si.invoiceday - 1) OR trunc(o.dateordered) <= (trunc(now(), 'MM') + si.invoicedaycutoff + 14) AND trunc(now()) >= (trunc(o.dateordered, 'MM') + si.invoiceday + 14) OR si.invoicefrequency = 'M' AND trunc(o.dateordered) <= (trunc(now(), 'MM') + si.invoicedaycutoff - 1) AND trunc(now()) >= (trunc(o.dateordered, 'MM') + si.invoiceday - 1)) AND (abs(l.qtyordered - l.qtyinvoiced) <> 0 OR abs(l.qtydelivered - l.qtyinvoiced) <> 0) GROUP BY o.ad_client_id, o.ad_org_id, o.c_bpartner_id, o.c_order_id, o.documentno, o.dateordered, o.c_doctype_id, o.totallines, o.grandtotal, o.invoicerule, c.c_currency_id, c.stdprecision]]></view>
+    <view name="C_INVOICE_CANDIDATE_V"><![CDATA[SELECT o.ad_client_id, o.ad_org_id, o.c_bpartner_id, o.c_order_id, o.documentno, o.dateordered, o.c_doctype_id, o.totallines AS amountlines, o.grandtotal AS amountlinesgross, sum(round((l.qtyordered - l.qtyinvoiced) * l.priceactual, c.stdprecision)) AS notinvoicedlines, round(sum(round((l.qtyordered - l.qtyinvoiced) * l.priceactual, c.stdprecision) * (1 + t.rate / 100)), c.stdprecision) AS notinvoicedlinesgross, o.invoicerule AS term, sum(round((l.qtydelivered - l.qtyinvoiced) * l.priceactual, c.stdprecision)) AS pendinglines, round(sum(round((l.qtydelivered - l.qtyinvoiced) * l.priceactual, c.stdprecision) * (1 + t.rate / 100)), c.stdprecision) AS pendinglinesgross, sum(abs(l.qtyordered)) AS qtyordered, sum(abs(l.qtydelivered)) AS qtydelivered FROM c_order o JOIN c_doctype dt ON o.c_doctype_id = dt.c_doctype_id JOIN c_bpartner bp ON o.c_bpartner_id = bp.c_bpartner_id JOIN c_currency c ON o.c_currency_id = c.c_currency_id JOIN c_orderline l ON o.c_order_id = l.c_order_id JOIN c_tax t ON t.c_tax_id = l.c_tax_id LEFT JOIN c_invoiceschedule si ON bp.c_invoiceschedule_id = si.c_invoiceschedule_id WHERE (o.docstatus = 'CO' OR o.docstatus = 'CL' OR o.docstatus = 'IP') AND (o.invoicerule = 'I' OR o.invoicerule = 'O' OR o.invoicerule = 'D' OR o.invoicerule = 'S') AND dt.docbasetype = 'SOO' AND (dt.docsubtypeso <> 'ON' OR dt.docsubtypeso <> 'OB' OR dt.docsubtypeso <> 'WR') AND (si.invoicefrequency IS NULL OR (si.invoicefrequency = 'D' OR si.invoicefrequency = 'W' OR si.invoicefrequency = 'T') AND trunc(o.dateordered) <= (trunc(now(), 'MM') + si.invoicedaycutoff - 1) AND trunc(now()) >= (trunc(o.dateordered, 'MM') + si.invoiceday - 1) OR trunc(o.dateordered) <= (trunc(now(), 'MM') + si.invoicedaycutoff + 14) AND trunc(now()) >= (trunc(o.dateordered, 'MM') + si.invoiceday + 14) OR si.invoicefrequency = 'M' AND trunc(o.dateordered) <= (trunc(now(), 'MM') + si.invoicedaycutoff - 1) AND trunc(now()) >= (trunc(o.dateordered, 'MM') + si.invoiceday - 1)) AND (abs(l.qtyordered - l.qtyinvoiced) <> 0 OR abs(l.qtydelivered - l.qtyinvoiced) <> 0) GROUP BY o.ad_client_id, o.ad_org_id, o.c_bpartner_id, o.c_order_id, o.documentno, o.dateordered, o.c_doctype_id, o.totallines, o.grandtotal, o.invoicerule, c.c_currency_id, c.stdprecision]]></view>
   </database>
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Wed Nov 16 15:20:19 2016 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Nov 22 13:14:49 2016 +0100
@@ -21197,7 +21197,7 @@
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <VALUE><![CDATA[BackgroundPolicyNoExecuteMsg]]></VALUE>
-<!--714FC5887F6E4FE08F57D4E69D75DC52-->  <MSGTEXT><![CDATA[This instance's policy for background processes is not to execute them, therefore it is not allowed to schedule or unschedule processes here. There should be another instance allowing background process execution, it is in that instance where this action should be performed.]]></MSGTEXT>
+<!--714FC5887F6E4FE08F57D4E69D75DC52-->  <MSGTEXT><![CDATA[This instance's policy for background processes is not to execute them, therefore it is not allowed to schedule, unschedule nor kill processes here. There should be another instance allowing background process execution, it is in that instance where this action should be performed.]]></MSGTEXT>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--714FC5887F6E4FE08F57D4E69D75DC52-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
--- a/src/org/openbravo/common/actionhandler/KillProcess.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/common/actionhandler/KillProcess.java	Tue Nov 22 13:14:49 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):  ______________________________________.
  ************************************************************************
@@ -46,10 +46,12 @@
 
   @Override
   protected JSONObject doExecute(Map<String, Object> parameters, String content) {
+    JSONObject result = new JSONObject();
+    try {
+      if (OBScheduler.isNoExecuteBackgroundPolicy()) {
+        return buildResult("error", "Error", "BackgroundPolicyNoExecuteMsg");
+      }
 
-    JSONObject result = new JSONObject();
-
-    try {
       JSONObject request = new JSONObject(content);
       String strProcessRunId = request.getString("inpadProcessRunId");
 
--- a/src/org/openbravo/erpCommon/ad_process/ScheduleProcess.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_process/ScheduleProcess.java	Tue Nov 22 13:14:49 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) 2008-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,7 +28,6 @@
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
@@ -52,9 +51,7 @@
   @Override
   public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
-    String policy = OBPropertiesProvider.getInstance().getOpenbravoProperties()
-        .getProperty("background.policy", "default");
-    if ("no-execute".equals(policy)) {
+    if (OBScheduler.isNoExecuteBackgroundPolicy()) {
       log.info("Not scheduling process because current context background policy is 'no-execute'");
       advisePopUp(request, response, "ERROR",
           OBMessageUtils.messageBD("BackgroundPolicyNoExecuteTitle"),
--- a/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock.java	Tue Nov 22 13:14:49 2016 +0100
@@ -43,14 +43,12 @@
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.client.application.report.ReportingUtils;
-import org.openbravo.costing.CostingBackground;
 import org.openbravo.costing.CostingStatus;
 import org.openbravo.costing.CostingUtils;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
-import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.DateTimeData;
@@ -61,10 +59,8 @@
 import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
-import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.erpCommon.utility.ToolBar;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.common.enterprise.Locator;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.plm.Product;
@@ -564,20 +560,6 @@
     return whereQry.uniqueResult() != null;
   }
 
-  private boolean transactionCostDateAcctInitialized() {
-    boolean transactionCostDateacctInitialized = false;
-    Client client = OBDal.getInstance().get(Client.class, "0");
-    Organization organization = OBDal.getInstance().get(Organization.class, "0");
-    try {
-      transactionCostDateacctInitialized = Preferences.getPreferenceValue(
-          CostingBackground.TRANSACTION_COST_DATEACCT_INITIALIZED, false, client, organization,
-          null, null, null).equals(Preferences.YES);
-    } catch (PropertyException e1) {
-      transactionCostDateacctInitialized = false;
-    }
-    return transactionCostDateacctInitialized;
-  }
-
   public String getServletInfo() {
     return "Servlet ReportValuationStock. This Servlet was made by Pablo Sarobe";
   } // end of getServletInfo() method
--- a/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock2.html	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportValuationStock2.html	Tue Nov 22 13:14:49 2016 +0100
@@ -127,7 +127,6 @@
 		refreshComboOrgs();
 		selectWarehouse();
 		setWindowElementFocus('firstElement');
-		setDefaultCurrency();
 	}
 
 	function onResizeDo(){
--- a/src/org/openbravo/erpCommon/obps/ActivationKey.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/erpCommon/obps/ActivationKey.java	Tue Nov 22 13:14:49 2016 +0100
@@ -292,11 +292,7 @@
    */
   public static synchronized ActivationKey reload() {
     ActivationKey ak = getInstance();
-    org.openbravo.model.ad.system.System sys = OBDal.getInstance().get(
-        org.openbravo.model.ad.system.System.class, "0");
-    ak.loadInfo(sys.getActivationKey());
-    ak.loadRestrictions();
-    ak.lastUpdateTimestamp = sys.getUpdated();
+    ak.loadFromDB();
     return ak;
   }
 
@@ -311,18 +307,21 @@
   public ActivationKey() {
     OBContext.setAdminMode();
     try {
-      org.openbravo.model.ad.system.System sys = OBDal.getInstance().get(
-          org.openbravo.model.ad.system.System.class, "0");
-      strPublicKey = sys.getInstanceKey();
-      lastUpdateTimestamp = sys.getUpdated();
-      String activationKey = sys.getActivationKey();
-      loadInfo(activationKey);
-      loadRestrictions();
+      loadFromDB();
     } finally {
       OBContext.restorePreviousMode();
     }
   }
 
+  private void loadFromDB() {
+    org.openbravo.model.ad.system.System sys = OBDal.getInstance().get(
+        org.openbravo.model.ad.system.System.class, "0");
+    strPublicKey = sys.getInstanceKey();
+    lastUpdateTimestamp = sys.getUpdated();
+    loadInfo(sys.getActivationKey());
+    loadRestrictions();
+  }
+
   public ActivationKey(String publicKey, String activationKey) {
     strPublicKey = publicKey;
     loadInfo(activationKey);
@@ -330,29 +329,7 @@
   }
 
   private void loadInfo(String activationKey) {
-    // Reset
-    isActive = false;
-    hasActivationKey = false;
-    errorMessage = "";
-    messageType = "Error";
-    instanceProperties = null;
-    hasExpired = false;
-    subscriptionConvertedProperty = false;
-    subscriptionActuallyConverted = false;
-    tier1Artifacts = null;
-    tier2Artifacts = null;
-    goldenExcludedArtifacts = null;
-    trial = false;
-    golden = false;
-    licenseClass = LicenseClass.COMMUNITY;
-    licenseType = null;
-    startDate = null;
-    endDate = null;
-    pendingTime = null;
-    limitedWsAccess = false;
-    limitNamedUsers = false;
-    outOfPlatform = false;
-    maxUsers = null;
+    reset();
 
     if (strPublicKey == null || activationKey == null || strPublicKey.equals("")
         || activationKey.equals("")) {
@@ -543,6 +520,31 @@
     checkDates();
   }
 
+  private void reset() {
+    isActive = false;
+    hasActivationKey = false;
+    errorMessage = "";
+    messageType = "Error";
+    instanceProperties = null;
+    hasExpired = false;
+    subscriptionConvertedProperty = false;
+    subscriptionActuallyConverted = false;
+    tier1Artifacts = null;
+    tier2Artifacts = null;
+    goldenExcludedArtifacts = null;
+    trial = false;
+    golden = false;
+    licenseClass = LicenseClass.COMMUNITY;
+    licenseType = null;
+    startDate = null;
+    endDate = null;
+    pendingTime = null;
+    limitedWsAccess = false;
+    limitNamedUsers = false;
+    outOfPlatform = false;
+    maxUsers = null;
+  }
+
   private boolean checkInOnDemandPlatform() {
     InputStream is = null;
     BufferedReader in = null;
@@ -1511,7 +1513,7 @@
         if (lastUpdateTimestamp == null
             || !lastUpdateTimestamp.equals(OBDal.getInstance()
                 .get(org.openbravo.model.ad.system.System.class, "0").getUpdated())) {
-          instance = ActivationKey.reload();
+          loadFromDB();
         }
       } catch (Exception e) {
         log.error("Error checking if activation key should be refreshed", e);
--- a/src/org/openbravo/materialmgmt/InventoryCountProcess.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/materialmgmt/InventoryCountProcess.java	Tue Nov 22 13:14:49 2016 +0100
@@ -80,7 +80,7 @@
 
   @Inject
   @Any
-  private Instance<InventoryCountCheckHook> inventoryCountProcesses;
+  private Instance<InventoryCountProcessHook> inventoryCountProcesses;
 
   @Override
   public void execute(ProcessBundle bundle) throws Exception {
--- a/src/org/openbravo/scheduling/OBScheduler.java	Wed Nov 16 15:20:19 2016 +0100
+++ b/src/org/openbravo/scheduling/OBScheduler.java	Tue Nov 22 13:14:49 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) 2008-2015 Openbravo SLU
+ * All portions are Copyright (C) 2008-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -52,7 +52,6 @@
  * 
  */
 public class OBScheduler {
-
   private static final OBScheduler INSTANCE = new OBScheduler();
 
   private static Logger log = LoggerFactory.getLogger(OBScheduler.class);
@@ -69,6 +68,9 @@
 
   public static String sqlDateTimeFormat;
 
+  private static final String BACKGROUND_POLICY = "background.policy";
+  private static final String NO_EXECUTE_POLICY = "no-execute";
+
   private OBScheduler() {
   }
 
@@ -182,9 +184,7 @@
    */
   public void schedule(String requestId, ProcessBundle bundle, Class<? extends Job> jobClass)
       throws SchedulerException, ServletException {
-    String policy = OBPropertiesProvider.getInstance().getOpenbravoProperties()
-        .getProperty("background.policy", "default");
-    if ("no-execute".equals(policy)) {
+    if (isNoExecuteBackgroundPolicy()) {
       log.info("Not scheduling process because current context background policy is 'no-execute'");
       return;
     }
@@ -204,6 +204,16 @@
   }
 
   /**
+   * Returns whether current node is set with no-execute background policy, which should prevent any
+   * process scheduling.
+   */
+  public static boolean isNoExecuteBackgroundPolicy() {
+    String policy = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty(BACKGROUND_POLICY, "default");
+    return NO_EXECUTE_POLICY.equals(policy);
+  }
+
+  /**
    * @param requestId
    * @param bundle
    * @throws SchedulerException