Fixes issue 30315: BackPort from issue 30333.
authorDavid Miguelez <david.miguelez@openbravo.com>
Thu, 16 Jul 2015 11:26:34 +0200
changeset 27082 d486b2997ee5
parent 27081 613b06e82db5
child 27083 31aa70ff60d9
Fixes issue 30315: BackPort from issue 30333.
src/org/openbravo/costing/CostingBackground.java
src/org/openbravo/costing/CostingServer.java
--- a/src/org/openbravo/costing/CostingBackground.java	Fri Jul 10 13:19:36 2015 +0200
+++ b/src/org/openbravo/costing/CostingBackground.java	Thu Jul 16 11:26:34 2015 +0200
@@ -112,7 +112,6 @@
               trxId);
           if ("S".equals(transaction.getCostingStatus())) {
             // Do not calculate trx in skip status.
-            transaction.setProcessed(true);
             continue;
           }
           log4j.debug("Start transaction process: " + transaction.getId());
@@ -154,10 +153,6 @@
       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();
     }
   }
@@ -183,27 +178,6 @@
     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();
@@ -212,7 +186,6 @@
     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");
@@ -247,7 +220,6 @@
     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	Fri Jul 10 13:19:36 2015 +0200
+++ b/src/org/openbravo/costing/CostingServer.java	Thu Jul 16 11:26:34 2015 +0200
@@ -106,6 +106,8 @@
         throw new OBException("@NoCostCalculated@: " + transaction.getIdentifier());
       }
       if (transaction.getCostingStatus().equals("P")) {
+        transaction.setProcessed(true);
+        OBDal.getInstance().flush();
         return;
       }
 
@@ -119,6 +121,7 @@
       transaction.setCostingStatus("CC");
       // insert on m_transaction_cost
       createTransactionCost();
+      transaction.setProcessed(true);
       OBDal.getInstance().save(transaction);
       OBDal.getInstance().flush();