details:   https://code.openbravo.com/erp/devel/pi/rev/a7f8d171c573
changeset: 22334:a7f8d171c573
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Mon Mar 03 18:55:21 2014 +0100
summary:   Related to Issue 24405. Checks if needed to update in Modulescript.

diffstat:

 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateMTransactionCostingStatus.class
 |    0 
 
src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus.java
            |   27 +--
 
src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus_data.xsql
       |   75 ++++++++++
 src/org/openbravo/costing/CostingBackground.java                               
                      |    6 +-
 4 files changed, 90 insertions(+), 18 deletions(-)

diffs (165 lines):

diff -r 411bc9e9060e -r a7f8d171c573 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateMTransactionCostingStatus.class
Binary file 
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateMTransactionCostingStatus.class
 has changed
diff -r 411bc9e9060e -r a7f8d171c573 
src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus.java
--- 
a/src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus.java
 Mon Mar 03 16:37:13 2014 +0000
+++ 
b/src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus.java
 Mon Mar 03 18:55:21 2014 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2012 Openbravo SLU
+ * All portions are Copyright (C) 2012-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -21,30 +21,27 @@
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
+import org.apache.log4j.Logger;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.modulescript.ModuleScript;
 
 public class UpdateMTransactionCostingStatus extends ModuleScript {
+  
+  private static final Logger log4j = 
Logger.getLogger(UpdateMTransactionCostingStatus.class);
 
   public void execute() {
-    PreparedStatement ps = null;
     try {
       ConnectionProvider cp = getConnectionProvider();
-      ps = cp
-          .getPreparedStatement("UPDATE m_transaction SET costing_status = 
'CC' WHERE iscostcalculated = 'Y' AND costing_status = 'NC'");
-      ps.executeUpdate();
-      ps = cp.getPreparedStatement("UPDATE m_transaction SET isprocessed = 'Y' 
WHERE iscostcalculated = 'Y' AND isprocessed = 'N'");
-      ps.executeUpdate();
+      // If the preference does not exist in the database yet the modulescript 
must be executed.
+      boolean isUpdated = UpdateMTransactionCostingStatusData.isUpdated(cp);
+      log4j.error(isUpdated);
+      if (!isUpdated) {
+        UpdateMTransactionCostingStatusData.updateCostingStatus(cp);
+        UpdateMTransactionCostingStatusData.updateIsProcessed(cp);
+        UpdateMTransactionCostingStatusData.createPreference(cp);
+      }
     } catch (Exception e) {
       handleError(e);
-    } finally {
-      try {
-        if (!ps.isClosed()) {
-          ps.close();
-        }
-      } catch (Exception e) {
-        handleError(e);
-      }
     }
   }
 }
diff -r 411bc9e9060e -r a7f8d171c573 
src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus_data.xsql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-util/modulescript/src/org/openbravo/modulescript/UpdateMTransactionCostingStatus_data.xsql
    Mon Mar 03 18:55:21 2014 +0100
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+-->
+<SqlClass name="UpdateMTransactionCostingStatusData" 
package="org.openbravo.modulescript">
+  <SqlClassComment></SqlClassComment>
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT '' as exist FROM DUAL
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="isUpdated" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT count(*) as exist
+        FROM DUAL
+        WHERE EXISTS (SELECT 1 FROM ad_preference
+                      WHERE attribute = 'MTransaction_Costing_Status_Updated')
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="createPreference" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        INSERT INTO ad_preference (
+          ad_preference_id, ad_client_id, ad_org_id, isactive,
+          createdby, created, updatedby, updated,
+          attribute, value
+        ) VALUES (
+          get_uuid(), '0', '0', 'Y',
+          '0', NOW(), '0', NOW(),
+          'MTransaction_Costing_Status_Updated', 'Y'
+        )
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="updateCostingStatus" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+       UPDATE m_transaction 
+       SET costing_status = 'CC' WHERE iscostcalculated = 'Y' AND 
costing_status = 'NC'
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="updateIsProcessed" type="preparedStatement" 
return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+       UPDATE m_transaction 
+       SET isprocessed = 'Y' WHERE iscostcalculated = 'Y' AND isprocessed = 'N'
+      ]]>
+    </Sql>
+  </SqlMethod>
+</SqlClass>
diff -r 411bc9e9060e -r a7f8d171c573 
src/org/openbravo/costing/CostingBackground.java
--- a/src/org/openbravo/costing/CostingBackground.java  Mon Mar 03 16:37:13 
2014 +0000
+++ b/src/org/openbravo/costing/CostingBackground.java  Mon Mar 03 18:55:21 
2014 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2012 Openbravo SLU
+ * All portions are Copyright (C) 2012-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -85,7 +85,7 @@
       }
 
       // Fix the Not Processed flag for those Transactions with Cost Not 
Calculated
-      SetNotProcessedWhenNotCalculatedTransactions(orgsWithRule);
+      setNotProcessedWhenNotCalculatedTransactions(orgsWithRule);
 
       List<MaterialTransaction> trxs = getTransactionsBatch(orgsWithRule);
       int counter = 0, total = trxs.size(), batch = 0;
@@ -140,7 +140,7 @@
     }
   }
 
-  private void SetNotProcessedWhenNotCalculatedTransactions(List<String> 
orgsWithRule) {
+  private void setNotProcessedWhenNotCalculatedTransactions(List<String> 
orgsWithRule) {
     ScrollableResults trxs = getTransactionsNotCalculated(orgsWithRule);
     while (trxs.next()) {
       MaterialTransaction transaction = (MaterialTransaction) trxs.get(0);

------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to