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

Merged
merged 10 commits into from
Jun 5, 2025
Merged

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
Commit9ba4f9d
Direct Downloadwoocommerce-wear-prototype-build-pr14064-9ba4f9d.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
Commit9ba4f9d
Direct Downloadwoocommerce-prototype-build-pr14064-9ba4f9d.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 3 times, most recently from a215e0b to 73219b5 Compare May 15, 2025 13:51
@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.

@hichamboushaba hichamboushaba added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label May 27, 2025
@JorgeMucientes JorgeMucientes self-assigned this May 28, 2025
Copy link
Contributor

@JorgeMucientes JorgeMucientes left a comment

Choose a reason for hiding this comment

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

Nicely done @hichamboushaba the changes look good and work as described.

Base automatically changed from issue/WOOMOB-394-refunds-networking-update to trunk June 5, 2025 10:01
@hichamboushaba hichamboushaba added this to the 22.6 milestone Jun 5, 2025
@hichamboushaba hichamboushaba removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Jun 5, 2025
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 force-pushed the issue/WOOMOB-395-fix-tax-refunding branch from 43f4448 to 9ba4f9d Compare June 5, 2025 10:08
@hichamboushaba hichamboushaba enabled auto-merge June 5, 2025 10:09
@hichamboushaba hichamboushaba merged commit 2711d98 into trunk Jun 5, 2025
18 checks passed
@hichamboushaba hichamboushaba deleted the issue/WOOMOB-395-fix-tax-refunding branch June 5, 2025 10:37
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 73.62637% with 24 lines in your changes missing coverage. Please review.

Project coverage is 37.71%. Comparing base (742e877) to head (9ba4f9d).
Report is 11 commits behind head on trunk.

Files with missing lines Patch % Lines
...otlin/com/woocommerce/android/model/OrderMapper.kt 36.36% 0 Missing and 7 partials ⚠️
...org/wordpress/android/fluxc/store/WCRefundStore.kt 0.00% 7 Missing ⚠️
...rce/android/ui/payments/refunds/RefundsUiModels.kt 87.50% 5 Missing ⚠️
...main/kotlin/com/woocommerce/android/model/Order.kt 83.33% 2 Missing ⚠️
.../network/rest/wpcom/wc/refunds/RefundRestClient.kt 0.00% 2 Missing ⚠️
...ndroid/ui/payments/refunds/IssueRefundViewModel.kt 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14064      +/-   ##
============================================
+ Coverage     37.68%   37.71%   +0.03%     
- Complexity     8885     8896      +11     
============================================
  Files          1951     1951              
  Lines        108870   108899      +29     
  Branches      14232    14239       +7     
============================================
+ Hits          41031    41076      +45     
+ Misses        64094    64072      -22     
- Partials       3745     3751       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

4 participants