[costadj] Add preference to avoid adjustments for some transactions
authorMiguel de Juana <miguel.dejuana@openbravo.com>
Tue, 19 Aug 2014 13:44:54 +0200
changeset 24797 3ff6ee8e56ba
parent 24796 9c709be3d4b6
child 24798 063f42a98de1
[costadj] Add preference to avoid adjustments for some transactions
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 19 13:43:29 2014 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Aug 19 13:44:54 2014 +0200
@@ -9588,6 +9588,17 @@
 <!--62AF6586FB94470DBD7C5D90430D8BC3-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--62AF6586FB94470DBD7C5D90430D8BC3--></AD_REF_LIST>
 
+<!--6336EEE0A73E4C199F2222180BAF266C--><AD_REF_LIST>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <AD_REF_LIST_ID><![CDATA[6336EEE0A73E4C199F2222180BAF266C]]></AD_REF_LIST_ID>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <VALUE><![CDATA[doNotCheckPriceCorrectionTrxs]]></VALUE>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <NAME><![CDATA[Do not Check Price Correction Transactions]]></NAME>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--6336EEE0A73E4C199F2222180BAF266C-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--6336EEE0A73E4C199F2222180BAF266C--></AD_REF_LIST>
+
 <!--63E3424F43124AE0BE5F479D9D9CA049--><AD_REF_LIST>
 <!--63E3424F43124AE0BE5F479D9D9CA049-->  <AD_REF_LIST_ID><![CDATA[63E3424F43124AE0BE5F479D9D9CA049]]></AD_REF_LIST_ID>
 <!--63E3424F43124AE0BE5F479D9D9CA049-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -10569,6 +10580,17 @@
 <!--93CDB0B07AC64DB7B0C92CB3C173C1D5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--93CDB0B07AC64DB7B0C92CB3C173C1D5--></AD_REF_LIST>
 
+<!--94016AB72D574413A0267D0B848EB120--><AD_REF_LIST>
+<!--94016AB72D574413A0267D0B848EB120-->  <AD_REF_LIST_ID><![CDATA[94016AB72D574413A0267D0B848EB120]]></AD_REF_LIST_ID>
+<!--94016AB72D574413A0267D0B848EB120-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--94016AB72D574413A0267D0B848EB120-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--94016AB72D574413A0267D0B848EB120-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--94016AB72D574413A0267D0B848EB120-->  <VALUE><![CDATA[doNotCheckBackDatedTrxs]]></VALUE>
+<!--94016AB72D574413A0267D0B848EB120-->  <NAME><![CDATA[Do Not Check BackDated Transactions]]></NAME>
+<!--94016AB72D574413A0267D0B848EB120-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--94016AB72D574413A0267D0B848EB120-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--94016AB72D574413A0267D0B848EB120--></AD_REF_LIST>
+
 <!--940939F3D7DA422A8FBD46D5B477F716--><AD_REF_LIST>
 <!--940939F3D7DA422A8FBD46D5B477F716-->  <AD_REF_LIST_ID><![CDATA[940939F3D7DA422A8FBD46D5B477F716]]></AD_REF_LIST_ID>
 <!--940939F3D7DA422A8FBD46D5B477F716-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/costing/CostingServer.java	Tue Aug 19 13:43:29 2014 +0200
+++ b/src/org/openbravo/costing/CostingServer.java	Tue Aug 19 13:44:54 2014 +0200
@@ -32,8 +32,10 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.materialmgmt.cost.CostAdjustment;
@@ -75,6 +77,8 @@
    * 
    */
   public void process() throws OBException {
+    boolean doNotCheckPriceCorrectionTrxs = false;
+    boolean doNotCheckBackDatedTrxs = false;
     if (trxCost != null) {
       // Transaction cost has already been calculated. Nothing to do.
       return;
@@ -108,7 +112,15 @@
       OBDal.getInstance().save(transaction);
 
       // check if price correction is needed
-      if (transaction.getGoodsShipmentLine() != null
+      try {
+        doNotCheckPriceCorrectionTrxs = Preferences.getPreferenceValue(
+            "doNotCheckPriceCorrectionTrxs", true, OBContext.getOBContext().getCurrentClient(),
+            OBContext.getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(),
+            OBContext.getOBContext().getRole(), null).equals("Y");
+      } catch (PropertyException e1) {
+        doNotCheckPriceCorrectionTrxs = false;
+      }
+      if (!doNotCheckPriceCorrectionTrxs && transaction.getGoodsShipmentLine() != null
           && transaction.getGoodsShipmentLine().getProcurementReceiptInvoiceMatchList() != null
           && transaction.getGoodsShipmentLine().getProcurementReceiptInvoiceMatchList().size() != 0) {
         try {
@@ -120,8 +132,17 @@
       }
 
       // check if cost adjustment should be done
-      if (CostAdjustmentUtils.isNeededCostAdjustmentByBackDateTrx(transaction, getCostingRule()
-          .isWarehouseDimension())) {
+      try {
+        doNotCheckBackDatedTrxs = Preferences.getPreferenceValue("doNotCheckBackDatedTrxs", true,
+            OBContext.getOBContext().getCurrentClient(),
+            OBContext.getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(),
+            OBContext.getOBContext().getRole(), null).equals("Y");
+      } catch (PropertyException e1) {
+        doNotCheckBackDatedTrxs = false;
+      }
+      if (!doNotCheckBackDatedTrxs
+          && CostAdjustmentUtils.isNeededCostAdjustmentByBackDateTrx(transaction, getCostingRule()
+              .isWarehouseDimension())) {
 
         CostAdjustment costAdjustmentHeader = CostAdjustmentUtils.insertCostAdjustmentHeader(
             transaction.getOrganization(), "BDT"); // BDT= Backdated transaction