Author: jacopoc
Date: Tue May 22 06:13:14 2007 New Revision: 540575 URL: http://svn.apache.org/viewvc?view=rev&rev=540575 Log: Added/fixed support for manual adjustments in credit returns. Added code to prevent a divide by zero exception when the returned price is set to zero. Fixed a bad condition check in the edit return item screen that was causing the update of the return adjustments after they were (correctly) updated in the updateReturnItem service. Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItemInc.ftl ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?view=diff&rev=540575&r1=540574&r2=540575 ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Tue May 22 06:13:14 2007 @@ -410,11 +410,12 @@ */ List orderItemQuantitiesIssued = null; try { - orderItemQuantitiesIssued = delegator.findByCondition("OrderItemQuantityReportGroupByItem", whereConditions, null, UtilMisc.toList("orderId", "orderItemSeqId"), UtilMisc.toList("orderItemSeqId"), null); + orderItemQuantitiesIssued = delegator.findByCondition("OrderItemQuantityReportGroupByItem", whereConditions, null, UtilMisc.toList("orderId", "orderItemSeqId", "quantityIssued"), UtilMisc.toList("orderItemSeqId"), null); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetReturnHeaderFromItem", locale)); } + if (orderItemQuantitiesIssued != null) { Iterator i = orderItemQuantitiesIssued.iterator(); while (i.hasNext()) { @@ -607,8 +608,10 @@ Debug.logError(e, "Problems looking up return information", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale)); } + + BigDecimal adjustments = new BigDecimal(getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId, "returnTypeId", "RTN_CREDIT"))); - if (returnHeader != null && returnItems != null && returnItems.size() > 0) { + if (returnHeader != null && ((returnItems != null && returnItems.size() > 0) || adjustments.compareTo(ZERO) > 0)) { String billingAccountId = returnHeader.getString("billingAccountId"); String fromPartyId = returnHeader.getString("fromPartyId"); String toPartyId = returnHeader.getString("toPartyId"); @@ -655,7 +658,6 @@ } // add the adjustments to the total - BigDecimal adjustments = new BigDecimal(getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId))); creditTotal = creditTotal.add(adjustments.setScale(decimals, rounding)); // create a Payment record for this credit; will look just like a normal payment @@ -2015,7 +2017,7 @@ if (orderAdjustment != null && orderAdjustment.get("taxAuthorityRateSeqId") != null) { newReturnAdjustment.set("taxAuthorityRateSeqId", orderAdjustment.getString("taxAuthorityRateSeqId")); } - newReturnAdjustment.set("amount", amount); + newReturnAdjustment.set("amount", (UtilValidate.isEmpty(amount)? new Double(0.0): amount)); newReturnAdjustment.set("returnAdjustmentTypeId", returnAdjustmentTypeId); newReturnAdjustment.set("description", description); newReturnAdjustment.set("returnItemSeqId", UtilValidate.isEmpty(returnItemSeqId) ? "_NA_" : returnItemSeqId); @@ -2041,7 +2043,6 @@ try { returnAdjustment = delegator.findByPrimaryKey("ReturnAdjustment", UtilMisc.toMap("returnAdjustmentId", context.get("returnAdjustmentId"))); - if (returnAdjustment != null) { returnItem = delegator.findByPrimaryKey("ReturnItem", UtilMisc.toMap("returnId", returnAdjustment.get("returnId"), "returnItemSeqId", returnAdjustment.get("returnItemSeqId"))); @@ -2064,11 +2065,16 @@ amount = (Double) context.get("amount"); } - returnAdjustment.setNonPKFields(context); - returnAdjustment.set("amount", amount); - delegator.store(returnAdjustment); - Debug.logInfo("Update ReturnAdjustment with Id:" + context.get("returnAdjustmentId") + " to amount " + amount +" successfully.", module); - Map result = ServiceUtil.returnSuccess("Update ReturnAdjustment with Id:" + context.get("returnAdjustmentId") + " to amount " + amount +" successfully."); + Map result = null; + if (UtilValidate.isNotEmpty(amount)) { + returnAdjustment.setNonPKFields(context); + returnAdjustment.set("amount", amount); + delegator.store(returnAdjustment); + Debug.logInfo("Update ReturnAdjustment with Id:" + context.get("returnAdjustmentId") + " to amount " + amount +" successfully.", module); + result = ServiceUtil.returnSuccess("Update ReturnAdjustment with Id:" + context.get("returnAdjustmentId") + " to amount " + amount +" successfully."); + } else { + result = ServiceUtil.returnSuccess(); + } return result; } catch (GenericEntityException e) { Debug.logError(e, "Failed to store returnAdjustment", module); @@ -2107,7 +2113,7 @@ } catch (org.ofbiz.service.GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); - } + } } /** @@ -2192,7 +2198,12 @@ int finalDecimals = isSalesTax ? UtilNumber.getBigDecimalScale(settingPrefix + ".final.decimals") : decimals; returnTotal = returnTotal.setScale(decimals, rounding); originalTotal = originalTotal.setScale(decimals, rounding); - BigDecimal newAmount = returnTotal.divide(originalTotal, decimals, rounding).multiply(amount).setScale(finalDecimals, rounding); + BigDecimal newAmount = null; + if (ZERO.compareTo(originalTotal) != 0) { + newAmount = returnTotal.divide(originalTotal, decimals, rounding).multiply(amount).setScale(finalDecimals, rounding); + } else { + newAmount = ZERO; + } return new Double(newAmount.doubleValue()); } } Modified: ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItemInc.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItemInc.ftl?view=diff&rev=540575&r1=540574&r2=540575 ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItemInc.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItemInc.ftl Tue May 22 06:13:14 2007 @@ -177,7 +177,7 @@ </#if> <#assign manualAdjRowNum = rowCount/> - <input type="hidden" name="returnItemTypeId_o_${rowCount}" value="RET_MAN_ADJ"/> + <input type="hidden" name="returnItemTypeId_o_${rowCount}" value="RET_MAN_ADJ"/> <tr><td colspan="9"><hr class="sepbar"></td></tr> <tr> <td colspan="9"> @@ -191,6 +191,14 @@ <td> <input type="text" class="inputBox" size="8" name="amount_o_${rowCount}" value="${0.00?string("##0.00")}"/> </td> + <td> + <select name="returnTypeId_o_${rowCount}" class="selectBox"> + <#list returnTypes as type> + <option value="${type.returnTypeId}" <#if type.returnTypeId == "RTN_REFUND">selected</#if>>${type.get("description",locale)?default(type.returnTypeId)}</option> + </#list> + </select> + </td> + <td align="right"> <input type="checkbox" name="_rowSubmit_o_${rowCount}" value="Y" onclick="javascript:checkToggle(this, '${selectAllFormName}');"/> </td> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl?view=diff&rev=540575&r1=540574&r2=540575 ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/return/returnItems.ftl Tue May 22 06:13:14 2007 @@ -20,8 +20,10 @@ <#macro displayReturnAdjustment returnAdjustment adjEditable> <#assign returnHeader = returnAdjustment.getRelatedOne("ReturnHeader")> <#assign adjReturnType = returnAdjustment.getRelatedOne("ReturnType")?if_exists> - <input type="hidden" name="_rowSubmit_o_${rowCount}" value="Y" /> - <input type="hidden" name="returnAdjustmentId_o_${rowCount}" value="${returnAdjustment.returnAdjustmentId}" /> + <#if (adjEditable)> + <input type="hidden" name="_rowSubmit_o_${rowCount}" value="Y" /> + <input type="hidden" name="returnAdjustmentId_o_${rowCount}" value="${returnAdjustment.returnAdjustmentId}" /> + </#if> <tr class="tabletext"> <td colspan="2"> </td> <td colspan="3" class="tabletext">${returnAdjustment.get("description",locale)?default("N/A")} @@ -56,7 +58,9 @@ <#else> <td> </td> </#if> - <#assign rowCount = rowCount + 1> + <#if (adjEditable)> + <#assign rowCount = rowCount + 1> + </#if> <#assign returnTotal = returnTotal + returnAdjustment.get("amount")> </tr> </#macro> @@ -258,9 +262,8 @@ </tr> </#if> <tr><td colspan="10"><hr class="sepbar"></td></tr> - <#-- these are general return adjustments not associated with a particular item (itemSeqId = "_NA_" --> -<#if (returnAdjustments?has_content)> +<#if (returnAdjustments?has_content)> <#list returnAdjustments as returnAdjustment> <#assign adjEditable = !readOnly> <#-- they are editable if the rest of the return items are --> <@displayReturnAdjustment returnAdjustment=returnAdjustment adjEditable=adjEditable/> |
Free forum by Nabble | Edit this page |