svn commit: r1564116 - in /ofbiz/branches/release11.04: ./ applications/order/src/org/ofbiz/order/order/OrderReturnServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1564116 - in /ofbiz/branches/release11.04: ./ applications/order/src/org/ofbiz/order/order/OrderReturnServices.java

jleroux@apache.org
Author: jleroux
Date: Mon Feb  3 22:35:13 2014
New Revision: 1564116

URL: http://svn.apache.org/r1564116
Log:
"Applied fix from trunk for revision: 1564111"
------------------------------------------------------------------------
r1564111 | jleroux | 2014-02-03 23:29:40 +0100 (lun. 03 févr. 2014) | 12 lignes

A (slightly modified) patch from  Ritu Raj Lakhera for "Order return is not refunding the money" https://issues.apache.org/jira/browse/OFBIZ-5528

When we placed an order with two items and generate a return towards one item then code is refunding the money correctly.
But if we again do return for second item then code is not refunding the money because first return-refund process has changed the status of OrderPaymentPreference from 'PAYMENT_SETTLED' to ‘PAYMENT_REFUNDED’.
I think We should create the new OrderPaymentPreference with PAYMENT_REFUNDED status against old OrderPaymentPreference of 'PAYMENT_SETTLED' status at the time of return-refund process. So second return can also refund the money.

In other words we should create the new OrderPaymentPreference for each refund amount as we are doing with Payment entity(processRefundResult PaymentGatewayServices.java).

jleroux: I
* replaced the deprecated findByPrimaryKey by a finByOne
* replaced Exception GenericServiceException in catch (as it was before)
* reformatted some parts
------------------------------------------------------------------------


Modified:
    ofbiz/branches/release11.04/   (props changed)
    ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java

Propchange: ofbiz/branches/release11.04/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1564111

Modified: ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?rev=1564116&r1=1564115&r2=1564116&view=diff
==============================================================================
--- ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original)
+++ ofbiz/branches/release11.04/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Mon Feb  3 22:35:13 2014
@@ -1397,6 +1397,7 @@ public class OrderReturnServices {
                             Map<String, Object> orderPaymentPrefDetails = pmtppit.next();
                             GenericValue orderPaymentPreference = (GenericValue) orderPaymentPrefDetails.get("orderPaymentPreference");
                             BigDecimal orderPaymentPreferenceAvailable = (BigDecimal) orderPaymentPrefDetails.get("availableTotal");
+                            GenericValue refundOrderPaymentPreference=null;
 
                             // Refund up to the maxAmount for the paymentPref, or whatever is left to refund if that's less than the maxAmount
                             BigDecimal amountToRefund = orderPaymentPreferenceAvailable.min(amountLeftToRefund);
@@ -1408,23 +1409,33 @@ public class OrderReturnServices {
                             // Call the refund service to refund the payment
                             if (electronicTypes.contains(paymentMethodTypeId)) {
                                 try {
-                                    // for electronic types such as CREDIT_CARD and EFT_ACCOUNT, use refundPayment service
-                                    serviceResult = dispatcher.runSync("refundPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount", amountToRefund.setScale(decimals, rounding), "userLogin", userLogin));
+                                    Map<String, Object> serviceContext = UtilMisc.toMap("orderId", orderId,"userLogin", context.get("userLogin"));
+                                    serviceContext.put("paymentMethodId", orderPaymentPreference.getString("paymentMethodId"));
+                                    serviceContext.put("paymentMethodTypeId", orderPaymentPreference.getString("paymentMethodTypeId"));
+                                    serviceContext.put("statusId", orderPaymentPreference.getString("statusId"));
+                                    serviceContext.put("maxAmount", amountToRefund.setScale(decimals, rounding));
+                                    String orderPaymentPreferenceNewId = null;
+                                    Map<String, Object> result = dispatcher.runSync("createOrderPaymentPreference", serviceContext);
+                                    orderPaymentPreferenceNewId = (String) result.get("orderPaymentPreferenceId");
+                                    refundOrderPaymentPreference = delegator.findOne("OrderPaymentPreference", false, "orderPaymentPreferenceId", orderPaymentPreferenceNewId);
+                                    serviceResult = dispatcher.runSync("refundPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", refundOrderPaymentPreference, "refundAmount", amountToRefund.setScale(decimals, rounding), "userLogin", userLogin));
                                     if (ServiceUtil.isError(serviceResult) || ServiceUtil.isFailure(serviceResult)) {
                                         Debug.logError("Error in refund payment: " + ServiceUtil.getErrorMessage(serviceResult), module);
                                         continue;
                                     }
+                                    // for electronic types such as CREDIT_CARD and EFT_ACCOUNT, use refundPayment service
                                     paymentId = (String) serviceResult.get("paymentId");
                                     amountRefunded = (BigDecimal) serviceResult.get("refundAmount");
                                 } catch (GenericServiceException e) {
                                     Debug.logError(e, "Problem running the refundPayment service", module);
-                                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,
-                                            "OrderProblemsWithTheRefundSeeLogs", locale));
+                                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemsWithTheRefundSeeLogs", locale));
                                 }
                             } else if (paymentMethodTypeId.equals("EXT_BILLACT")) {
                                 try {
                                     // for Billing Account refunds
-                                    serviceResult = dispatcher.runSync("refundBillingAccountPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount", amountToRefund.setScale(decimals, rounding), "userLogin", userLogin));
+                                    serviceResult = dispatcher.runSync("refundBillingAccountPayment",
+                                            UtilMisc.<String, Object> toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount",
+                                                    amountToRefund.setScale(decimals, rounding), "userLogin", userLogin));
                                     if (ServiceUtil.isError(serviceResult) || ServiceUtil.isFailure(serviceResult)) {
                                         Debug.logError("Error in refund payment: " + ServiceUtil.getErrorMessage(serviceResult), module);
                                         continue;
@@ -1461,7 +1472,11 @@ public class OrderReturnServices {
 
                             // Fill out the data for the new ReturnItemResponse
                             Map<String, Object> response = FastMap.newInstance();
-                            response.put("orderPaymentPreferenceId", orderPaymentPreference.getString("orderPaymentPreferenceId"));
+                            if (UtilValidate.isNotEmpty(refundOrderPaymentPreference)) {
+                                response.put("orderPaymentPreferenceId", refundOrderPaymentPreference.getString("orderPaymentPreferenceId"));
+                            } else {
+                                response.put("orderPaymentPreferenceId", orderPaymentPreference.getString("orderPaymentPreferenceId"));
+                            }
                             response.put("responseAmount", amountRefunded.setScale(decimals, rounding));
                             response.put("responseDate", now);
                             response.put("userLogin", userLogin);