[ic] Issue with taxable_amount / total_cost calculating incorrect totals when Discount ENTIRE_ORDER is used

Peter peter at pajamian.dhs.org
Wed Feb 3 02:31:58 UTC 2010

On 03/02/10 14:19, Ron Phipps wrote:
> I found this issue while working with a build of 5.5.0 from 2007, and in
> reviewing Interpolate.pm from git HEAD it appears to be the same.
> This is more to ask if there is a scenario where taxable_amount should
> be returning negative amounts and what that scenario might look like. If
> we cannot come up with the scenario it might make sense to fix the issue.
> Here is the situation, we have a $6 discount in use on a $100 subtotal
> order.  There is $6.00 in shipping and the tax is %9.
> If the items in the cart are marked nontaxable the results are as follows:
> Subtotal:    100
> Ship:        6
> SalesTax:    -0.54
> Discount:    -6
> Total:        $99.46
> The problem is that when total_cost calls salestax which in turn calls
> taxable_amount $cost is calculated as -6.00 (the amount of the discount
> since no items are taxed), and this -6.00 is returned to salestax which
> then calculates the tax as -0.54 and is figured into the total cost.
> I patched my local copy by adding:
>         if ($cost < 0) {
>             $cost = 0;
>         }
> prior to:
>     $taxable = $cost;

That's one way to at least partially solve the problem, but if you have
some times that are taxable and some that aren't you could still be
charging too little sales tax.  The real issue here is that when you
discount an entire order there is no indication of which actual items
are being discounted and so no indication of how much sales tax to take
out.  Two possible solutions here (that would be better than the above

1.  Calculate new sales tax based on new subtotal and the sales tax
percentage, compare to the old sales tax and set the sales tax to the
lesser of the two.

2.  Calculate an averaged percentage based on the old sales tax and old
subtotal and apply that percentage to the new subtotal to determine the
new sales tax, ie: new_sales_tax = old_sales_tax / old_subtotal *

Solution 1 favors the vendor for any sales tax applied and solution 2 is
a more balanced approach, but either solution is not going to be fully
accurate since we don't have any data on which orderlines to apply the
discount to.


More information about the interchange-users mailing list