Backed out changeset d486b2997ee5
authorDavid Miguelez <david.miguelez@openbravo.com>
Thu, 16 Jul 2015 11:27:31 +0200
changeset 27083 31aa70ff60d9
parent 27082 d486b2997ee5
child 27084 fbe4acffc34a
Backed out changeset d486b2997ee5
src/org/openbravo/costing/CostingBackground.java
src/org/openbravo/costing/CostingServer.java
--- a/src/org/openbravo/costing/CostingBackground.java	Thu Jul 16 11:26:34 2015 +0200
+++ b/src/org/openbravo/costing/CostingBackground.java	Thu Jul 16 11:27:31 2015 +0200
@@ -112,6 +112,7 @@
               trxId);
           if ("S".equals(transaction.getCostingStatus())) {
             // Do not calculate trx in skip status.
+            transaction.setProcessed(true);
             continue;
           }
           log4j.debug("Start transaction process: " + transaction.getId());
@@ -153,6 +154,10 @@
       bundle.setResult(result);
       return;
     } finally {
+      // Set the processed flag to true to those transactions whose cost has been calculated.
+      if (!orgsWithRule.isEmpty()) {
+        setCalculatedTransactionsAsProcessed(orgsWithRule);
+      }
       OBContext.restorePreviousMode();
     }
   }
@@ -178,6 +183,27 @@
     OBDal.getInstance().flush();
   }
 
+  /**
+   * Get Transactions with Processed flag = 'N' and it's cost is Calculated and set Processed flag =
+   * 'Y'
+   */
+  private void setCalculatedTransactionsAsProcessed(List<String> orgsWithRule) {
+    final StringBuilder hqlTransactions = new StringBuilder();
+    hqlTransactions.append(" update " + MaterialTransaction.ENTITY_NAME + " as trx set trx."
+        + MaterialTransaction.PROPERTY_ISPROCESSED + " = true ");
+    hqlTransactions.append(" where trx." + MaterialTransaction.PROPERTY_ISPROCESSED + " = false");
+    hqlTransactions.append("   and trx." + MaterialTransaction.PROPERTY_ISCOSTCALCULATED
+        + " = true");
+    hqlTransactions.append("   and trx." + MaterialTransaction.PROPERTY_ORGANIZATION
+        + ".id in (:orgs)");
+    Query updateTransactions = OBDal.getInstance().getSession()
+        .createQuery(hqlTransactions.toString());
+    updateTransactions.setParameterList("orgs", orgsWithRule);
+    updateTransactions.executeUpdate();
+
+    OBDal.getInstance().flush();
+  }
+
   @SuppressWarnings("unchecked")
   private List<String> getTransactionsBatch(List<String> orgsWithRule) {
     StringBuffer where = new StringBuffer();
@@ -186,6 +212,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 +247,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");
--- a/src/org/openbravo/costing/CostingServer.java	Thu Jul 16 11:26:34 2015 +0200
+++ b/src/org/openbravo/costing/CostingServer.java	Thu Jul 16 11:27:31 2015 +0200
@@ -106,8 +106,6 @@
         throw new OBException("@NoCostCalculated@: " + transaction.getIdentifier());
       }
       if (transaction.getCostingStatus().equals("P")) {
-        transaction.setProcessed(true);
-        OBDal.getInstance().flush();
         return;
       }
 
@@ -121,7 +119,6 @@
       transaction.setCostingStatus("CC");
       // insert on m_transaction_cost
       createTransactionCost();
-      transaction.setProcessed(true);
       OBDal.getInstance().save(transaction);
       OBDal.getInstance().flush();