Closed (won't fix)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Price
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
5 Dec 2011 at 23:36 UTC
Updated:
1 Feb 2015 at 15:19 UTC
Jump to comment: Most recent
Comments
Comment #1
geek-merlini think there are at least two directions out of this
* add some price component like "included-vat" which is *not* added but only displayed
* configurable increased precision, which might also solve problems like "a screw for 1,39 cent" or "a liter gas for 123,9 cent"
Comment #2
rszrama commentedAnd you aren't inputting prices including VAT in this case? Is there any reason why? Also, the point of rounding is configurable; perhaps adjusting the rounding option for your tax rate can yield a better result? At the end of the day, increasing a value by an odd percentage is often going to result in an odd final value. Including VAT in the price itself is the only reliable way to make sure it is the desired number.
Comment #3
geek-merlinright now i don't see how i (using tax module)
* input prices including vat *and*
* diplay vat separately
Comment #4
rszrama commentedWhat do you mean by "display vat separately"?
Comment #5
geek-merlin* shopadmin enters price 100€ including vat for a cam
* customer buys this cam
* checkout and invoice tell us:
* cam 84,03€
* vat 15,97€
* total 100,00€
Comment #6
geek-merlinlooks to me like the rules-action 'Apply a tax rate to a line item'
might need an option "tax included" for this
commerce_tax_rate_apply($tax_rate, $line_item)
http://drupalcode.org/project/commerce.git/blob/refs/heads/7.x-1.x:/modu...
Comment #7
rszrama commentedWhat you're describing should be the default behavior. Can you take a screenshot of it where it's not working as you expect?
Comment #8
geek-merlinwhat i find here as behaviour
(if that does not clarify i can provide screenshots):
(in both examples set 19% vat)
* shopadmin enters price 100€ for a cam
* customer buys this cam
* checkout and invoice tell us:
* cam 100,00€
* vat 19,00€
* total 119,00€
so it's about "price including vat" (which should be possible too) and "price excluding vat" (which is what tax module apperently does and is a good behaviour in many cases)
Comment #9
rszrama commentedOk, on the product edit form, there should be a select list beside the price field that lets you input the product price including VAT. This will make it work as you're expecting, with the order totals area showing the VAT split out from the product price for a grand total of 100€.
See for example:
Comment #10
geek-merlinEDIT: didn't get this is already implemented - read #13
yes, i think this would do the trick for most cases.
i agree this should go into the product form.
i think i don't agree this should tell us "hey, i calculate tax now, not later".
i think commerce_tax_rate_apply() should still calculate tax on checkout, *but differently*
(i think it is clear how this has to work when tax is included)
why?
* i think it is most elegant
* consider a situation where tax changes
or do i miss something?
Comment #11
geek-merlinhmm, just wondering why tax calculation is in code and not a rules component ;-)
(didn't check if the rules-price api would allow that)
Comment #12
geek-merlinwhat is said in #9 in fact works for normal products.
in my case i have customizable products with a dynamic price (set by rules).
Comment #13
rszrama commentedAhh, ok, I was wondering why you weren't seeing this. The screenshots I showed above are working right now; those are from a clean installation of Commerce. The calculation has to happen differently in code because it happens when the product is loaded and performs an inverse calculation at that point in time to separate the tax out of the base price. This is different from normal pricing; entering a price including VAT essentially functions as if there were a tax calculation Rule with no conditions always being executed first. It could be that we just need an action to set a price including VAT, which could solve this entirely for you, no?
Comment #14
geek-merlin> It could be that we just need an action to set a price including VAT, which could solve this entirely for you, no?
yes, that would in fact make my day.
>The calculation has to happen differently in code because it happens when the product is loaded and performs an inverse calculation at that point in time to separate the tax out of the base price. This is different from normal pricing; entering a price including VAT essentially functions as if there were a tax calculation Rule with no conditions always being executed first.
ok, i get the idea.
still think what i outlined in #10 would be superior in terms of elegance and flexibility and good architecture.
dont want to force anyone to spend time on that, but if i find time to roll an experimental patch, would you find time to consider it?
Comment #15
rszrama commentedSure, but you might actually want to evaluate other issues that deal with removing price components from a price. The problem is that if your tax calculation doesn't happen, the amount entered in the database is going to still be the full amount including VAT. So, whether you do the inverse tax calculation or not, the price of the product will be the price as entered (i.e. 10 €). I think what you really want is to have access to the price excluding VAT, right? In that case, we'd first need to do the inverse calculation so we know how much to remove.
Comment #16
rszrama commentedGoing to close this now unless there are follow-up things to pursue. I don't know of any actual tax rounding problems, just better support that we need for VAT, which is coalescing around the http://drupal.org/project/commerce_eu_vat project.
Comment #17
dwkitchen commentedI mused have missed this issue being closed and I am re opening it as the bug still exists.
The Commerce EU VAT module suffers from this issue exactly as described.
* a net price of 13,50 € results in 14,44 € (incl. 7% vat)
* a net price of 13,51 € results in 14,46 € (incl. 7% vat)
You can't have a gross price of 14,45 €.
I can't find a separate issue about increasing the accuracy for storing and calculating price data but still displaying in the standard accuracy
Comment #18
rszrama commentedThere is no issue (for 1.x at least) to increase the computational precision while retaining a smaller display precision. However, what I find odd about this example is that 13.5 * 1.07 rounds up to 14.45. I don't know how you're getting to 14.44 unless you've opted to round the half down. (And fwiw, I just confirmed that it goes to 14.45 on a clean install of Kickstart 1.x.)
That said, this issue has been discussed elsewhere, which is why it was undoubtedly closed here. (There was about a year's lack of activity on this at the time I closed it.) The summary if I recall is that there isn't a bug here, just a desire for different functionality. Right now we support either 1) entering a product price including VAT (which gets you any precise amount but makes it harder to discount / show the price w/o tax - there are other issues for those feature requests) or 2) adding the VAT via Rules (which makes it impossible to arrive at certain desired prices depending on the tax rate).
As far as I can tell, the code is working fine as is - i.e. there's no bug in what we offer, it just doesn't do what some users want - conditional VAT but the ability to input a price with a desired "final purchase price" including VAT. My recommendation in the past has been for a contributed module to be developed to handle that in 1.x, and then in 2.x when we up our storage / computational precision and separate that from our display precision, it may become a non-issue.
Such a contributed module basically needs to know how to accept a desired target price, associate that with a tax rate, store in the price field the actual product price excl. VAT, and then know that when a VAT is applied to a price that it should use the target price and reverse calculate the base_price / VAT price components instead of trying to calculate it with the typical multiplication. It's non-trivial, which is why we haven't pursued adding such a feature to core.
Comment #19
joachim commented> 1) entering a product price including VAT (which gets you any precise amount but makes it harder to discount / show the price w/o tax - there are other issues for those feature requests) or 2) adding the VAT via Rules (which makes it impossible to arrive at certain desired prices depending on the tax rate).
It's a while since I was working on this, but IIRC, neither of those are viable if your store needs to support different VAT rates. Which in the UK at least, happens as soon as you want to sell children's clothes, for instance -- so not that rare a use case surely.
Comment #20
rszrama commentedI think you'd need to tease that out a little further - different VAT rates... for different products? different customers? Either way, though, as I mentioned after this, the as of yet unsupported feature would be "conditional tax rates where store owners won't to specify pricing including VAT" (acknowledging that Commerce must still store price excluding VAT in the event that taxes are conditionally applied to products).
Comment #21
dwkitchen commentedRyan, I was trying to help someone on IRC today with this problem.
The maths in commerce is not as simple, and here is a correct example:
Thus you cannot calculate a sales price of 24.99 with a VAT rate of 20%.
As joachim says (1) entering a product price including VAT, is not viable if you also need to support selling outside of the EU or Intra-community reverse charge.
The way this is calculated is prices are rounded up and VAT is rounded down so:
I suppose there could be a tax fudge tick box on the product that deducts 0.01 from the VAT amount when required. Looks like this will need to be a custom tax rate calculation callback.
Comment #22
dwkitchen commented#1970882: Fix for imposible prices including tax
Comment #23
geek-merlinRyan said in #18:
> There is no issue (for 1.x at least) to increase the computational precision while retaining a smaller display precision.
So let's document this here.
I did not test this yet but do we talk about something like this:
?
Comment #24
dwkitchen commentedHow about something like this:
This would allow you to still have multi currency and use the same callback.
This could still lead to some odd rounding issues when adding up the line items to get the order total.
I will test as this could be a much better solution than my current one in Commerce VAT.
Comment #25
dwkitchen commentedSo giving this some testing this comes back to all the lots of issues around external APIs. Particularly payment gateways who expect an amount at the correct number of decimal places.
Having checked some would cope with this as one I have worked on requires two decimal places on all currencies it supports.
commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code)Could result in 15.5 so I use
number_format($amount, 2, '.', '')to get 15.50. This would also cover the 15.551 problem, but wouldn't respect commerce currency rounding settings.There are many other issues that this has with calculation of totals when adding up 100s of orders as the rounding will be off when they are aggregated.
This does give further thoughts on what we need from price storage and calculation in Commerce 2.x though. Have a look at #1125706: Price Implementation for Commerce 2.x
Comment #26
lmeurs commentedI shared a solution similar to #23 and #24 at #2125611-4: VAT rounding flawed in some countries to overcome VAT rounding differences. axel.rutz pointed me at #25 of this issue that other contribs (especially payment gateways) might not handle a different number of decimals very well.
@dwkitchen: Could you elaborate on which other modules did not cope well with different amounts of decimals?
We use the Payment Commerce module which converts the integer amount to a float and sends this float (with any amount of decimals) to a payment processing module (in our case the commercial Rabobank Omnikassa, also by Xano) which formats the amount according to the payment provider's requirements. So in our case a custom amount of decimals fortunately appeared to work out of the box, as probably with all other Payment modules will. I suppose the problem lies within payment gateways written especially for Commerce which assume integers based on certain amounts of decimals.
This could be circumvented if a payment gateway offers a hook to alter payment data right before they get sent to the payment provider (as ie. the Rabobank Omnikassa and Ogone modules do offer). We could add two custom options to ie. the Euro currency which has 2 decimals by default:
decimals(default option): amount of decimals used for storage and calculations, ie. 4 for more precise calculations.decimals_display(custom option): amount of decimals to display using a custom implementation of commerce_currency_format(), ie. 3 for products that are ordered in large quantities.decimals_official(custom option): used by alter hooks to format amounts before they get sent to the payment provider to meet their requirements, for Euro's this is 2.As long as payment gateways (start) offer(ing) alter hooks, I think a contrib module could handle this.