Fixes Issue 26641:Complete a G/L journal when using open items is not working
authorAtul Gaware <atul.gaware@openbravo.com>
Tue, 26 Aug 2014 00:50:27 +0530
changeset 24327 7ddaaea7ae8f
parent 24326 c020b50ce0fe
child 24328 de09123fc129
child 24329 edc2a785a7a3
Fixes Issue 26641:Complete a G/L journal when using open items is not working
if the role does not have access to document sequence
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java	Mon Aug 25 16:24:51 2014 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java	Tue Aug 26 00:50:27 2014 +0530
@@ -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) 2013 Openbravo SLU
+ * All portions are Copyright (C) 2013-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -54,7 +54,7 @@
     String strMessageType = "";
     StringBuilder strMessageResult = new StringBuilder();
     String strTitle = "";
-
+    OBContext.setAdminMode(true);
     try {
 
       // retrieve the parameters from the bundle
@@ -67,8 +67,8 @@
       BusinessPartner bPartner = journalLine.getBusinessPartner();
       GLItem glItem = journalLine.getGLItem();
       Date date = journalLine.getPaymentDate();
-      boolean isReceipt = journalLine.getDebit().subtract(journalLine.getCredit())
-          .compareTo(BigDecimal.ZERO) > 0;
+      boolean isReceipt = journalLine.getDebit().subtract(journalLine.getCredit()).compareTo(
+          BigDecimal.ZERO) > 0;
 
       // Check restrictions
       OBContext.setAdminMode(false);
@@ -111,18 +111,18 @@
           (isReceipt) ? "ARR" : "APP", (isReceipt) ? "AR Receipt" : "AP Payment");
 
       // Generate Payment
-      FIN_Payment payment = dao.getNewPayment(isReceipt, journalLine.getOrganization(),
-          dao.getObject(DocumentType.class, strDocTypeId), strPaymentDocumentNo, bPartner,
-          paymentMethod, financialAccount,
-          journalLine.getForeignCurrencyDebit().subtract(journalLine.getForeignCurrencyCredit())
-              .abs().toString(), date, null, journalLine.getCurrency(), null, null);
+      FIN_Payment payment = dao.getNewPayment(isReceipt, journalLine.getOrganization(), dao
+          .getObject(DocumentType.class, strDocTypeId), strPaymentDocumentNo, bPartner,
+          paymentMethod, financialAccount, journalLine.getForeignCurrencyDebit().subtract(
+              journalLine.getForeignCurrencyCredit()).abs().toString(), date, null, journalLine
+              .getCurrency(), null, null);
 
       // Add Payment Details
-      FIN_AddPayment.saveGLItem(payment,
-          journalLine.getForeignCurrencyDebit().subtract(journalLine.getForeignCurrencyCredit())
-              .abs(), glItem, bPartner, journalLine.getProduct(), journalLine.getProject(),
-          journalLine.getSalesCampaign(), journalLine.getActivity(), journalLine.getSalesRegion(),
-          journalLine.getCostCenter(), journalLine.getStDimension(), journalLine.getNdDimension());
+      FIN_AddPayment.saveGLItem(payment, journalLine.getForeignCurrencyDebit().subtract(
+          journalLine.getForeignCurrencyCredit()).abs(), glItem, bPartner,
+          journalLine.getProduct(), journalLine.getProject(), journalLine.getSalesCampaign(),
+          journalLine.getActivity(), journalLine.getSalesRegion(), journalLine.getCostCenter(),
+          journalLine.getStDimension(), journalLine.getNdDimension());
 
       OBDal.getInstance().flush();
 
@@ -144,10 +144,8 @@
         strMessageType = "Success";
       }
       strMessageResult.append("@Payment@ ").append(payment.getDocumentNo());
-      strMessageResult
-          .append(" (")
-          .append(
-              payment.getBusinessPartner() != null ? payment.getBusinessPartner().getName() : "")
+      strMessageResult.append(" (").append(
+          payment.getBusinessPartner() != null ? payment.getBusinessPartner().getName() : "")
           .append(")");
       if (!"".equals(message.getMessage()))
         strMessageResult.append(": ").append(message.getMessage());
@@ -170,6 +168,8 @@
       msg.setMessage(e.getMessage());
       msg.setTitle("@Error@");
       bundle.setResult(msg);
+    } finally {
+      OBContext.restorePreviousMode();
     }
 
   }