Fixes Issue 22782: Business Partner should not be mandatory in G/L Journal line
authorPandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
Thu, 17 Jan 2013 14:18:36 +0530
changeset 19403 36dbe385905f
parent 19402 a71939e3dcc8
child 19404 cf2de0fafe31
Fixes Issue 22782: Business Partner should not be mandatory in G/L Journal line
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
src-db/database/sourcedata/AD_MESSAGE.xml
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java	Thu Jan 17 14:15:41 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java	Thu Jan 17 14:18:36 2013 +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) 2012 Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -130,7 +130,8 @@
 
       // Print result
       if (message.getType().equals("Error")) {
-        String exceptionMessage = payment.getBusinessPartner().getName();
+        String exceptionMessage = payment.getBusinessPartner() != null ? payment
+            .getBusinessPartner().getName() : "";
         exceptionMessage += ": " + message.getMessage();
         throw new OBException(exceptionMessage);
       } else if (message.getType().equals("Warning")) {
@@ -141,7 +142,11 @@
         strMessageType = "Success";
       }
       strMessageResult.append("@Payment@ ").append(payment.getDocumentNo());
-      strMessageResult.append(" (").append(payment.getBusinessPartner().getName()).append(")");
+      strMessageResult
+          .append(" (")
+          .append(
+              payment.getBusinessPartner() != null ? payment.getBusinessPartner().getName() : "")
+          .append(")");
       if (!"".equals(message.getMessage()))
         strMessageResult.append(": ").append(message.getMessage());
       strMessageResult.append("<br>");
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Jan 17 14:15:41 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Jan 17 14:18:36 2013 +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) 2010-2012 Openbravo SLU
+ * All portions are Copyright (C) 2010-2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -96,27 +96,36 @@
             return;
           }
         } else {
-          for (FIN_PaymentDetail pd : payment.getFINPaymentDetailList()) {
-            for (FIN_PaymentScheduleDetail psd : pd.getFINPaymentScheduleDetailList()) {
-              BusinessPartner bPartner;
-              if (psd.getInvoicePaymentSchedule() == null) {
-                bPartner = psd.getOrderPaymentSchedule().getOrder().getBusinessPartner();
-              } else {
-                bPartner = psd.getInvoicePaymentSchedule().getInvoice().getBusinessPartner();
-              }
-              if (FIN_Utility.isBlockedBusinessPartner(bPartner.getId(), payment.isReceipt(), 4)) {
-                // If the Business Partner is blocked for Payments, the Payment will not be
-                // completed.
-                msg.setType("Error");
-                msg.setTitle(Utility.messageBD(conProvider, "Error", language));
-                msg.setMessage(OBMessageUtils.messageBD("ThebusinessPartner") + " "
-                    + bPartner.getIdentifier() + " "
-                    + OBMessageUtils.messageBD("BusinessPartnerBlocked"));
-                bundle.setResult(msg);
-                OBDal.getInstance().rollbackAndClose();
-                return;
+          OBContext.setAdminMode();
+          try {
+            for (FIN_PaymentDetail pd : payment.getFINPaymentDetailList()) {
+              for (FIN_PaymentScheduleDetail psd : pd.getFINPaymentScheduleDetailList()) {
+                BusinessPartner bPartner;
+                if (psd.getInvoicePaymentSchedule() != null
+                    || psd.getOrderPaymentSchedule() != null) {
+                  if (psd.getInvoicePaymentSchedule() == null) {
+                    bPartner = psd.getOrderPaymentSchedule().getOrder().getBusinessPartner();
+                  } else {
+                    bPartner = psd.getInvoicePaymentSchedule().getInvoice().getBusinessPartner();
+                  }
+                  if (FIN_Utility
+                      .isBlockedBusinessPartner(bPartner.getId(), payment.isReceipt(), 4)) {
+                    // If the Business Partner is blocked for Payments, the Payment will not be
+                    // completed.
+                    msg.setType("Error");
+                    msg.setTitle(Utility.messageBD(conProvider, "Error", language));
+                    msg.setMessage(OBMessageUtils.messageBD("ThebusinessPartner") + " "
+                        + bPartner.getIdentifier() + " "
+                        + OBMessageUtils.messageBD("BusinessPartnerBlocked"));
+                    bundle.setResult(msg);
+                    OBDal.getInstance().rollbackAndClose();
+                    return;
+                  }
+                }
               }
             }
+          } finally {
+            OBContext.restorePreviousMode();
           }
         }
       }
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jan 17 14:15:41 2013 +0530
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jan 17 14:18:36 2013 +0530
@@ -19040,7 +19040,7 @@
 <!--96B02DEA21084AD28903E48E2612C52A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--96B02DEA21084AD28903E48E2612C52A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--96B02DEA21084AD28903E48E2612C52A-->  <VALUE><![CDATA[gl_journalline_openitem_check]]></VALUE>
-<!--96B02DEA21084AD28903E48E2612C52A-->  <MSGTEXT><![CDATA[If Open Items is checked, Business Partner, Financial Account, Payment Method, GL Item and Payment Date fields must be filled.]]></MSGTEXT>
+<!--96B02DEA21084AD28903E48E2612C52A-->  <MSGTEXT><![CDATA[If Open Items is checked, Financial Account, Payment Method, GL Item and Payment Date fields must be filled.]]></MSGTEXT>
 <!--96B02DEA21084AD28903E48E2612C52A-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
 <!--96B02DEA21084AD28903E48E2612C52A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--96B02DEA21084AD28903E48E2612C52A--></AD_MESSAGE>