fixes issue 22089: Modulescript needed to correct the fact_acct records
authorCarlos Aristu <carlos.aristu@openbravo.com>
Mon, 26 Nov 2012 11:32:51 +0100
changeset 18619 f7c14ec8bc1a
parent 18618 c39b85fd3075
child 18620 1734e920ff4c
fixes issue 22089: Modulescript needed to correct the fact_acct records
with acctdescription different from the associated element value name
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateFactAcctDescription.class
src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateFactAcctDescriptionData.class
src-util/modulescript/src/org/openbravo/modulescript/UpdateFactAcctDescription.java
src-util/modulescript/src/org/openbravo/modulescript/UpdateFactAcctDescription_data.xsql
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateFactAcctDescription.class has changed
Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/UpdateFactAcctDescriptionData.class has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdateFactAcctDescription.java	Mon Nov 26 11:32:51 2012 +0100
@@ -0,0 +1,37 @@
+/*
+ *************************************************************************
+ * 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) 2012 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.modulescript;
+
+import java.sql.PreparedStatement;
+
+import org.openbravo.modulescript.ModuleScript;
+import org.openbravo.database.ConnectionProvider;
+
+public class UpdateFactAcctDescription extends ModuleScript{
+  @Override
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      if(UpdateFactAcctDescriptionData.needsUpdate(cp))
+        UpdateFactAcctDescriptionData.updateFactAcctDescription(cp);
+    } catch(Exception e){
+      handleError(e);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/modulescript/src/org/openbravo/modulescript/UpdateFactAcctDescription_data.xsql	Mon Nov 26 11:32:51 2012 +0100
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (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) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+-->
+<SqlClass name="UpdateFactAcctDescriptionData" package="org.openbravo.modulescript">
+   <SqlClassComment></SqlClassComment>
+   <SqlMethod name="needsUpdate" type="preparedStatement" return="boolean">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+         SELECT count(1) as total
+         FROM fact_acct fa LEFT JOIN c_elementvalue ev ON fa.account_id = ev.c_elementvalue_id
+         WHERE (fa.acctdescription is null
+                OR (fa.acctdescription is not null and fa.acctdescription <> ev.name))
+      ]]>
+    </Sql>
+  </SqlMethod>
+  <SqlMethod name="updateFactAcctDescription" type="preparedStatement" return="rowcount">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        UPDATE fact_acct
+        SET acctdescription = (select name from c_elementvalue where c_elementvalue_id = account_id)
+        WHERE fact_acct_id IN
+              (SELECT fact_acct_id
+               FROM fact_acct fa LEFT JOIN c_elementvalue ev ON fa.account_id = ev.c_elementvalue_id
+               WHERE (fa.acctdescription is null
+               OR (fa.acctdescription is not null and fa.acctdescription <> ev.name)))
+      ]]>
+    </Sql>
+  </SqlMethod>
+</SqlClass>
\ No newline at end of file