Fixes Issue 27298:Error reactivating payment if business partner field is blank
authorDaniel Ruiz <daniel.ruiz@openbravo.com>
Mon, 11 Aug 2014 11:06:52 +0200
changeset 24079 83c29ab40446
parent 24078 9f64a8da1daa
child 24080 f4010c9edcd3
Fixes Issue 27298:Error reactivating payment if business partner field is blank
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Tue Oct 14 15:12:25 2014 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Mon Aug 11 11:06:52 2014 +0200
@@ -765,17 +765,20 @@
         OBContext.setAdminMode();
         try {
           BusinessPartner businessPartner = payment.getBusinessPartner();
-          // When credit is used (consumed) we compensate so_creditused as this amount is already
-          // included in the payment details. Credit consumed should not affect to so_creditused
           BigDecimal paidAmount = BigDecimal.ZERO;
           String fromCurrency = payment.getCurrency().getId();
-          String toCurrency = businessPartner.getCurrency().getId();
-          if (payment.getGeneratedCredit().compareTo(BigDecimal.ZERO) == 0
-              && payment.getUsedCredit().compareTo(BigDecimal.ZERO) != 0) {
-            if (isReceipt) {
-              decreaseCustomerCredit(businessPartner, payment.getUsedCredit());
-            } else {
-              increaseCustomerCredit(businessPartner, payment.getUsedCredit());
+          String toCurrency = "";
+          if (!(businessPartner == null)) {
+            // When credit is used (consumed) we compensate so_creditused as this amount is already
+            // included in the payment details. Credit consumed should not affect to so_creditused
+            toCurrency = businessPartner.getCurrency().getId();
+            if (payment.getGeneratedCredit().compareTo(BigDecimal.ZERO) == 0
+                && payment.getUsedCredit().compareTo(BigDecimal.ZERO) != 0) {
+              if (isReceipt) {
+                decreaseCustomerCredit(businessPartner, payment.getUsedCredit());
+              } else {
+                increaseCustomerCredit(businessPartner, payment.getUsedCredit());
+              }
             }
           }
           List<FIN_PaymentDetail> paymentDetails = payment.getFINPaymentDetailList();
@@ -838,41 +841,42 @@
                         .getInvoicePaymentSchedule().getInvoice() : null;
                     paidAmount = BigDecimal.ZERO;
                     fromCurrency = payment.getCurrency().getId();
-                    toCurrency = businessPartner.getCurrency().getId();
-                    if (!fromCurrency.equals(toCurrency)) {
-                      BigDecimal exchangeRate = BigDecimal.ZERO;
-                      // check at invoice document level
-                      List<ConversionRateDoc> conversionRateDocumentForInvoice = getConversionRateDocumentForInvoice(
-                          invoiceForConversion, isReceipt);
-                      if (conversionRateDocumentForInvoice.size() > 0) {
-                        exchangeRate = conversionRateDocumentForInvoice.get(0).getRate();
+                    toCurrency = "";
+                    if (!(businessPartner == null)) {
+                      toCurrency = businessPartner.getCurrency().getId();
+                      if (!fromCurrency.equals(toCurrency)) {
+                        BigDecimal exchangeRate = BigDecimal.ZERO;
+                        // check at invoice document level
+                        List<ConversionRateDoc> conversionRateDocumentForInvoice = getConversionRateDocumentForInvoice(
+                            invoiceForConversion, isReceipt);
+                        if (conversionRateDocumentForInvoice.size() > 0) {
+                          exchangeRate = conversionRateDocumentForInvoice.get(0).getRate();
+                        } else {
+                          // global
+                          exchangeRate = getConversionRate(payment.getOrganization().getId(),
+                              fromCurrency, toCurrency,
+                              invoiceForConversion != null ? invoiceForConversion.getInvoiceDate()
+                                  : payment.getPaymentDate());
+                        }
+                        if (exchangeRate == BigDecimal.ZERO) {
+                          msg.setType("Error");
+                          msg.setTitle(Utility.messageBD(conProvider, "Error", language));
+                          msg.setMessage(Utility.parseTranslation(conProvider, vars, language,
+                              "@NoCurrencyConversion@"));
+                          bundle.setResult(msg);
+                          OBDal.getInstance().rollbackAndClose();
+                          return;
+                        }
+                        paidAmount = amount.multiply(exchangeRate);
                       } else {
-                        // global
-                        exchangeRate = getConversionRate(payment.getOrganization().getId(),
-                            fromCurrency, toCurrency,
-                            invoiceForConversion != null ? invoiceForConversion.getInvoiceDate()
-                                : payment.getPaymentDate());
+                        paidAmount = amount;
                       }
-                      if (exchangeRate == BigDecimal.ZERO) {
-                        msg.setType("Error");
-                        msg.setTitle(Utility.messageBD(conProvider, "Error", language));
-                        msg.setMessage(Utility.parseTranslation(conProvider, vars, language,
-                            "@NoCurrencyConversion@"));
-                        bundle.setResult(msg);
-                        OBDal.getInstance().rollbackAndClose();
-                        return;
+                      if (isReceipt) {
+                        increaseCustomerCredit(businessPartner, paidAmount);
+                      } else {
+                        decreaseCustomerCredit(businessPartner, paidAmount);
                       }
-                      paidAmount = amount.multiply(exchangeRate);
-                    } else {
-                      paidAmount = amount;
                     }
-                    if (isReceipt) {
-                      increaseCustomerCredit(businessPartner, paidAmount);
-                    } else {
-                      decreaseCustomerCredit(businessPartner, paidAmount);
-
-                    }
-
                   }
                 }
                 if (paymentScheduleDetail.getOrderPaymentSchedule() != null && restorePaidAmounts) {