While working on the discounts framework, I came across some problems in the way tax line items are handled. Since the discounts were being handled in a similar way, they kept getting in each other's way. This patch is the result of getting everything fixed, and it takes into account the fact that an order's line items exist both in the database, and on the $order object through most of the checkout process. So, when tax line items are recalculated, they need to modify both the database for future loads, and the present $order.

Comments

Island Usurper’s picture

StatusFileSize
new4.1 KB

One more try to attach the patch...

rszrama’s picture

Status: Needs review » Needs work

On the 2.x Livetest, I setup a tax rate that adds a 6% sales tax to shippable products and shipping line items. I setup a second tax rate that adds a 6% sales tax to any product, shipping line items, and other tax line items. This second is added after the first. On the checkout form, the second one is $0.05 more to account for taxing the tax. However, on the review page, the second one is $0.10 more like it's taxing itself.

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new4.45 KB

There was some goofiness with taxed taxes being taxed twice (three times fast :P ). Try this one.

rszrama’s picture

Status: Needs review » Needs work

Failed to apply.

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new4.48 KB

Wow. I guess patch can't handle it when two changes in the same hunk drift too far apart. Try this one.

rszrama’s picture

Status: Needs review » Reviewed & tested by the community

This worked for a normal tax line item, a second tax line item taxing tax line items, and a third line item taxing tax line items... if anything should've confused it, it would've been that. And I don't think anything is quite as complex in real life. I hope. : P

I guess it's good to go!

Island Usurper’s picture

Status: Reviewed & tested by the community » Fixed

Great!

Committed.

m.a.king’s picture

Hi --

I'm wondering if I'm doing something wrong, but with this patch (or the latest version of the module), I'm getting duplicate tax line items if I visit the cart/checkout/review page more than once.
that is:
- go through the checkout process to the review page
- press back to go cart/checkout
- press review again to go to cart/checkout/review

Each time I go to the review page from the checkout page, my tax line items are duplicated.
I can fix the issue by changing uc_taxes.module like so:

uc_taxes/uc_taxes.module	2009-02-24 18:02:58.000000000 -0500
@@ -378,6 +378,7 @@
   if (is_array($order->line_items)) {
     foreach ($order->line_items as $i => $line) {
       if (substr($line['type'], 0, 3) == 'tax' && substr($line['type'], 4) != '_subtotal') {
+        uc_order_delete_line_item($line['line_item_id']);
         unset($order->line_items[$i]);
       }
     }

That is, I delete the line item from the DB in addition to unsetting it. Does that make sense?

Thanks.

rszrama’s picture

Status: Fixed » Needs review
Island Usurper’s picture

Category: support » bug
StatusFileSize
new2.22 KB

While that would fix this problem, it would prevent the order log page from ever showing a "Changed %tax" message, which I think is kind of valuable. In any case, I've changed some other things to preserve that information and prevent the duplicate taxes.

rszrama’s picture

Status: Needs review » Fixed
StatusFileSize
new1.55 KB

Tested on the Livetest... taxes calculating fine during and after checkout. Committed that attached version, as the previous patch was not good after committing a separate tax patch earlier.

rszrama’s picture

Issue tags: +dc2009 code sprint

tagging

chrisschaub’s picture

These patches do not work. I also tested with latest BETA5 code without patching. Still getting duplicate taxes, when I go "back" and then "review order" again. Have "weight" set to 10 for this tax item. Also, the tax on the first time through does not reflect line items like discounts etc. It only adds these line items into the mix after a "back" and then "review order" -- but then there are dupes! Two bugs really.

chrisschaub’s picture

Maybe I applied the patches wrong? Do I apply #10 and then #11? Applying #10 by itself seems to solve the dupe issue. But, the taxes are still out of state, the order object is stale. This is still happening for discounts (various discount modules). The taxes don't take the discount line items into considerations. If you check the order object before calculating taxes, it should fix it.

rszrama’s picture

There was a tax patch committed that invalidated #10, so I applied #11 after the prior one was committed. At this point, I'm not sure where your install is. #11 was done on the latest bzr code and committed... any chance you can grab that? I'm also not sure which discount module you're using. Any more info?

chrisschaub’s picture

Ok, I'll grab bzr and test. uc_coupons was fixed by the developer, but uc_discount, uc_discounts and uc_discounts_alt all have the problem with tax calculation because they use hook_order. But the order object is stale. Look at the link I posted, comment #4 and you'll see the fix. It would be cool if somehow a fix could happen in uc_taxes which would try and grab the totals after all line items are written to the order object. I think the discount line items are getting written to the database, but the order object used by uc_taxes is stale. Not sure how, yet.

See comment #4 here for what fixed uc_coupon and taxes:

http://drupal.org/node/350359

rszrama’s picture

Status: Fixed » Needs review
chrisschaub’s picture

Ok, I just removed all discount modules and tried the latest uc_taxes folder and file from bzr. No dice. If you go "back" from the review order screen and then continue to review order, you get two dupe tax line items. This scenario would happen if user was on the review order screen and wanted to go back and change some data.

pebosi’s picture

worked for me when using bzr version and applyin the patch from #11.

regards

chrisschaub’s picture

Ok, I just got the latest from bzr and applied patch #11. Seems to work! Thanks Ryan and Lyle.

Island Usurper’s picture

Status: Needs review » Fixed

That's good. I was getting really worried for a bit. :)

Status: Fixed » Closed (fixed)
Issue tags: -dc2009 code sprint

Automatically closed -- issue fixed for 2 weeks with no activity.