[APRM] Add delete transaction process.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Fri, 08 Apr 2011 15:27:25 +0200
changeset 11689 f24340e06977
parent 11688 191550a29ca9
child 11690 c3bbfe470578
[APRM] Add delete transaction process.
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_COLUMN.xml
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_PROCESS.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/DeleteTransaction.java
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_COLUMN.xml	Fri Apr 08 15:26:54 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_COLUMN.xml	Fri Apr 08 15:27:25 2011 +0200
@@ -2773,6 +2773,7 @@
 <!--A028C06E679F6F62E040007F01007206-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--A028C06E679F6F62E040007F01007206-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
 <!--A028C06E679F6F62E040007F01007206-->  <AD_ELEMENT_ID><![CDATA[A0417A0E924ACA28E040007F01003C18]]></AD_ELEMENT_ID>
+<!--A028C06E679F6F62E040007F01007206-->  <AD_PROCESS_ID><![CDATA[FF8080812F348A97012F349DC24F0007]]></AD_PROCESS_ID>
 <!--A028C06E679F6F62E040007F01007206-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
 <!--A028C06E679F6F62E040007F01007206-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
 <!--A028C06E679F6F62E040007F01007206-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODEL_OBJECT.xml	Fri Apr 08 15:26:54 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODEL_OBJECT.xml	Fri Apr 08 15:27:25 2011 +0200
@@ -228,4 +228,16 @@
 <!--FF8080812E437710012E43BE26A3000E-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
 <!--FF8080812E437710012E43BE26A3000E--></AD_MODEL_OBJECT>
 
+<!--FF8080812F348A97012F349E7610000A--><AD_MODEL_OBJECT>
+<!--FF8080812F348A97012F349E7610000A-->  <AD_MODEL_OBJECT_ID><![CDATA[FF8080812F348A97012F349E7610000A]]></AD_MODEL_OBJECT_ID>
+<!--FF8080812F348A97012F349E7610000A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8080812F348A97012F349E7610000A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8080812F348A97012F349E7610000A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8080812F348A97012F349E7610000A-->  <ACTION><![CDATA[P]]></ACTION>
+<!--FF8080812F348A97012F349E7610000A-->  <CLASSNAME><![CDATA[org.openbravo.advpaymentmngt.ad_actionbutton.DeleteTransaction]]></CLASSNAME>
+<!--FF8080812F348A97012F349E7610000A-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--FF8080812F348A97012F349E7610000A-->  <AD_PROCESS_ID><![CDATA[FF8080812F348A97012F349DC24F0007]]></AD_PROCESS_ID>
+<!--FF8080812F348A97012F349E7610000A-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
+<!--FF8080812F348A97012F349E7610000A--></AD_MODEL_OBJECT>
+
 </data>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_PROCESS.xml	Fri Apr 08 15:26:54 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_PROCESS.xml	Fri Apr 08 15:27:25 2011 +0200
@@ -357,4 +357,22 @@
 <!--FF8080812E2F8EAE012E2F94CF470014-->  <UIPATTERN><![CDATA[S]]></UIPATTERN>
 <!--FF8080812E2F8EAE012E2F94CF470014--></AD_PROCESS>
 
+<!--FF8080812F348A97012F349DC24F0007--><AD_PROCESS>
+<!--FF8080812F348A97012F349DC24F0007-->  <AD_PROCESS_ID><![CDATA[FF8080812F348A97012F349DC24F0007]]></AD_PROCESS_ID>
+<!--FF8080812F348A97012F349DC24F0007-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8080812F348A97012F349DC24F0007-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8080812F348A97012F349DC24F0007-->  <VALUE><![CDATA[FIN_DeleteTransaction]]></VALUE>
+<!--FF8080812F348A97012F349DC24F0007-->  <NAME><![CDATA[Delete]]></NAME>
+<!--FF8080812F348A97012F349DC24F0007-->  <ACCESSLEVEL><![CDATA[3]]></ACCESSLEVEL>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISUSERSTARTABLE><![CDATA[N]]></ISUSERSTARTABLE>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISREPORT><![CDATA[N]]></ISREPORT>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISDIRECTPRINT><![CDATA[N]]></ISDIRECTPRINT>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISBACKGROUND><![CDATA[N]]></ISBACKGROUND>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISJASPER><![CDATA[N]]></ISJASPER>
+<!--FF8080812F348A97012F349DC24F0007-->  <ISEXTERNALSERVICE><![CDATA[N]]></ISEXTERNALSERVICE>
+<!--FF8080812F348A97012F349DC24F0007-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--FF8080812F348A97012F349DC24F0007-->  <UIPATTERN><![CDATA[S]]></UIPATTERN>
+<!--FF8080812F348A97012F349DC24F0007--></AD_PROCESS>
+
 </data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/DeleteTransaction.java	Fri Apr 08 15:27:25 2011 +0200
@@ -0,0 +1,90 @@
+/*
+ *************************************************************************
+ * 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):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.advpaymentmngt.ad_actionbutton;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openbravo.advpaymentmngt.process.FIN_TransactionProcess;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
+import org.openbravo.scheduling.Process;
+import org.openbravo.scheduling.ProcessBundle;
+
+public class DeleteTransaction implements Process {
+
+  @Override
+  public void execute(ProcessBundle bundle) throws Exception {
+
+    VariablesSecureApp vars = bundle.getContext().toVars();
+    Map<String, Object> params = bundle.getParams();
+
+    String strKey = (String) params.get("Fin_Finacc_Transaction_ID");
+    FIN_FinaccTransaction transaction = OBDal.getInstance()
+        .get(FIN_FinaccTransaction.class, strKey);
+    try {
+      OBError msg = processTransaction(vars, bundle.getConnection(), "R", transaction);
+      if ("Success".equals(msg.getType())) {
+        OBContext.setAdminMode();
+        try {
+          OBDal.getInstance().remove(transaction);
+          OBDal.getInstance().flush();
+        } finally {
+          OBContext.restorePreviousMode();
+        }
+      }
+      bundle.setResult(msg);
+    } catch (Exception e) {
+      throw new OBException("Process failed deleting the financial account Transaction", e);
+    }
+  }
+
+  /**
+   * It calls the Transaction Process for the given transaction and action.
+   * 
+   * @param vars
+   *          VariablesSecureApp with the session data.
+   * @param conn
+   *          ConnectionProvider with the connection being used.
+   * @param strAction
+   *          String with the action of the process. {P, D, R}
+   * @param transaction
+   *          FIN_FinaccTransaction that needs to be processed.
+   * @return a OBError with the result message of the process.
+   * @throws Exception
+   */
+  private OBError processTransaction(VariablesSecureApp vars, ConnectionProvider conn,
+      String strAction, FIN_FinaccTransaction transaction) throws Exception {
+    ProcessBundle pb = new ProcessBundle("F68F2890E96D4D85A1DEF0274D105BCE", vars).init(conn);
+    HashMap<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put("action", strAction);
+    parameters.put("Fin_FinAcc_Transaction_ID", transaction.getId());
+    pb.setParams(parameters);
+    OBError myMessage = null;
+    new FIN_TransactionProcess().execute(pb);
+    myMessage = (OBError) pb.getResult();
+    return myMessage;
+  }
+
+}