Can't distinguish two taxes of different percentages in the order summary

Created on 24 May 2017, over 7 years ago
Updated 15 November 2024, 2 months ago

An order with two order items. One is taxed using the Standard rate (French VAT, for example), the other is taxed using the Reduced rate. The order summary will show two rows both labelled "VAT".

The TaxOrderProcessor needs to detect this situation (count the occurrence of adjustments with the same label but different source IDs), and when detected, add the used percentage, so that we get something like:
VAT - 19%
VAT (19%)
19% VAT
We need to decide which one is preferable.

My current idea for getting the used percentage is to have LocalTaxTypeBase append it to the source ID.

🐛 Bug report
Status

Needs review

Version

3.0

Component

Tax

Created by

🇷🇸Serbia bojanz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    Just ran into the same requirement! Even if only one tax is used, it would be super helpful to show the vat rate used for information and easier review.

    We'll have a look at this soon to push things forward.

  • First commit to issue fork.
  • 🇩🇪Germany Grevil

    Main branch was way too far behind. Created a new 3.0.x branch and manually applied changes by @attisan.

  • 🇩🇪Germany Grevil

    grevil changed the visibility of the branch 2881056-make-tax-label-themable to hidden.

  • Pipeline finished with Success
    2 months ago
    Total: 617s
    #342306
  • 🇩🇪Germany Grevil

    The new twig template is quite different from the original one. I'll adjust this accordingly.

  • 🇩🇪Germany Grevil

    Adjusted accordingly.

  • Pipeline finished with Success
    2 months ago
    Total: 1023s
    #342339
  • 🇩🇪Germany Anybody Porta Westfalica

    I've hidden the patches to focus on the MR now and get this fixed! :)

  • 🇮🇱Israel jsacksick

    I disagree with this approach... I think perhaps it'd be better to introduce an event from the OrderTotalSummary service, and have the Tax module react to it. From there we could alter the adjustment label to include the tax percentage.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @jsacksick we'll implement that as separate MR tomorrow. Having the VAT rate shown is definitely a big win!

  • 🇩🇪Germany Grevil

    grevil changed the visibility of the branch 2881056-make-tax-label-themable-3.0.x to hidden.

  • 🇩🇪Germany Grevil

    Alright, all done. Ready for review!

  • Pipeline finished with Canceled
    2 months ago
    Total: 420s
    #343312
  • Pipeline finished with Success
    2 months ago
    Total: 620s
    #343326
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @grevil! LGTM and seems to do what @jsacksick suggested?
    I only had a little docs comment, everything else seems fine to me.

    Could you post a screenshot with the result?

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Grevil

    Here is a screenshot (although in german and using a custom theme, but anyway):

  • 🇮🇱Israel jsacksick

    Hm... I think we need to fix the naming as well...

    Maybe OrderSummaryBuildTotalsEvent? (a bit wordy though). But just BUILD_TOTAL could confuse people and they'd be under the impression that the event is dispatched when the order total is recalculated.

    The event constant should probably be OrderEvents::ORDER_SUMMARY_BUILD_TOTALS.
    Also, the alteration should probably only be done for VAT adjustments... So probably makes sense to do this only if the adjustment is included? (as VAT is always included).
    Also, the way it is currently done makes the label untranslatable...

    It should be something like:

    $this->t('@zone_display_label (@percentage%)', [
            '@percentage' => Calculator::multiply($adjustment['percentage'], '100'),
          ]);

    Or maybe we keep the original label just like you did if we can't easily get the zone display label.
    Also, just so you know, I'd like to wait for feedback from other people that previously contributed here before moving forward with this.

  • 🇩🇪Germany Grevil

    Also, the alteration should probably only be done for VAT adjustments... So probably makes sense to do this only if the adjustment is included

    This is already the case, as we are checking the adjustment type in modifyAdjustmentsLabels. Or am I misunderstanding you here?

    It should be something like:

    $this->t('@zone_display_label (@percentage%)', [
    '@percentage' => Calculator::multiply($adjustment['percentage'], '100'),
    ]);

    Not quite sure what the zone display label is here?

  • Pipeline finished with Success
    2 months ago
    Total: 797s
    #343505
  • 🇮🇱Israel jsacksick

    @grevil: Checking the adjustment type isn't sufficient, there is also the Sales tax scenario and other taxes as well.

  • Pipeline finished with Success
    2 months ago
    Total: 861s
    #343556
  • 🇩🇪Germany Grevil

    @jsacksick but wouldn't it be always preferable to have the tax percentage displayed on adjustments of type "tax"?

  • 🇩🇪Germany Anybody Porta Westfalica

    Looks like we need some more fine-graded number formatting:
    e.g. 0.09975 * 100
    https://git.drupalcode.org/project/commerce/-/blob/3.0.x/modules/tax/src...

    So that the number is formatted correctly.

  • 🇩🇪Germany Grevil

    Looks like we need some more fine-graded number formatting:
    e.g. 0.09975 * 100

    Alright, should be fixed now using the commerce price calculator (as @jsacksick already mentioned in #53 🐛 Can't distinguish two taxes of different percentages in the order summary Needs review anyway).

    Back to needs review!

  • Pipeline finished with Success
    2 months ago
    Total: 576s
    #346882
  • 🇮🇱Israel jsacksick

    @grevil: Perhaps we need to allow resetting the whole array? And not just adjustments? I mean, can't really think of a usecase altering the subtotal or total... But I guess it doesn't hurt?

  • 🇩🇪Germany Grevil

    Alright, done!

    I implemented it, so that the subtotal and total is only overwritten for the "buildTotals" array, meaning that $order->getSubtotalPrice() and $order->getTotalPrice() will have the unmodified value set.

  • Pipeline finished with Success
    about 2 months ago
    Total: 706s
    #351761
  • 🇩🇪Germany Grevil

    Static patch for the time being.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @grevil! Works great and as expected so far!!

  • 🇮🇱Israel jsacksick

    @grevil: My suggestion from #59 was to pass the whole array to the subscriber, so it can easily be read / altered. Eventually, additional data could be injected for use in a custom template as well.

    So perhaps a getTotals() and a setTotals() helper as opposed to getters / setters for the subtotal & total.

    In any event, as mentioned on Slack, I'd like to get feedback from the community on this considering 3-4 different approaches have been previously implemented here.

  • 🇩🇪Germany Grevil

    Alright, we now pass the whole array!

  • Pipeline finished with Success
    about 2 months ago
    Total: 817s
    #353096
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇮🇱Israel jsacksick

    @anybody: you mean RTBCED by your company :), as mentioned, waiting for other community members to chime in here, especially the ones that contributed patches previously. But from a pure code point of view, this looks good now (as I wanted it to look at least).

  • 🇩🇪Germany Anybody Porta Westfalica

    @jsacksick yes, but there's no option for that. Waiting longer without active people here won't help much I think? The world moves on and Drupal needs to do the same...

    But yes of course always important to have as much feedback as possible. Having this RTBC'd doesn't mean will be accepted immediately by maintainers. Thanks :)

  • 🇮🇱Israel jsacksick

    There is 2 remaining problems with the MR though. The event dispatcher has a NULL default value. We shouldn't make it optional, or we should conditionally dispatch the event.
    Also, I think the label alteration makes the label untranslatable.

    $adjustment['label'] = $originalLabel . ' (' . $taxPercentage . '%)';

    So perhaps a translatable string here with a context? commerce_tax? t('@label (@tax_percentage%')); or something similar.

  • 🇩🇪Germany Anybody Porta Westfalica

    So perhaps a translatable string here with a context? commerce_tax? t('@label (@tax_percentage%')); or something similar.

    Definitely +1 thanks for the feedback!

  • 🇳🇱Netherlands megachriz

    I see that on a site where I had this issue I'm still using the solution in #7.

    I do plan to try to update that site to as much D11 compatible releases as possible, so perhaps I can test the changes from this issue along with it. But no promises, I noticed that when I tried to do composer update now, quite a few patches could no longer be applied. It depends on how much time it will take to update these if there will be any time left to look at this issue.

  • 🇩🇪Germany Grevil

    Back to NW based on #68

  • 🇩🇪Germany Grevil

    Alright, adjusted accordingly, thanks for the feedback @jsacksick!

  • Pipeline finished with Success
    about 2 months ago
    Total: 848s
    #356519
  • Pipeline finished with Success
    21 days ago
    Total: 162s
    #384013
  • Pipeline finished with Failed
    18 days ago
    Total: 753s
    #386399
  • Pipeline finished with Failed
    18 days ago
    Total: 406s
    #386409
  • Pipeline finished with Success
    18 days ago
    Total: 834s
    #386413
  • Pipeline finished with Skipped
    13 days ago
    #391210
Production build 0.71.5 2024