Posted by attiks on May 29, 2009 at 10:30am
28 followers
| Project: | Ubercart Discounts (Alternative) |
| Version: | 6.x-2.x-dev |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
See #476344: Incompatible with uc_discounts_alt
Module is working as expected, but once I start using uc_discounts_alt (http://drupal.org/project/uc_discounts_alt) the prices get mixed up. uc_discounts_alt uses the sell prices to calculte the discount and the price alterer isn't running in the message displayed, so it shows the sell price without VAT, while the shopping cart shows the price including VAT.
Comments
#1
uc_discounts_alt should be calling uc_price() rather than uc_currency_format() to ensure the VAT alterer modifies the price correctly. But I'm not currently sure what context you should be calling uc_price() with, and this will have to be done carefully as tax may need to be calculated differently depending on whether the discount applies to an individual product or the full order - see #475474: Price alterer contexts and VAT support for the current discussion on this in Ubercart core.
#2
Hi attiks,
I'm unfamiliar with VAT. It works like a tax, correct? Can you give me an example of what the you are getting and what you should get for the following screens?
-cart page
-checkout page
-review page
-product page (if using the product_price_alterer_field submodule of uc_discounts_alt)
I see I'm using $product->price in some areas and $product->sell_price in others. This may be a problem.
This module may doesn't call uc_currency_format() on product fields, only on its own discount amounts. So it may need to get a decimal price using uc_price. We'll see what needs to be done once we have a little more information. Thanks.
#3
@ryan, VAT works the same as taxes, this is what i did:
1/ created a tax rule for all products, add 21%
2/ created a discount buy 2 one for free ('2 + 1 gratis')
3/ created a product with sell price 10
4/ product page shows 12,10 as price (dev load shows 10), so VAT is added
5/ added 3 items to cart, the cart shows The discount, '2 + 1 gratis', was applied for a discount of 10,00€. (should be 12,10) while the cart line shows the price including VAT
6/ checkout
- shows price = 30, vat = 6,30, total = 36,30
- enter discount codes pane shows The discount, '2 + 1 gratis', was applied for a discount of 10,00€. (should be 12,10)
- order total preview pane shows
Order total preview:
Subtotal: 30,00€
Afhalen: 0,00€
Total discount: -10,00€
Subtotal excluding taxes: 20,00€
21% BTW: 6,30€ (should be 4,20)
Order total: 26,30€ (should be 24,20)
7/ checkout review shows
Subtotal: 30,00€
2 + 1 gratis: -10,00€
Afhalen: 0,00€
Subtotal excluding taxes: 20,00€
21% BTW: 6,30€ (should be 4,20)
Total: 26,30€ (should be 24,20)
8/ same results on store/orders/nid
I hope it helps, if not let me know
#4
screenies
#5
So the discount calculated by uc_discounts_alt is consistent, it just doesn't take into account VAT.
Since VAT is a tax, it seems like the VAT module should work like uc_taxes. In uc_taxes you can specify which line items each tax is applies to (it's a setting in each tax rule as "Taxed line items"). If the VAT module worked like uc_taxes, you would tell the VAT module to include "Discounts" line items in its calculations. Then VAT would be correctly calculate at 4,20 because it would add 21% to 20 (30 + -10).
Ask Longwave what he thinks about this. Thanks!
#6
The VAT module requires uc_taxes and uses the same calculations. However, the problem is that in European stores, the site must show tax-inclusive prices to the customer before checkout, so tax calculations have to be performed every time a product price is displayed. This means that any product discounts displayed on product pages or in the cart need to incorporate this same calculation.
As I said in #1, your module should call uc_price() instead of uc_currency_format() whenever it displays a price, which will do this calculation for you. This function was introduced in Ubercart 6.x-2.x-rc1. However, this function is more complex as it requires a 'context' parameter describing what the price is for, and the exact format of this is still being worked out in #475474: Price alterer contexts and VAT support. At present this will also require specific support in uc_vat depending on the 'location' contexts you use for discount prices, though I am hoping to avoid this by standardising the context parameter if possible.
#7
Actually, I'm not sure how this will work when discounts apply to multiple products. If you have a taxed product at $10 and an untaxed product at $10, then you give a $10 discount when both are purchased together, I'm not sure what the correct tax calculation would be in this case - if the discount is"buy X get Y free" then this is a different calculation to "$5 off each product". How does uc_discounts_alt currently handle this?
#8
As mentioned uc_discounts_alt doesn't call uc_currency_format or uc_price on an item's price because it never displays the price of an item.
With this module, discounts are applied to carts as a whole and not to individual products. This is the case even if the discount applies to a single product. This module adds a separate discount line item for each discount to adjust the total for the cart. So uc_discounts_alt will never change the price, sell_price, etc. of a product. This module may need to perform its calculations using an altered price in some future version but that's not what uc_price provides, right? Isn't uc_price is for showing strings to the user not for getting float price values?
#9
Hi,
I have this problem as well. I'm trying to use the VAT module for Australian GST.
I'm going to try and hack the module to get it to work for me. Has any work been done on this problem before I start?
It also shows as a problem on the product page. The discounted price shown for the product uses the price without GST as a starting point. Also I notice from a brief look at the code sometimes $product->price is used and sometimes $product->sell_price is this meant to be that way?
Thanks for your help. I'll let you know how I go.
Andrew
#10
I've created a patch that fixes the issues on the cart pane.
#11
Updated patches to match 6.x-1.0-beta36.
#12
We should definitely be vat-compatible.
Thanks for the re-roll. This no longer applies to 6.x-2.x. Could you please re-roll against the end of this branch, without the "patched_uc_discounts_alt" directory?
Thanks!
#13
Updated patches for 6.x-2.x-dev
#14
Thanks for the re-roll. This looks generally good though I'd like to do a bit of testing this week before committing.
#15
The Patch works for me - but there ist another problem with VAT for European Stores into the cart pane:
If you activate a percentage discount for the total order - the discount is calculated in the cart pane by subtotal without VAT.
In germany - like European Stores to - we need to calculate the discount for customers from the subtotal with VAT.
This example show what I mean:
you have a percent discount of 10% of Total Order.
The VAT for each product ist also 10%.
Product A and B costs each 10,- EUR without VAT and 11,-EUR incl. VAT
The customer see on the cart pane:
Product A 11,- EUR (incl. VAT)
Product B 11,- EUR (incl. VAT
Subtotal = 22,- EUR (incl. VAT)
If I activate a 10% discount to subtotal actually is following cart pane shown:
Product A 11,- EUR (incl. VAT)
Product B 11,- EUR (incl. VAT)
Subtotal = 22,- EUR (incl. VAT)
Discount= 2,- EUR (=> The Problem: The Discount is calculated from Subtotal without VAT)
Subtotal incl. Disount=20,- EUR (incl. VAT)
The correct Cart pane would be:
Product A 11,- EUR (incl. VAT)
Product B 11,- EUR (incl. VAT)
Subtotal = 22,- EUR (incl. VAT)
Discount= 2,20- EUR (=> 10% from Subtotal incl. VAT)
Subtotal incl. Disount=19,80 EUR
The checkout pane works correct and calculate the discount from the subtotal incl. VAT - if you apply VAT to discounts in the UC VAT Module.
#16
Thanks for the re-roll.
Based on the comment in #15, it seems like this needs work.
#17
There's another problem with the calculations when there're products in the order with different vat rates.
There's an option in the vat rate configuration form to include the discount line in that rate calculation. This is correct.
An example:
Price without vat: 100
vat 16%: 16
Price with vat: 116
Applying a 10% discount ->
Price without vat: 90
discount without vat: 10
vat 16%: 14,4
discount with vat: 11,6
Price with vat: 104,4
So, 116 - 11,6 = 104,4 that's correct
But, to include the calculations of the other vat rates in the discount line I need to check that option in the corresponding vat rate configuration form and then the module calculates the vat amount over the discount though there isn't any item of that kind in the order.
In a try to solve this with ca, I've added conditions to every vat rate that limits the product classes this calculation applies but it doesn't work as expected.
Example:
vat rate: 16% applied to products class A and discount line.
Conditional actions for 16%:
Conditions: Product is class A
Actions: Apply 16%
vat rate: 7% applied to products class B and discount line.
Conditional actions for 7%:
Conditions: Product is class B
Actions: Apply 7%
Order with:
1 x Product class A
Price without vat: 100
discount 10%: 10
New price without vat: 90
vat 16%: 14,4
Discount with vat: 11,6
Price with vat: 104,4
1 x Product class B
Price without vat: 2
No discount
vat 7%: 0,14
Price with vat: 2,14
Checkout:
Must be:
Subtotal: 118,14€ (vat incl.)
Total discount: -11,60€ (vat incl.)
Subtotal vat excl.: 92,00€
VAT 16%: 14,40€
VAT 7%: 0,14€
Order total: 106,54€
But, it shows:
Subtotal: 118,14€ (vat incl.)
Total discount: -12,30€ (vat incl.) (wrong!)
Subtotal vat excl.: 92,00€
VAT 16%: 14,40€
VAT 7%: -0,56€ (wrong!)
Order total: 105,84€ (wrong!)
Because it was calculating the 7% vat rate over the 10 € discount of product class A (0.7), too and substracting it from vat 7% (0.14) (0.14 - 0.7 = -0.56) and adding the 0,7 to the real discount of 11,6 (11,6 + 0,7 = 12,30)
The conditions in vat 7% conditional actions says that only must be calculated if product belongs to class B but this isn't taken into account.
#18
Hi,
Hi,
UC_discount_alt calculate the discount based on the Price exclusive of VAT .. instead to calculate on the price VAT inclusive.
Ex : I apply a 20% discount on the products.
Standard Price (16% of VAT included) : 100
Discounted price from uc_dicount_alt : 68,97€
REAL discounted price : 80 => that's what it should be.
Is there any patch to solve this? I did apply the patches #13, but I'm still facing the same problem.
Ubercart 2.2
UC_discount_alt 6.x-2.x-dev
UC_vat 6x-1.0
#19
Hi,
is there something new regarding this patch? It would be really great to have UC_discount_alt working correctly with VAT like in #17 from miguel_angel described.
Thank you in advance.
yours
ingolf
#20
subscribe
#21
Hi,
I also run into this problem. Has anything been made on this.
br,
gapa
#22
Just discovered this problem and have been working on it.
As far as I can see, the two remaining issues are:
1) The cart page discount total is incorrect (as it's still calculating before VAT is added) - but the checkout page has correct discount rates
2) Having multiple tax rates causes incorrect discount calculations. I replicated this problem, but haven't quite yet understood what is going wrong there.
Well I've fixed problem 1, I think. It basically needed a few changes to the get_discounts_for_order() function (just adding uc_price function where it was taking the sell price value).
I'm going to look into issue 2 tomorrow and hopefully fix that.
I'll come back soon with a patch, will need a bit of testing.
Thanks
Leon
#23
Right, I've got a patch which seems to be working okay for me for both issues.
One thing to note is that you need to de-select the discount line item on the tax rate page.
The reason for this is we don't want tax to be added to our discount, as we've already included the tax using the uc_price() function.
I've tested it with an order consisting of two items with different tax rates and discount rates applied.
ITEM 1
PRICE £6.04
TAX 17.5%
DISCOUNT 6%
QUANTITY 5
5 * (6.04 + 17.5%) = 35.49
Discount: 35.49 * 0.06 = 2.13
ITEM 2
PRICE £20
TAX 10%
DISCOUNT 50%
QUANTITY 3
3 * (£20 + 10%) = £66
Discount: 66 * 0.5 = £33
Subtotal: 35.5 + 66 = 101.5
Discount: 2.13 + 33 = 35.13
Order total: 101.5 - 35.13 = 66.37
This works for me.
Let me know if there's any probs. Also, I havent tested this out without using the vat module. It should work the same as uc_price() will then get the price exc tax, and you could tax the discount by selecting this line item on the tax admin page.
Thanks
Leon
#24
Hi,
Thank you so so much for this!
I had to manually patch this thing (probably because of different module version). I attached my patch if someone else will have this problem.
As far as I could test it it really works. :)
Do you maybe also know how to get products discounted prices into invoice? Couse products on invoice are displayed without discounted price.
thanks again and br,
gapa
#25
hi gapa,
On the invoice you get the items price and then the total discount below it, the same as on the cart and checkout review pages.
You want the item price to include the discount rather than listing them separately? Isn't that a bit misleading as you're not showing what the normal cost of the product was (plus losing the opportunity to show what the customer saved in discounts).
Anyway, the invoices are php files so I guess you could use the uc_price() method inside them to work out the discounted price.
#26
Maybe I forgot to mention that I would like to display both prices of a product. Original, and new discounted. So that customers could see on product basics how much they saved. And also if it is possible to calculate the difference between original and discounted price (you saved: price - discounted price).
This kind of functionality would also be great in product node. So the customers can see right away how much they would save if they bought the product. Also maybe with % display. So that they don't have to do the calculations for them self.
I will try to implement your idea into invoice. Is it also possible to use this idea (using uc_price) in template files node-product.tpl.php?
br,
gapa
#27
Thanks for the patches but, with both patches #23 and #24, I got the message:
patching file uc_discounts.module
Hunk #2 succeeded at 955 (offset 15 lines).
patch: **** malformed patch at line 56: @@ -1387,25 +1422,25 @@
Thanks
#28
I checked again my patch and i think i made a reverse. try again with this one.
#29
gapa,
this one worked
you saved my day, thank you!
#30
I found another error and I applied another patch. This should also correct "Subtotal including discounts:". Now it is displayed with VAT.
br,
gapa
#31
Hi Gapa,
Thanks for your update.
Can't imagine it has to do with the patch but for some reason the field discounted price disappeared.
#32
hello,
i'm having the same issues with VAT + uc_discount_alt
do i have to aplly all the patches, or just #30
is there a way someone could send me a patched version of the module that would work with VAT
i never could patch a module it always fails ...
thanks to all
#33
Hi Joachim
I attached the patched versions of uc_vat and uc_discount_alt.
As far as I can see so far it works as aspected.
Paul
#34
Hello,
thanks for the file
i updated the module (i sites/default/modules)with the ones you sent me
created a buy one get one free rule
ran cron, emptied caches
and it still calculates discount on VAT non inclusive price
did i forget something ?
see attached file
the website is here http://newsite.lefestin.net/node/802
you can try putting two items in the cart ....
is there a way to output something to see if it works ?
thanks
#35
i tried uninstalling the module
unchecked it in the module section, deleted the files, ran update.php
reinstalling it
upped the files you gave me, checked discount box in modules section.
my discount rules are still there
and it still isn't working :((((
#36
BTW : i'm working with three different taxe rate i don't know if this is what makes it uneffective
#37
i tried searching in the admin/store/settings/taxes page
i have three taxe rates one for books, one for magazines, and one for normal product
when in one taxe rate i check the taxable line item option "discount"
it works on checkout but not in the cart
if i check the taxable line item option "discount" on the second taxe rate
on checkout it outputs two taxes (see pic for discount checkboxes)
can anybody tell me what does the "taxable line item" do ? what are "empty line" and "taxe" options for ?
Is there a way to make this work ?
I feel i'm missing something
thanks to all
#38
Try deselecting the discount line item on the tax rate page. It is already mentioned in post #23. I don't have discount line in my setup and for me it works. Haven't yet tried your type of discount rule thou.
br,
Gapa
#39
Found another issue. In the attached picture you can see two product with same discount (50% off). Why are this two products rounded differently? If I divide original price (this is VAT inclusive) I get 2,295 and 3,755. As I can see this two are rounded differently. I also tried to do this calculation without VAT inclusive prices and I still get to same result.
I also am trying to get discounted price into invoice template. And as far as I could do I used this code to pass another parameter into ordered products. And "discounted_price" is 2.29 and 3.76. Why is this different than in product display page? I just can't figure it out. To be honest, I am not a coder so I don't understand completely how things works. Any help is welcome.
function uc_discounts_order($op, &$arg1, $arg2) {switch ($op) {
case "load":
//Get order's codes from database
$codes_string = uc_discounts_order_codes_get($arg1->order_id);
$arg1->uc_discounts_codes = get_codes($codes_string);
foreach ($arg1->products as $product) {
$item=node_load($product->nid);;
$discounts = get_codeless_discounts_for_product_and_quantity($item, 1);
//Sum discount amounts
$total_discount_amount = 0;
foreach ($discounts as $discount) $total_discount_amount += $discount->amount;
$product->discounted_price=$total_discount_amount;
}
break;
#40
hi gapa,
Sorry I havent been helping out with this that much since uploading the patch. I've had to stop work on it because it turns out the project I'm on never required the vat module anyway.
With the rounded prices, have you checked the original sell price? I think I saw this issue before, but found it was calculating the discount from the actual sell price, which is also rounded (separately) for the store. Does that make sense?
So say your second product that was rounding down (.5 should always be rounded up), the original sell price could have been 7.508, which would round correctly to 7.51 for the store and 3.75 for the discount.
As for the discounted prices showing on invoices, this should really be done with tokens. It's something I'm going to have to do myself pretty soon, when I do I'll submit a patch. If you want to do it yourself I would look into using hook_token_values(), or carry on using the code in the template (bit messy) as that seems to round correctly.
Thanks
Leon
#41
Thanks for answer leon.nk.
I will check rounding problem and report back what I will found.
As for invoice template. I don't know if tokens are meant to be used this way. Cause every product that would have discounted price should also have it's own token. Or did you have any other idea implementing this?
That's why I thought it would be best to attach discounted price to products that are in order. So I could go through order->products array and display original sell price and discounted price (if product has discounted price). And also total price without discount and total price with discounted price.
br,
gapa
#42
Hello,
I was reading this topic and I used your patches to correct the vat problems. I ran some tests for each kind of possible discounts.
So basically there are two categories : Qualif type = Price or Number and Discount Type = Percent Off, Fixed Amount Off, Fixed Amount Per Qualifying Item, Percent Per Qualifying Item and Free Items.
After testing, I understood what your patches fix but I found new issues which are :
- wrong discount calculation when Qualif type = Price and Discount Type = Fixed Amount Per Qualifying Item
$order_and_discount_product_ids = array_intersect($discount_product_ids, $order_product_ids);foreach ($order->products as $this_product)
if (in_array($this_product->nid, $order_and_discount_product_ids))
$discount->amount+=$this_product->qty;
$discount->amount*=$discount->discount_amount;
break;
instead of
$discount->amount = $discount->discount_amount * $order_qualifying_amount;break;
explanation : discount amount was calculated too quickly, should be $discount->discount_amount * the number of qualified items
- wrong discount calculation when Discount Type = Percent Off Per Qualifying Item
$this_product_price = get_uc_price($this_product);instead of
$this_product_price = $this_product->price;explanation : not using get_uc_price function
- not including VAT in price of free item(s) when Type = Free Items
$price_info = array(
'price' => $cheapest_product->price,
'qty' => 1,
);
$context = array(
'type' => 'cart_item',
'revision' => 'altered',
'subject' => array(
'cart_item' => $cheapest_product,
'node' => node_load($cheapest_product->nid),
),
);
//Add current discount amount to running total
$discount_amount += $discount_count * uc_price($price_info, $context);
instead of
//Add current discount amount to running total$discount_amount += $discount_count * $cheapest_product->price;
explanation : not using the get_uc_price technique to calculate the price of the free item(s) discounted
So I provide a patch which include all the previous modifications on the uc_discounts.module file (of this topic) and adding mines.
If I'm not wrong, only the change made in #13 have to be added, because not in the same module.
I would appreciate having feedback about this contrib because I'm not sure it's completely tested.
#43
I have looked at your patch and I think that it doesn't include your new patches. Could you please have another look at this?
br,
gapa
#44
You're right, my bad !
I changed it a little bit, using an .inc file containing the function get_uc_price() and allowing to use it with a quantity of 1.
So the functions.txt should be renamed in functions.inc and placed in sites/all/modules/includes/ (create it before).
I did that because a lot of modules don't handle the VAT issue and so need to call this function.
What do you think about that ?
I re attached the patch file, and this one should be complete.
#45
#46
Don't know why but the file uc_discounts.module.patch is missing (wrong link to file).
But don't know about functions.inc file. I have a feeling that this is not "drupal" way of handling things. But I am not an experienced drupaler so I will let others decide. My personal opinion is that it should stay in module itself. Other modules maybe want to calculate things differently.
br,
gapa
p.s.: do you maybe have an answer to my other problems discussed in posts #39,#40,#41
#47
Re uploading this *** patch :p
I don't know if it's the best way to share this function, I think the Drupal way is to create a module for this. But as it's a very basic function, I used this.
About your issues, I didn't get this problem yet but I will let you know...
#48
I have tested few examples (not all), and it works for me. I have also discovered what is with my question in post #39. I have found out how discounts get calculated. It is original price - discount. And if I calculate my numbers this way the results are correct.
br,
gapa
#49
Hi,
Sorry to be a pain but any chance somebody could post a patched version of this module. Having spent a few hours (as a non programmer) trying to work out how to apply a patch under windows (yep I should probably be running Linux, I'll get there one day) frustration is kicking in and i am getting no where. This might be a simple process for most people but not here, it would be a big help if I could just grab the already patched mod from somewhere and upload it.
Thanks a lot to anybody that can help, and to everybody for solving these issues.
Andy
#50
for anybody else wanting to apply a patch, using windows and not having a clue where to start, try using Tortoise SVN, it makes it very simple and is available here:
http://tortoisesvn.net/
and the instructions here meant even I managed to do it:
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-patch.html
hope this helps somebody else.
Andy
#51
I see these get_ucprice patches has been applied to the latest dev version of uc_discounts_alt - also VAT support "almost" works.
I tested on a test site - purchasing 3 items costing a 100 kr. (80 kr. without VAT) and a discount of 30 kr. if 3 is purchased.
The total became 270 - so that was correct, but the VAT amount was still 60 - it should have been 54 (the 6 deducted as the discount amount (30) is 24 + 6 in VAT).
#52
if I enable taxes on discount line item the VAT is correct - and the entered discount amount is taken as being excl. VAT (ie. to get a discount of 30 incl. VAT I need to enter 24).
Only issue is the places where it says what your discount is - it states this without VAT - (ie. 24) where it should say 30 - as that is what the customer actually saves.
I'm guessing the "your discount is" output is not run through uc_price ? (I'll have a look at the code and see).
#53
the patches with get_uc_price returns a price of 0.
I tried to fix it up - and the below works, except VAT is NOT applied. I can't seem to figure out why :(
function get_uc_price($item) {
$price_info = array(
'price' => $item->price,
'qty' => $item->qty,
);
$context = array(
'type' => 'cart_item',
'revision' => 'altered',
'field' => 'price',
'subject' => array(
'cart_item' => $item,
'node' => node_load($item->nid),
),
);
return uc_price($price_info, $context);
}
#54
btw. this is only needed in the cart pane - VAT is correctly done in the checkout section.
#55
I fixed it - you need to feed it a proper item - or perhaps try to change from cart_item to line_item - I haven't gotten line_item working yet though.
#56
I tried to get get_uc_price to check for an $item->nid, so that calls to get_uc_price with an $item object which has ONLY price and quantity (ie. discounts - ergo line_items) could be calculated as well.
But it doesn't add VAT to line_items and I can't seem to figure out what's missing from the line_item item (and yes - I have selected that Discounts (uc_discounts) be taxed in my tax rule.
If you have ideas - pls. put'em forward - otherwise you can just clone the last $item from the shopping cart and use that - that's what I do now. It is flawed though, as you might have a case where an $item is untaxable (or has a different tax - like books in Sweden, childrens clothing in UK etc.) and the line_item discount still should be taxed.
if ($item->nid) {
$context = array(
'type' => 'cart_item',
'revision' => 'altered',
'field' => 'price',
'subject' => array(
'cart_item' => $item,
'node' => node_load($item->nid),
),
);
}
else {
//This doesn't work - it is however how tax on discount line_items should be calculated
$line_item = new stdClass();
$line_item->type = 'uc_discounts';
$line_item->amount = $item->price;
global $user;
$order = new stdClass();
$order->uid = $user->uid;
$order->line_items[] = array( 'type' => $line_item->type, 'amount' => $line_item->amount);
$context = array(
'type' => 'line_item',
'revision' => 'altered',
'field' => 'price',
'subject' => array(
'order' => $order,
'line_item' => $line_item,
),
);
}
#57
+1 subscribing
Can we port a final version of all working patches from above that work with the current uc_vat dev, please?
#58
From this entire thread, I am under the impression that there is a version that actually solves the problem. But there is somehow no combined version available for download. So I assume that the problem isn't solved yet and that the patches are incomplete?
#59
The discounts and VAT support are a difficult problem to solve for all cases of use (and all countries).
Perhaps the solution is that any module that alters prices must have a price alterer function and find the right order to apply them.
Meanwhile, I've wrote a patch to uc_discounts_alt (6.x-2.x-dev 2010-Aug-24) that handles discounts in orders with mixed VAT rates.
The solution calling uc_price contributed in this thread doesn't work for me.
This patch creates a different line item per vat rate, so you can assign in VAT settings the right discount line item to each vat rate.
For this to work, the discounts created must no mix products of different vat rates.
You can have a vat rate for products class: A, B, C and discount line item "VAT rate 1"
other for products class: D, E and discount line item "VAT rate 2"
and a discount that qualify for products class A, B or C
other discount that qualify for products class D or E
but not discounts that qualify for products B or D, for example (due to different vat rates of B and D classes)
I've tested the patch with modules:
uc_vat, uc_taxes, uc_discounts_alt enabled
uc_vat, uc_taxes disabled and uc_discounts_alt enabled
uc_vat, uc_taxes enabled and uc_discounts_alt disabled
This isn't an elegant solution, but it works.
Please, feel free to try the patch and your feedback is welcome.
#60
Hi,
Can anyone please send me already patched files (uc_discounts.js and uc_discounts.module)?
It give me an error.
#61
@Peter76: Why would anyone send those patched files to you? Think broader, think about the community and ask to port those patches to dev. That way you will get your patched files, the rest of the community could test it and the maintainer will get more feedback.
#62
madjoe;
Yes you are right.
Can anyone port these parches to dev?
#63
@Peter76 I believe what @madjoe was getting at, is that this is a community project and the efforts of people like yourself could benefit everyone else.
So instead of waiting around for someone to make the patch for you. You could have taken the time to understand how to manually apply a patch. These patches were relatively small and would have been good experience for you. However, me being the nice guy that I am. I went ahead and created a new patch file for you.
I even took an extra step and hunted down a post here on Drupal.org that explains how you can help out by reapplying patches manually. Then all you would have to do is create a new patch file for everyone else to use.
Apply a patch file manually
Create a patch file
Apply a patch file
#64
davexoxide thank you very much.
#65
For testing, I've just checked out the latest release from the CVS head which appears to incorporate the above changes but I'm getting the following error code:
Fatal error: Call to undefined function uc_discounts_add_discount_rate_id() in /sites/all/modules/uc_discounts_alt/uc_discounts/uc_discounts.module on line 1448It would appear that 'uc_discounts.module' around line 1950 has some code which looks out of place and is effecting the function 'uc_discounts_add_discount_rate_id'.
I'm happy to post my copy 'uc_discounts.module' if that would help.
#66
Any help will be great, I tried to apply the patch above but realised that it was for an older version of the module - having issues myself with the discount calculating the pre-tax value, and also showing the subtotal excluding VAT on the shopping cart page.
Thanks!
#67
Hi all, I've just downloaded the 6.x-2.x-dev version of Ubercart Discounts (Alternative) and tried to manage a term based discount but occurred in the problem described here: the discount is applied before taxes, which is not correct here in Italy. Actually the taxes are managed correctly by Ubercart 2 VAT support module.
I've read the whole thread, even the links posted by davexoxide about patches, then tried to apply patches both manually and using the Eclipse tool, but it seems to me (consider that I'm not an expert), that the patches aren't suitable for current 6.x-2.x-dev release (like stated in the previous post too).
Is there any chance to port the fixes in the -dev version ?
#68
Hello,
i have a problem with a french site that is online and "working" :(
an acountant told me that the vat is not applied where it should be.
they sell magazine with a vat rate of 5,5%
in this example we have 2 discounts applied using uc_discount_alt, free shipping and 5% off
if i buy 2 magazines at 20 each i should have
total : 40
total HT excluded : 37,92
5% discount : 36,02
vat : 1,98
total to pay : 38
++
shipping : 2
free shipping : - 2
shipping has no vat in France
this is what i get on the site (attached file)
total : 40
5 % discount : - 1,90
shipping : 2
free shiping : - 2
total HT excluded : 36,01
vat : 2,09
total to pay :38,10
I first noticed that the rounding is not done on each articles but on both (36,02 - 36,01)
and the VAT is not correct, customer pay 10 cents more, because it has to be effective once the discounts have been applied (on the vat excluded price)
Is there a way i could change the workflow to have a correct sum ?
do i have to change something in the uc_vat module or in the uc_discount_alt module ?
Thanks to all for all the work
#69
To #68
Doing a manual patch (manual for search the strings to change) of uc_discounts.module and using code from #30 works for me.
uc_discounts.module is at: sites/all/modules/uc_discounts_alt/uc_discounts
Using 6.x-2.x-dev
#70
The same. #30 manualy applied patch works so far so good. And for product price altered field to display correct price it seems to help the following fix:
After applying the patch in uc_discounts.module in uc_discounts_get_discounted_price_for_product function
REPLACE: return $product->sell_price - $total_discount_amount;
WITH: return get_uc_price($product) - $total_discount_amount;
#71
There's still a problem with patch #30. The sub-total and total price is correct now, but if you enable "Show VAT amounts in separate columns at checkout." (admin/store/settings/taxes/vat) the VAT amounts ignore the discount(s).
Example and difference between uc_discounts_alt and uc_coupon (which has a special fix for uc_vat):
1 x Product (incl. 19% VAT) - 4,99 €
uc_coupon:
Sub-total: 4,99€
Coupon (20%): -1,00€
Shipping (incl. 19%): 5,95€
Total: 9,94€
incl. 19%: 1,59€
uc_discounts_alt:
Sub-total: 4,99€
20% discount: -1,00€
Shipping (incl. 19%): 5,95€
Total: 9,94€
incl. 19%: 1,75€
Now an example with two products and two different VATs:
Product-A (incl. 19% VAT) - 4,99 €
Product-B (incl. 7% VAT) - 29,00 €
uc_coupon:
Sub-total: 33,99€
Coupon (20%): -6,80€
Shipping (incl. 19% VAT): 5,95€
Total: 33,14€
incl. 7%: 1,52€
incl. 19%: 1,59€
uc_discounts_alt:
Sub-total: 33,99€
20% Discount: -6,80€
Shipping (incl. 19%): 5,95€
Total: 33,14€
incl. 7%: 1,90€
incl. 19%: 1,75€
As you can see everything except the VAT amounts are identical. The VAT amounts ignore the discounts in uc_discounts_alt. I think the solution can be found by looking in the last changes of uc_coupon, because they had the same problems before.
Update:
uc_vat supports a 'tax_adjustment' callback. Take a look into the 'uc_vat_line_item_price_alter' (uc_vat.module) function: $callback = _line_item_data($line_item['type'], 'tax_adjustment');
and uc_coupon registers that callback:
/**
* Implementation of hook_line_item().
*/
function uc_coupon_line_item() {
$items[] = array(
'id' => 'coupon',
'title' => t('Coupon discount'),
'tax_adjustment' => 'uc_coupon_tax_adjustment',
'weight' => 0,
'default' => FALSE,
'stored' => TRUE,
'add_list' => TRUE,
'calculated' => TRUE,
);
return $items;
}
#72
Subscribing
#73
hello,
I have tried many configuration, patches, modules versions ..etc and i just cannot get to the right calculations in the checkout. It's a shame because discounts are actually not usuable for European shops right now. At least I haven't found a solution.
I would be happy to sponsor a development to solve the problems between uc_vat and uc_discounts_alt
Contact me if you are interested.
#74
Same for me... unfortunately none of the solutions posted seem to work
#75
Hi!
This message is for all of you that say "it doesn't work".
My solution at #59 works for my particular case.
If it doesn't work for yours, please, give us information about your problem.
With more detailed information we can get an almost optimal solution.
Thank you.
#76
A three year old issue that has never been solved... such a shame!
@miguel_angel your patch in #59 ofcourse doesn't run against latest dev anymore. Have you ever updated to latest and do you have a new patch?
I'm also marking this as major. One of the reasons is mentioned by longwave in #6 and others after this, incorrect calculations make this module unusable for EU (and possibly other countries) web shops.
Pointed http://drupal.org/node/1330476 and http://drupal.org/node/824510 to this issue as I believe these are similar issues.
Cheers
#77
@Gapa, have tried your patch in #30 and it fixes part of it, but am still having some troubles;
My setup:
First I had some troubles with incorrect VAT calculations, possibly due to change in Ubercart 6.x-2.6, this was solved here http://drupal.org/node/1170992#comment-5536898
Then I noticed that discounts on both cart and checkout page were calculated based on sell price exclusive of VAT. Tried many things mentioned in this and other issues and many different settings but nothing worked.
/cart/checkout before patch:
Subtotal 23.68 (correct -> 19.90 incl 19% VAT)Shipping 8.03 (correct -> 6.75 incl 19% VAT)
Total discount 9.95 (should be 23.68 - 50% = 11.84)
Subt ex VAT 16.70 (correct -> 19.90 - 50% + 6.75)
VAT 19% 5.06 (should be 16.70 * 19% = 3.17)
Order total 21.76 (should be 19.90 - 50% + 6.75 + 19% = 19.87)
I have applied #30 by hand to UC Discounts Alt (6.x-2.4) and since then the discounts are correctly calculated after VAT has been applied. Yet the patch causes the subtotal exclusive of VAT and the VAT line to be incorrect. Seems like they don't know about the discounted prices.
Subtotal 23.68 (correct -> 19.90 + 19%)Shipping 8.03 (correct -> 6.75 + 19%)
Total discount 11.84 (correct -> 23.68 - 50%)
Subt ex VAT 14.81 (should be 19.90 - 50% + 6.75 = 16.70)
VAT 19% 5.06 (should be (19.90 - 50% + 6.75) * 19% = 3.17)
Order total 19.87 (correct -> 19.90 - 50% + 6.75 + 19%)
So partially there but no complete fix. Tried manually applying patches in #59 but they are based on the dev release from sept 2009 I believe so that's not really working out well.
Back to square one? Can't believe there isn't a live webshop out there that doesn't have uc_vat and uc_discount_alt combined which is working... can anyone who's got this working share a bit more info?!
Cheers
#78
Sorry, I changed to incorrect status.
Have done some more dubugging. I converted to UC Discounts Alt (6.x-2.4) without patch in #30 and I'm back to the results in the first code block in #77.
Now I went to my VAT setting admin/store/settings/taxes/1/edit and checked the 'discount' as a taxed line item. This resulted in a perfect calculation in the Order Total Preview pane on the checkout form;
Subtotal 23.68 (correct -> 19.90 + 19%)Shipping 8.03 (correct -> 6.75 + 19%)
Total discount 11.84 (correct -> 23.68 - 50%)
Subt ex VAT 16.70 (correct -> 19.90 - 50% + 6.75)
VAT 19% 3.17 (correct -> (19.90 - 50% + 6.75) * 19%)
Order total 19.87 (correct -> 19.90 - 50% + 6.75 + 19%)
The only issues remaining are the /cart page and the Cart Contents pane on the /cart/checkout page. The discount here is calculated based upon the sell price ex vat which is incorrect. Back to the drawing board!
For now I'm using uc_coupon which works fine but I'd like to switch to uc_discounts_alt!
Cheers