onepica / avatax

One Pica Magento extension for sales tax calculation performed by Avatax
http://www.magentocommerce.com/magento-connect/6760.html
29 stars 34 forks source link

Rewrite Mage_Tax_Model_Calculation::calcTaxAmount() to use requested rates #49

Open colnpanic opened 8 years ago

colnpanic commented 8 years ago

If any modules or custom development uses Mage::getSingleton('tax/calculation')->calcTaxAmount($price, $taxRate) then it will do a simple calculation instead of requesting the tax rate from Avalera. The tax calculation will be right most of the time, but it is vulnerable to rounding errors where the regional taxes added do not equal the simple calculation.

For example, a $25.99 item has 3 taxes in AvaTax:

These intermediate taxes sum to $1.98. Tax rates sum to 7.638%, times $25.99 is 1.9851162 which rounds to $1.99, which, last I checked, does not in fact equal $1.98.

Both values can be viewed as "right" I believe, but they do need to be consistent. Rewriting the tax calculation module can help maintain consistency in tax calculations.

colnpanic commented 8 years ago

Thinking more on this, there is not sufficient data available to the calcTaxAmount call to use the AvaTax rates. We will need to find each place that is called and modify it to use something like Mage::getSingleton('avatax/avatax_estimate')->getItemTax($item) instead.

Feel free to close, unless you have ideas for how to assist compatibility and consistency with tax rates in other modules.

J-Fricke commented 7 years ago

@colnpanic Curious what your final solution was here. We are having a similar issue to this one https://github.com/onepica/avatax/issues/109 only it's located in another module calling calcTaxAmount like in your issue.

Mage::getSingleton('avatax/avatax_estimate')->getItemTax($item) of course does not work as it's not a model.

I attempted to swap $taxCalculationModel = Mage::getSingleton('tax/calculation'); out for $taxCalculationModel = Mage::getSingleton('avatax/tax_calculation'); in this other extension I have for order editing. Though it also does not appear to be calculating the tax still.

Have tried with both Enable/Disable on this Disable tax calculation requests on non-checkout actions

Seems like this extension should be overriding the calculation, but it does not appear to be working correctly outside of the cart.

J-Fricke commented 7 years ago

I did some digging and my issue is related to the tax being calculated only on quote objects and our object is already an order when it's modified and requiring tax calculation.