Hi,

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'][0]['price']['amount'] - $price['data']['components'][0]['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'][0]['price']['amount'] * $tax_rate['rate'];, but I can't tell if that applies for all kind of taxes.

Files: 
CommentFileSizeAuthor
#1 1784468-commerce_tax_vat_manual_edit_fix-1.patch1.25 KBmh86
PASSED: [[SimpleTest]]: [MySQL] 3,567 pass(es).
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new1.25 KB
PASSED: [[SimpleTest]]: [MySQL] 3,567 pass(es).
[ View ]

Attached the patch that I'm currently using. Maybe it's better to fix the formula in commerce_tax_rate_calculate(), but actually I have no idea how it is intended to be.

Status:Needs review» Needs work

The last submitted patch, 1784468-commerce_tax_vat_manual_edit_fix-1.patch, failed testing.

Status:Needs work» Needs review

any news on this? i am having problems in some vat calculations on Commerce Kickstart 7.x-2.8

Title:Wrong VAT calculation when manually editing the priceLine item unit price rebasing with VAT behaves unexpectedly
Version:7.x-1.3» 7.x-1.x-dev
Category:bug» task
Status:Needs review» Postponed (maintainer needs more info)

I just tested this behavior and found it working as designed. What the code currently does is, when a line item's unit price is directly changed via an order edit form, its price components are scanned to locate any taxes that had been applied to the line item. If it found a VAT tax rate, it performs the inverse tax calculation to treat the unit price text field as the administrator supplying the "price including VAT." We do this, because that's what the price was beforehand - the price including VAT. What your patch does is change it so that the administrator supplies the "price excluding VAT" and then applies the VAT on top of the new price, which is what the code already does for sales taxes a few lines above.

Your patch as written is actually a regression, even if it works for you, but what I suppose we could do is make it explicit what's happening when these prices are adjusted. Unfortunately, I don't have any ideas on how to do this, so I'm going to leave this postponed for now until someone wants to propose a solution.