Closed (fixed)
Project:
Commerce VAT
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 May 2014 at 10:13 UTC
Updated:
21 Jan 2021 at 10:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
geek-merlinPatch flying in.
Comment #2
geek-merlinYups, that's the right patch.
Comment #3
geek-merlinComment #4
geek-merlinComment #5
periksson commentedIn my case this is what happened:
1. The first rate was calculated and applied (25%)
2. The second rate was calculated and applied (12%). At the same time the previous rate was recalculated and reduced (22 cents disappeared).
I solved it with the following patch:
Comment #6
AnssiH commentedThe function commerce_vat_commerce_line_item_rebase_unit_price() (which handles updating the components when existing line item price is modified) also needs to be updated for this proportional calculation model. Marking as Needs work.
(Note that rebasing is currently broken in other unrelated ways and requires the patch from #2237853: VAT not applied if order is changed in backend)
@nwpullman2, Can you provide the price of the item and the tax values you got and what you expected? As far as I can see, it is expected that the previous tax component gets reduced:
1. Starting base price 100 EUR.
2. 25% applied => Base price 80 EUR, 25% tax = 20 EUR.
3. 12% applied => Base price 71.43 EUR, 25% tax = 17.86 EUR, 12% tax = 10.71 EUR.
With these values, the taxes match: 25% tax is on top of untaxed price: 71.43 * 0.25 = 17.86. 12% tax is on top of the previous total: (71.43+17.86) * 0.12 = 10.71 EUR.
With your change AFAICS the end result would be base 69.29 EUR, 25% = 20 EUR, 12% = 10.71 EUR, which doesn't add up properly - the 25% is calculated on top of Base+12% and the 12% tax is calculated on top of Base+25% - but one of the taxes should be calculated based on the base price.
But maybe I misunderstood, so an example would be helpful :)
Comment #7
czigor commentedWorks for us. Will get back here as soon as we are in production with this.
Comment #8
czigor commentedNote for self: this patch is needed to because in case of a discount/giftcard line item the 0th price component (base_price) is 0 so we want to alter the 1st price component (which is discount|something or giftcard).
Comment #9
czigor commentedA small fix to the patch. In case we have more than one vat components on a line item (which happens for coupons when using https://www.drupal.org/project/commerce_vat_proportional) we don't want to apply vat on a vat component.
Which is the same issue as #5 and #6 if I get it correctly.
Comment #10
czigor commentedAdding a check if there was a nonzero component at all to prevent some notices.
Comment #11
thepanz commentedUpdated patch: avoid division by zero
Comment #12
czigor commentedThanks for the catch! The patch in #11 changes the formula though. But I'd rather return early instead anyway.
Comment #13
czigor commentedThe interdiff.
Comment #14
dwkitchen commented