[costAdj] Added preference to Negative Stock Correction
authorMiguel A. Alsasua <miguel.alsasua@openbravo.com>
Wed, 27 Aug 2014 08:38:36 +0200
changeset 24822 f08c52d2d396
parent 24821 2e15f45c46c0
child 24823 1cbd4f408438
[costAdj] Added preference to Negative Stock Correction
src-db/database/sourcedata/AD_REF_LIST.xml
src/org/openbravo/costing/CostingServer.java
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Aug 26 15:08:12 2014 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Wed Aug 27 08:38:36 2014 +0200
@@ -9268,6 +9268,17 @@
 <!--4DF20C1FA37C42648A73FB9107831DA4-->  <SEQNO><![CDATA[10]]></SEQNO>
 <!--4DF20C1FA37C42648A73FB9107831DA4--></AD_REF_LIST>
 
+<!--4E0A4D67A83E4A1BBF194BF0006A089C--><AD_REF_LIST>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <AD_REF_LIST_ID><![CDATA[4E0A4D67A83E4A1BBF194BF0006A089C]]></AD_REF_LIST_ID>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <VALUE><![CDATA[doNotCheckNegativeStockCorrecctionTrxs]]></VALUE>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <NAME><![CDATA[Do Not Check Negative Stock Correction Transactions]]></NAME>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--4E0A4D67A83E4A1BBF194BF0006A089C--></AD_REF_LIST>
+
 <!--4E785CCAD3344BF5A0DCE242F5D7A1BC--><AD_REF_LIST>
 <!--4E785CCAD3344BF5A0DCE242F5D7A1BC-->  <AD_REF_LIST_ID><![CDATA[4E785CCAD3344BF5A0DCE242F5D7A1BC]]></AD_REF_LIST_ID>
 <!--4E785CCAD3344BF5A0DCE242F5D7A1BC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/costing/CostingServer.java	Tue Aug 26 15:08:12 2014 +0200
+++ b/src/org/openbravo/costing/CostingServer.java	Wed Aug 27 08:38:36 2014 +0200
@@ -133,6 +133,7 @@
   private void checkCostAdjustments() {
     boolean doNotCheckPriceCorrectionTrxs = false;
     boolean doNotCheckBackDatedTrxs = false;
+    boolean doNotCheckNegativeStockCorrectionTrxs = false;
     // check if price correction is needed
     try {
       doNotCheckPriceCorrectionTrxs = Preferences.getPreferenceValue(
@@ -255,12 +256,22 @@
     }
 
     // check if negative stock correction should be done
+    try {
+      doNotCheckBackDatedTrxs = Preferences.getPreferenceValue(
+          "doNotCheckNegativeStockCorrecctionTrxs", true,
+          OBContext.getOBContext().getCurrentClient(),
+          OBContext.getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(),
+          OBContext.getOBContext().getRole(), null).equals("Y");
+    } catch (PropertyException e1) {
+      doNotCheckNegativeStockCorrectionTrxs = false;
+    }
 
     boolean modifiesAvg = AverageAlgorithm.modifiesAverage(TrxType.getTrxType(transaction));
     BigDecimal currentStock = CostingUtils.getCurrentStock(getOrganization(), transaction,
         getCostingAlgorithm().costDimensions, transaction.getProduct().isProduction());
     // the stock preivous to transaction was negative
-    if (currentStock.compareTo(transaction.getMovementQuantity()) < 0 && modifiesAvg) {
+    if (!doNotCheckNegativeStockCorrectionTrxs
+        && currentStock.compareTo(transaction.getMovementQuantity()) < 0 && modifiesAvg) {
 
       CostAdjustment costAdjustmentHeader = CostAdjustmentUtils.insertCostAdjustmentHeader(
           transaction.getOrganization(), "NSC"); // NSC= Negative Stock Correction