spree/spree — pull request #4327 by radar (2014-02-11 06:58:46+00:00)
Title: Correctly apply relevant tax rates

This is a medium size PR which addresses a couple of things:

### 1. Shipments were not being taxed correctly if the rate was an inclusive tax.

This is now fixed by shipping methods linking to tax categories, and then when shipping rates are generated the relevant tax rate (if any) is linked to the shipment. As a "side-effect" of this, shipping rates are able to display the amount of tax they will incur.

### 2. Fixes #4318

I've personally witnessed a case where tax rates from the same tax category were being applied to an item in the order. See my example in #4318. There is now a fix for this within this PR.

### 3. Altered the Spree::TaxRate specs to call class-level adjust, not instance-level

This means that the fix for point number 2 here is tested. A small difference, but an important one.

### 4. Pre-tax amounts are now being stored

Previously, if you wanted to gain access to the pre-tax amount for an item you would need to re-calculate that based off the tax for that item. Now it's stored and you don't need to do the calculation. This amount is then used to calculate the amount of tax that should be applied to an item. For instance, a $10 item with 10% inclusive tax should have a tax amount of $0.91, not $1.00. Sales tax of 10% would cause the tax rate to be an additional one of 10%, which *would* be $1.00 and NOT $0.91.

(Have I mentioned how much fun tax is yet?)

### 5. Fixed some silly double looping in checkout's sidebar

It was seriously dumb and I think it was my fault. It was causing tax rates to appear not once but twice. Fix was simple.

/cc @cduv @jdurand