Taxes incorrectly calculated when store coupons are applied

rhubarb-media - February 19, 2009 - 14:39
Project:Ubercart Discount Coupons
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs work
Description

------------------------------
Configuration:
------------------------------

I'm running Drupal 5.15 with Ubercart 5.x-1.7 on a Unix server, with MySQL 5.0.67 and PHP 5.2.5.

------------------------------
Problem:
------------------------------

Taxes are being incorrectly calculated when store coupons are applied to products. This problem is affecting all products, regardless of which tax rules are applied to them. In some cases, negative tax values (such as -$2.00) are being generated.

We've got 2 tax rates setup in Ubercart - G.S.T. (5%) and P.S.T. (8%). Some of our products have both taxes, others have G.S.T. but not P.S.T., and some have no taxes at all. (Tax rules are applied to products on a per-class basis, on the "admin/store/settings/taxes" page).

This problem only occurs when store coupons are applied to products. Taxes are calculated correctly when the coupon field is left empty.

Here are some examples...

------------------------------
Example 1:
------------------------------

A product with both G.S.T. and P.S.T.

The G.S.T. appears to have been calculated based on the original product price (before the coupon value was subtracted). The P.S.T., however, was correctly calculated based on the coupon-adjusted price. Strange...

------------------------------
Example 2:
------------------------------

A product with G.S.T. but no P.S.T.

Both G.S.T. and P.S.T. were calculated and applied to the product, despite the fact that the product is not supposed to have P.S.T. The G.S.T. was calculated correctly, and the P.S.T. was calculated as a negative dollar amount (because it's value was $0.00 to begin with?).

------------------------------
Example 3:
------------------------------

A product with no taxes at all.

G.S.T. was calculated and applied to the product, despite the fact that the product is not supposed to have any taxes. The G.S.T. was calculated as a negative dollar amount (because it's value was $0.00 to begin with?).

------------------------------
Conclusion:
------------------------------

We may be forced to de-activate the coupon module and search for an alternative. Can anyone shed some light on this issue? Has anyone else experienced these kinds of problems?

Thanks.

Mark

#1

longwave - February 19, 2009 - 22:51

What are your "taxed line item" checkbox settings for each of the taxes? It sounds like you have "Coupon discount" checked for one tax but not the other, which would explain some of the calculation discrepancies.

The rest of the problems are explained by the fact that taxes apply to individual products, but discounts are applied as a line item to the entire order. The taxes module is not aware of which products a coupon applies to; if the "Coupon discount" line item is selected for a tax, the coupon value will always be taxed, which can sometimes make the total negative. I guess this will only work correctly if taxes are applied equally across products and not as in your example; I hadn't realised this was a problem before now.

I am also currently unsure as to what the solution is. I think it will require closer interaction between uc_coupon and uc_taxes, or at least some way of modifying the product prices or subtotals that uc_taxes uses in its calculations. Any help or ideas are welcome.

#2

rhubarb-media - February 20, 2009 - 18:39

Thanks for your reply, longwave. We've been struggling with this for weeks, trying to isolate the source of the problem(s). It looks like we're going to have to deactivate the uc_coupon module and search for a different solution. Hopefully these problems can be overcome in a future version of the module.

Our taxed line items are:

G.S.T.

  • Shipping
  • Empty line
  • Coupon discount

P.S.T.

  • Shipping

This explains why the G.S.T. and P.S.T. were calculated at different stages in the workflow, in the first example I posted. We had experimented with adding "Coupon discount" to the P.S.T.'s taxed line items, but we ended up removing it in the end.

Thanks again for your help!

#3

longwave - February 20, 2009 - 20:41

I think I see a possible workaround involving additional hidden line items that store temporary "coupon subtotals" based on product classes and tax settings, uc_taxes can then use these instead of the all-or-nothing "Coupon discount" line item to correctly apply taxes on discounted products. This shouldn't need any modifications to uc_taxes but will need quite a bit of development and testing on the coupon side of things, however currently I'm not sure when I'll have time to do this work.

#4

sleepingmonk - February 23, 2009 - 06:56

I just added a patch for multiple Product selection. Now I'm wondering if this has already been added in the dev version...

Regarding this tax issue. I too am suffering from it and would be willing to help code a solution. I was afraid it would depend on "fixing" the tax system but I'll think about your idea longwave and see if I can come up with something. If you can provide any more details about this theory that would be great.

I'm extremely busy too but this is a pretty important issue so I'm willing to put some time into a collaborated effort.

#5

longwave - March 6, 2009 - 01:47
Version:5.x-1.6» 5.x-1.x-dev
Status:active» needs work

My first attempt at a patch for this is attached. It adds a new line item for each tax rate containing the applicable subtotal of the coupon value - in the tax settings, for each tax rate you should deselect "Coupon discount" and select only the specific "Coupon subtotal" for the tax.

From some basic testing I think these line items are calculated correctly, but the subtotal before tax is wrong. 'calculated' is set to false in hook_line_item() so these lines shouldn't be used for totalling, but uc_taxes apparently doesn't respect this when calculating the subtotal before tax (though should it?), and changing the line item weight doesn't appear to help.

The "hidden" line items was a bit of a dead end as I thought it may be possible to set 'stored' to false and calculate these on the fly, but they seemingly must be stored in the database for uc_taxes to use them. This may well not be the best approach, any ideas are welcome!

AttachmentSize
uc_coupon_taxes.patch 3.95 KB

#6

WiredEscape - April 10, 2009 - 02:33

Sorry if I add another complication to this tax calculation issue...

This is related, but could also be a separate feature request... feel free to move it but just though I'd bring it up while the tax issue was being looked at.

Canadian GST is calculated in two different ways depending on the type of coupon used.

1) If the coupon is a "store" coupon the discount amount is deducted from the item's price BEFORE taxes are calculated.
2) If the coupon is a "manufacturer's" coupon, one that the store is being reimbursed for, the discount is deducted AFTER taxes are calculated.

To handle coupons correctly a coupon 'type' option would be required.

Thanks,
Doug

 
 

Drupal is a registered trademark of Dries Buytaert.