Related to Issue 22782. Code Review changes.
authorDavid Miguelez <david.miguelez@openbravo.com>
Tue, 22 Jan 2013 18:51:23 +0100
changeset 19404 cf2de0fafe31
parent 19403 36dbe385905f
child 19406 de3e9011052b
Related to Issue 22782. Code Review changes.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
src-db/database/model/tables/GL_JOURNALLINE.xml
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java	Thu Jan 17 14:18:36 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPaymentFromJournalLine.java	Tue Jan 22 18:51:23 2013 +0100
@@ -92,11 +92,11 @@
         throw new OBException("@FIN_NoMultiCurrencyAllowed@");
       }
       if (journalLine.getDebit().subtract(journalLine.getCredit()).compareTo(BigDecimal.ZERO) > 0
-          && !bPartner.isCustomer()) {
+          && bPartner != null && !bPartner.isCustomer()) {
         throw new OBException("@FIN_NoCustomer@");
       }
       if (journalLine.getDebit().subtract(journalLine.getCredit()).compareTo(BigDecimal.ZERO) < 0
-          && !bPartner.isVendor()) {
+          && bPartner != null && !bPartner.isVendor()) {
         throw new OBException("@FIN_NoVendor@");
       }
 
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java	Thu Jan 17 14:18:36 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java	Tue Jan 22 18:51:23 2013 +0100
@@ -30,6 +30,7 @@
 import org.openbravo.advpaymentmngt.utility.Value;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.client.kernel.RequestContext;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
@@ -110,24 +111,32 @@
             return error;
           }
         } 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.
-                OBError error = new OBError();
-                error.setType("Error");
-                error.setMessage(strmessage1 + " " + bPartner.getIdentifier() + " " + strmessage2);
-                OBDal.getInstance().rollbackAndClose();
-                return error;
+          OBContext.setAdminMode(true);
+          try {
+            for (FIN_PaymentDetail pd : payment.getFINPaymentDetailList()) {
+              for (FIN_PaymentScheduleDetail psd : pd.getFINPaymentScheduleDetailList()) {
+                BusinessPartner bPartner = null;
+                if (psd.getInvoicePaymentSchedule() != null) {
+                  bPartner = psd.getInvoicePaymentSchedule().getInvoice().getBusinessPartner();
+                } else if (psd.getOrderPaymentSchedule() != null) {
+                  bPartner = psd.getOrderPaymentSchedule().getOrder().getBusinessPartner();
+                }
+                if (bPartner != null
+                    && FIN_Utility.isBlockedBusinessPartner(bPartner.getId(), payment.isReceipt(),
+                        4)) {
+                  // If the Business Partner is blocked for Payments, the Payment will not be
+                  // completed.
+                  OBError error = new OBError();
+                  error.setType("Error");
+                  error
+                      .setMessage(strmessage1 + " " + bPartner.getIdentifier() + " " + strmessage2);
+                  OBDal.getInstance().rollbackAndClose();
+                  return error;
+                }
               }
             }
+          } finally {
+            OBContext.restorePreviousMode();
           }
         }
       }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Jan 17 14:18:36 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Tue Jan 22 18:51:23 2013 +0100
@@ -96,31 +96,29 @@
             return;
           }
         } else {
-          OBContext.setAdminMode();
+          OBContext.setAdminMode(true);
           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;
-                  }
+                BusinessPartner bPartner = null;
+                if (psd.getInvoicePaymentSchedule() != null) {
+                  bPartner = psd.getInvoicePaymentSchedule().getInvoice().getBusinessPartner();
+                } else if (psd.getOrderPaymentSchedule() != null) {
+                  bPartner = psd.getOrderPaymentSchedule().getOrder().getBusinessPartner();
+                }
+                if (bPartner != null
+                    && 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;
                 }
               }
             }
--- a/src-db/database/model/tables/GL_JOURNALLINE.xml	Thu Jan 17 14:18:36 2013 +0530
+++ b/src-db/database/model/tables/GL_JOURNALLINE.xml	Tue Jan 22 18:51:23 2013 +0100
@@ -241,6 +241,6 @@
       <check name="GL_JOURNALLINE_C_TAX_ID_CHK"><![CDATA[(C_TAX_ID IS NULL) OR (C_WITHHOLDING_ID IS NULL)]]></check>
       <check name="GL_JOURNALLINE_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check>
       <check name="GL_JOURNALLINE_ISGENERATED_CHK"><![CDATA[ISGENERATED IN ('Y', 'N')]]></check>
-      <check name="GL_JOURNALLINE_OPENITEM_CHECK"><![CDATA[(OPEN_ITEMS = 'N') OR ((OPEN_ITEMS = 'Y') AND (FIN_FINANCIAL_ACCOUNT_ID IS NOT NULL) AND (FIN_PAYMENTMETHOD_ID IS NOT NULL) AND (C_GLITEM_ID IS NOT NULL) AND (PAYMENTDATE IS NOT NULL))]]></check>
+      <check name="GL_JOURNALLINE_OPENITEM_CHECK"><![CDATA[(OPEN_ITEMS = 'N') OR (((((OPEN_ITEMS = 'Y') AND (FIN_FINANCIAL_ACCOUNT_ID IS NOT NULL)) AND (FIN_PAYMENTMETHOD_ID IS NOT NULL)) AND (C_GLITEM_ID IS NOT NULL)) AND (PAYMENTDATE IS NOT NULL))]]></check>
     </table>
   </database>