From acca0bcfdcc6f2bbf69d9aef40faff71ee844572 Mon Sep 17 00:00:00 2001 From: Scott Gray Date: Thu, 1 Oct 2009 12:42:18 +0000 Subject: [PATCH] Fix to make sure all tax adjustments are including when calculating the total tax for an order, adjustments without taxAuth information were being passed over resulting in an incorrect grand total being calculated. Also changed a couple setScale calls to use the fields already defined instead of getting them all over again from UtilNumber. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@820632 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/ofbiz/order/order/OrderReadHelper.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java b/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java index 09abdbcef5..1f58c33388 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java +++ b/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java @@ -2850,6 +2850,8 @@ public class OrderReadHelper { List distinctTaxAuthGeoIdList = EntityUtil.getFieldListFromEntityList(orderAdjustments, "taxAuthGeoId", true); List distinctTaxAuthPartyIdList = EntityUtil.getFieldListFromEntityList(orderAdjustments, "taxAuthPartyId", true); + // Keep a list of amount that have been added to make sure none are missed (if taxAuth* information is missing) + List processedAdjustments = FastList.newInstance(); // For each taxAuthGeoId get and add amount from orderAdjustment for (String taxAuthGeoId : distinctTaxAuthGeoIdList) { for (String taxAuthPartyId : distinctTaxAuthPartyIdList) { @@ -2863,14 +2865,23 @@ public class OrderReadHelper { if (amount == null) { amount = ZERO; } - totalAmount = totalAmount.add(amount).setScale(UtilNumber.getBigDecimalScale("salestax.calc.decimals"), taxRounding); + totalAmount = totalAmount.add(amount).setScale(taxCalcScale, taxRounding); + processedAdjustments.add(orderAdjustment); } - totalAmount = totalAmount.setScale(UtilNumber.getBigDecimalScale("salestax.final.decimals"), UtilNumber.getBigDecimalRoundingMode("salestax.rounding")); + totalAmount = totalAmount.setScale(taxFinalScale, taxRounding); taxByTaxAuthGeoAndPartyList.add(UtilMisc.toMap("taxAuthPartyId", taxAuthPartyId, "taxAuthGeoId", taxAuthGeoId, "totalAmount", totalAmount)); taxGrandTotal = taxGrandTotal.add(totalAmount); } } } + // Process any adjustments that got missed + List missedAdjustments = FastList.newInstance(); + missedAdjustments.addAll(orderAdjustments); + missedAdjustments.removeAll(processedAdjustments); + for (GenericValue orderAdjustment : missedAdjustments) { + taxGrandTotal = taxGrandTotal.add(orderAdjustment.getBigDecimal("amount").setScale(taxCalcScale, taxRounding)); + } + taxGrandTotal = taxGrandTotal.setScale(taxFinalScale, taxRounding); } Map result = FastMap.newInstance(); result.put("taxByTaxAuthGeoAndPartyList", taxByTaxAuthGeoAndPartyList);