spree/spree — pull request #4779 by IrvinFan (2014-06-03 22:47:48+00:00)
Title: Do not destroy associated adjustments when tax rate or promotion is deleted

This is an attempt to fix https://github.com/spree/spree/issues/4771

Currently when a tax rate is deleted the associated tax adjustments are destroyed no matter the order is open or closed. When a promotion is deleted the associated promotion adjustments are destroyed too if the order is still open. On top of that when the adjustments are destroyed the total cost doesn't get updated, which results in discrepancy in sum of the total cost.

One way to address this is to make sure total cost gets updated when adjustments are destroyed. But I think for better user experience we'd better keep those adjustments even for open order. Adjustments are created at the time a tax rate or coupon code is applied. It's like taking a snapshot. Later the deletion of the tax rate or promotion should not affect the adjustments that were created already. Unless we communicate that well to user, which we're not doing anything currently. It's a bad user experience when you see the discount and click "place order" and only find out later that you didn't get the discount. If I was the user I would feel cheated.

The fix in this PR is to keep the adjustments when a tax rate or promotion is deleted. It only nullifies the source_id in this case. So far I don't find any side effect of doing that. Anybody who is familiar with adjustments code are welcome to provide feedback.