Provide an administrative taxes page on the order

Created on 13 January 2023, almost 2 years ago
Updated 7 February 2023, almost 2 years ago

Currently there is no administrative display of detailed tax information on an order. We see a summary on the order admin page but there's no breakdown about individual items, shipping taxes, etc.
Additionally after an order has been placed there is no way for an administrator to force recalculation of taxes after editing an order.

Situations taxes would need to be recalculated:
Shipping/billing address changed/corrected
Line items added, deleted, quantity changes
Shipments added or deleted

While an automated process would be nice it's really difficult to get right, especially if multiple changes are happening to an order. We need a button to trigger tax recalculation.

Other tax modules could hook this form to add more controls or trigger additional actions like sending transaction adjustment data to a tax provider when this button is clicked.

✨ Feature request
Status

Active

Version

2.0

Component

Tax

Created by

πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

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

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    While that would be nice to have, it's outside of the scope of this issue. There is no recalculation functionality at all in commerce after order placement and this issue aims to add that. After this is done site builders could either create their own event subscribers to do what they feel is right for their store.

  • Status changed to Needs review over 1 year ago
  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    Thank you for the patch, it works like described and re-calculates the taxes. The only problem I've got is "Access Denied" for `/admin/commerce/orders/{commerce_order}/taxes` page because in patch #2 there is no access control requirement. The new patch has access control with new permission.

  • πŸ‡ΊπŸ‡ΈUnited States lisastreeter

    This seems like it should be a custom solution. I don't know that every Drupal Commerce website would necessarily want an admin "Taxes" form for Orders. At the very least, you need to check that Commerce Tax is installed, as it's optional.

    I'd need to use an alter hook to remove this new tab/page, if committed. We already have custom code to automatically recalculate taxes as needed for administrative updates. And we have an admin form for overriding the automatically calculated tax amount. This extra page would just cause confusion for our admin users.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    This is entirely contained in the tax submodule. It wouldn't appear unless the tax module was installed.

    This is needed functionality. You've implemented it yourself. Initially the only use case I could think of was a place to view tax breakdown but the ability to edit taxes manually would be good to have too.

    This issue is certainly open to suggestions on style of implementation. If not a tab, what else would you suggest?

  • πŸ‡ΊπŸ‡ΈUnited States lisastreeter

    @rhovland so sorry I missed that all this was within the tax module! Just plain dopiness on my part.

    We use Commerce Avatax for tax calculations with customizations. And then we use order refresh for updating orders that have been placed--so taxes and everything else that gets processed during order refresh are automatically calculated. Administrative users never need to trigger any recalculations manually. Any updates they're allowed to make to placed orders (item quantity updates, additional, removals, shipping method changes, etc.) trigger order refresh. I just have this line of code before order saves in various places:
    $order->setRefreshState(OrderInterface::REFRESH_ON_SAVE);

    For overriding tax, we set a "tax_override" value in the order data. There's a custom order operation that links to a custom form, only available for default-type orders that are not-yet-completed. The main reason for the operation vs. a tab is that the Order tabs all correspond to things our admins should be routinely doing for all orders: View, Edit, Items, Shipping, WBC Sync, and Payments. Tax overrides should be rare so better to make it a little more difficult to find.

    The custom form makes an api call to Avalara to get the standard tax rate based on shipping address. The form allows admin users to enable/disable the override, enter the desired tax amount and specify the reason for the override from a list of "tax status" options (provided by our accountants.) On submission, if an override is enabled, a new locked adjustment is added to the order. (Pre-existing tax adjustments are removed.) All updates are logged with custom commerce-log templates.

    Elsewhere, the order "tax_override" data value is checked to prevent application of avatax values.

    I'm always happy to share any custom code I have; I just generally assume that much of what I'm doing is fairly specific to the Drupal Commerce website I'm working on. I am working on putting together a personal website with more generalized versions of custom code solutions relevant to Drupal Commerce sites. "Tax overrides" is one of the topics on my to-do list (assuming it doesn't become part of Core Commerce anytime soon...)

    Here are some screenshots, if you're interested. (The form has some custom "order alert" messages displayed at the top that are visible on every administrative order page.)

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    Part of why I made it manual was so there was a way to recalculate taxes that didn't depend on an order refresh. If stores wanted to do it automatically then they could do it in a module. In our case we absolutely do not want order refresh to ever happen after an order is placed so triggering that is undesirable.

    So if I understand right your main contention is that it's a tab on the order and feel a taxes form should be accessed differently. On the order list action button is a good place to have a link to it. What if you're on the order and want to administrate taxes? I can't think of any UI other than a tab or a button to get to the form from the order page. Would an action button be better than a tab?

    As for the actual form page, it sounds like we're more or less on the same page where it's a place to get current up to date taxes and possibly modify them. The bare bones provided by commerce solution should be a button to calculate taxes since commerce by default does not refresh the order after it's placed. If someone is creating a module to implement automatic recalculation or what not then they can modify the form to delete the manual button.

    In our implementation we also use avatax, and we have an additional checkbox on the form that determines if an adjustment should be sent to avatax and added a function to the avatax module that does that.

  • πŸ‡ͺπŸ‡ΈSpain henkpotman

    The patch #6 is working fine for regular order created in the store by customers.

    However for admin created orders the patch does not seem to work. I don't know if there is a solution for this situation. I our store we get frequently phone calls from customers and admins have to create orders manually.

  • There is definitely something needed here in the UI.

    I think this would be better to:

    • Add this on the edit_form so that it doesn't clutter up the canonical.
    • Also, maybe links.action instead of tasks.
    • Also, maybe make use of ContentEntityConfirmFormBase

    I added this functionality to my site by adding a links.action to the order edit_form.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    Yeah the UI is definitely borne out of my ability level. Ideally tax information would be displayed on the order view screen and there would be a recalculate taxes button there.

  • My mention of need in the UI was that it's needed in Commerce. That comment was not meant to be a critique of the patch. πŸ˜‰πŸ‘

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Looks very helpful and totally makes sense to me. I agree that the "Recalculate Tax" button might be the MVP.
    Maybe proceed in a MR here against 3.x for easier review and testing?

Production build 0.71.5 2024