Related to Issue 30332: Do not take into account Transactions in Skip Status.
authorDavid Miguelez <david.miguelez@openbravo.com>
Fri, 17 Jul 2015 15:04:27 +0200
changeset 27086 06c15f9276a7
parent 27085 bbfccafd18ed
child 27087 6273bf287bb7
Related to Issue 30332: Do not take into account Transactions in Skip Status.
Remove them from the queries.
In Costing Server, set all Transactions as isProcessed=Y when they go through
doProcess() method.
src/org/openbravo/costing/CostingBackground.java
src/org/openbravo/costing/CostingServer.java
--- a/src/org/openbravo/costing/CostingBackground.java	Wed Jul 15 17:49:30 2015 +0200
+++ b/src/org/openbravo/costing/CostingBackground.java	Fri Jul 17 15:04:27 2015 +0200
@@ -110,10 +110,6 @@
           counter++;
           MaterialTransaction transaction = OBDal.getInstance().get(MaterialTransaction.class,
               trxId);
-          if ("S".equals(transaction.getCostingStatus())) {
-            // Do not calculate trx in skip status.
-            continue;
-          }
           log4j.debug("Start transaction process: " + transaction.getId());
           CostingServer transactionCost = new CostingServer(transaction);
           transactionCost.process();
@@ -168,6 +164,7 @@
     hqlTransactions.append(" where trx." + MaterialTransaction.PROPERTY_ISPROCESSED + " = true");
     hqlTransactions.append("   and trx." + MaterialTransaction.PROPERTY_ISCOSTCALCULATED
         + " = false");
+    hqlTransactions.append("   and trx." + MaterialTransaction.PROPERTY_COSTINGSTATUS + " <> 'S'");
     hqlTransactions.append("   and trx." + MaterialTransaction.PROPERTY_ORGANIZATION
         + ".id in (:orgs)");
     Query updateTransactions = OBDal.getInstance().getSession()
@@ -186,6 +183,7 @@
     where.append(" join trx." + MaterialTransaction.PROPERTY_PRODUCT + " as p");
     where.append("\n , " + org.openbravo.model.ad.domain.List.ENTITY_NAME + " as trxtype");
     where.append("\n where trx." + MaterialTransaction.PROPERTY_ISPROCESSED + " = false");
+    where.append("   and trx." + MaterialTransaction.PROPERTY_COSTINGSTATUS + " <> 'S'");
     where.append("   and p." + Product.PROPERTY_PRODUCTTYPE + " = 'I'");
     where.append("   and p." + Product.PROPERTY_STOCKED + " = true");
     where.append("   and trxtype." + CostAdjustmentUtils.propADListReference + ".id = :refid");
@@ -220,6 +218,7 @@
     where.append(" join trx." + MaterialTransaction.PROPERTY_PRODUCT + " as p");
     where.append("\n , " + org.openbravo.model.ad.domain.List.ENTITY_NAME + " as trxtype");
     where.append("\n where trx." + MaterialTransaction.PROPERTY_ISPROCESSED + " = false");
+    where.append("   and trx." + MaterialTransaction.PROPERTY_COSTINGSTATUS + " <> 'S'");
     where.append("   and p." + Product.PROPERTY_PRODUCTTYPE + " = 'I'");
     where.append("   and p." + Product.PROPERTY_STOCKED + " = true");
     where.append("   and trxtype." + CostAdjustmentUtils.propADListReference + ".id = :refid");
@@ -246,10 +245,6 @@
         }
         MaterialTransaction transaction = OBDal.getInstance().get(MaterialTransaction.class, trxId);
         counter++;
-        if ("S".equals(transaction.getCostingStatus())) {
-          // Do not calculate trx in skip status.
-          continue;
-        }
         CostingServer transactionCost = new CostingServer(transaction);
         transactionCost.process();
       }
--- a/src/org/openbravo/costing/CostingServer.java	Wed Jul 15 17:49:30 2015 +0200
+++ b/src/org/openbravo/costing/CostingServer.java	Fri Jul 17 15:04:27 2015 +0200
@@ -89,48 +89,51 @@
    * 
    */
   public void process() {
-    if (trxCost != null) {
-      // Transaction cost has already been calculated. Nothing to do.
-      return;
-    }
-    log4j.debug("Process cost");
     try {
-      OBContext.setAdminMode(false);
-      // Get needed algorithm. And set it in the M_Transaction.
-      CostingAlgorithm costingAlgorithm = getCostingAlgorithm();
-      costingAlgorithm.init(this);
-      log4j.debug("  *** Algorithm initializated: " + costingAlgorithm.getClass());
-
-      trxCost = costingAlgorithm.getTransactionCost();
-      if (trxCost == null && !transaction.getCostingStatus().equals("P")) {
-        throw new OBException("@NoCostCalculated@: " + transaction.getIdentifier());
-      }
-      if (transaction.getCostingStatus().equals("P")) {
-        transaction.setProcessed(true);
-        OBDal.getInstance().flush();
+      if (trxCost != null) {
+        // Transaction cost has already been calculated. Nothing to do.
         return;
       }
+      log4j.debug("Process cost");
+      try {
+        OBContext.setAdminMode(false);
+        // Get needed algorithm. And set it in the M_Transaction.
+        CostingAlgorithm costingAlgorithm = getCostingAlgorithm();
+        costingAlgorithm.init(this);
+        log4j.debug("  *** Algorithm initializated: " + costingAlgorithm.getClass());
 
-      trxCost = trxCost.setScale(costingAlgorithm.getCostCurrency().getStandardPrecision()
-          .intValue(), RoundingMode.HALF_UP);
-      log4j.debug("  *** Transaction cost amount: " + trxCost.toString());
-      // Save calculated cost on M_Transaction.
-      transaction.setTransactionCost(trxCost);
-      transaction.setCurrency(currency);
-      transaction.setCostCalculated(true);
-      transaction.setCostingStatus("CC");
-      // insert on m_transaction_cost
-      createTransactionCost();
+        trxCost = costingAlgorithm.getTransactionCost();
+        if (trxCost == null && !transaction.getCostingStatus().equals("P")) {
+          throw new OBException("@NoCostCalculated@: " + transaction.getIdentifier());
+        }
+        if (transaction.getCostingStatus().equals("P")) {
+          return;
+        }
+
+        trxCost = trxCost.setScale(costingAlgorithm.getCostCurrency().getStandardPrecision()
+            .intValue(), RoundingMode.HALF_UP);
+        log4j.debug("  *** Transaction cost amount: " + trxCost.toString());
+        // Save calculated cost on M_Transaction.
+        transaction.setTransactionCost(trxCost);
+        transaction.setCurrency(currency);
+        transaction.setCostCalculated(true);
+        transaction.setCostingStatus("CC");
+        // insert on m_transaction_cost
+        createTransactionCost();
+        OBDal.getInstance().save(transaction);
+        OBDal.getInstance().flush();
+
+        setNotPostedTransaction();
+        checkCostAdjustments();
+      } finally {
+        OBContext.restorePreviousMode();
+      }
+      return;
+    } finally {
+      // Every Transaction must be set as Processed = 'Y' after going through this method
       transaction.setProcessed(true);
-      OBDal.getInstance().save(transaction);
       OBDal.getInstance().flush();
-
-      setNotPostedTransaction();
-      checkCostAdjustments();
-    } finally {
-      OBContext.restorePreviousMode();
     }
-    return;
   }
 
   private void checkCostAdjustments() {