Skip to content

[Refunds] Fix taxes handling #14064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: issue/WOOMOB-394-refunds-networking-update
Choose a base branch
from

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented May 14, 2025

Closes: WOOMOB-395

Description

This PR builds on top of the previous PR to fix the issue of tax refunding, as for now, we weren't handling it correctly.
This PR updates the logic of the refunding to handle splitting the taxes refund according to each item taxes.

Important: There is a discrepancy between the taxes array that each order line returns, and the total_tax, the total_tax is rounded, while the values in the array are raw. Initially, I wanted to avoid making any calculations on client side, and drop the amount argument from the API call, but I noticed an issue where the refunds could have less amount that the total order amount, so for now, we'll still send the amount, and its value will still use the total_tax for calculation (this matches iOS behavior too).
This issue will become problematic when we try to add support for partial refunds, I asked about it here p1747301522966739-slack-C07JJG089M0, and depending on the response, I'll document the next steps.

Steps to reproduce

  1. Enable tax calculation on your store.
  2. Add multiple tax rates (make sure to assign different priorities so that they all get used for calculation).
  3. Create an order.
  4. Go to the app and refund the order.

Testing information

  • Confirm refunding works as expected.
  • Check wp-admin and confirm taxes were correctly refunded (as shown in the screenshots below)

The tests that have been performed

^

Images/gif

Before After
Screenshot 2025-05-15 at 14 50 23 Screenshot 2025-05-15 at 14 51 01
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@hichamboushaba hichamboushaba added type: bug A confirmed bug. type: technical debt Represents or solves tech debt of the project. feature: refunds Related to order refunds. labels May 14, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 14, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit43f4448
Direct Downloadwoocommerce-wear-prototype-build-pr14064-43f4448.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 14, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit43f4448
Direct Downloadwoocommerce-prototype-build-pr14064-43f4448.apk

@hichamboushaba hichamboushaba force-pushed the issue/WOOMOB-394-refunds-networking-update branch from 0de75f6 to fe84ddb Compare May 14, 2025 18:13
@hichamboushaba hichamboushaba force-pushed the issue/WOOMOB-395-fix-tax-refunding branch 2 times, most recently from bbdea1f to a215e0b Compare May 15, 2025 13:33
The `taxes` array returned by the API includes raw taxes, not rounded, while the `total_tax` property is using rounded values, and this leads to some inconsistencies for calculating the amount when using them, so for now, we calculate the total amount using `total_tax` in the ViewModel.
@hichamboushaba hichamboushaba changed the title Issue/woomob 395 fix tax refunding [Refunds] Fix taxes handling May 15, 2025
@hichamboushaba hichamboushaba marked this pull request as ready for review May 15, 2025 16:11
) : Parcelable {
val availableRefundQuantity
get() = maxQuantity.toInt()
sealed class RefundItem : Parcelable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactoring is not really needed for this PR, but it will be useful for a future refactoring of the IssueRefundViewModel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: refunds Related to order refunds. type: bug A confirmed bug. type: technical debt Represents or solves tech debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants