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
This commit is contained in:
Scott Gray
2009-10-01 12:42:18 +00:00
parent dbd33955ed
commit acca0bcfdc
@@ -2850,6 +2850,8 @@ public class OrderReadHelper {
List<String> distinctTaxAuthGeoIdList = EntityUtil.getFieldListFromEntityList(orderAdjustments, "taxAuthGeoId", true);
List<String> 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<GenericValue> 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.<String, Object>toMap("taxAuthPartyId", taxAuthPartyId, "taxAuthGeoId", taxAuthGeoId, "totalAmount", totalAmount));
taxGrandTotal = taxGrandTotal.add(totalAmount);
}
}
}
// Process any adjustments that got missed
List<GenericValue> 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);