DrupalCon Baltimore: 161 sessions, many voices, infinite possibilities. Earlybird rate ends Friday.
we're are using the commerce tax module for calculating the VAT tax. The tax rate is configured with 0.16666666667 and it works fine if people completely go through the checkout process.
Nevertheless we found a few orders on our system where the tax was just wrong. For those the admin has changed the price for whatever reason.
When debugging the system, we found out that there are two different processes in the tax module and different formulas are used.
First, if it's a normal checkout, the function commerce_tax_rate_calculate() will be invoked, where the tax is calculated with:
$amount = $line_item_wrapper->commerce_unit_price->amount->value() * $tax_rate['rate'];
which works if you use 0.16 for the VAT.
If the price of an line item is changed afterwards, commerce_tax_commerce_line_item_rebase_unit_price() is invoked, using:
$tax_amount = $price['data']['components']['price']['amount'] - $price['data']['components']['price']['amount'] / (1 + $tax_rate['rate']);
which is of course different to the one above (you would have to use 0.2 for the VAT).
The tax system is quite complex, in the meanwhile we just changed the last formula to
$tax_amount = $price['data']['components']['price']['amount'] * $tax_rate['rate'];, but I can't tell if that applies for all kind of taxes.