Skip to content

[WOOMOB-2397][POS Refunds M2] Part 1: Refunded items data layer#15488

Merged
samiuelson merged 13 commits intotrunkfrom
woomob-2397-data-layer
Mar 9, 2026
Merged

[WOOMOB-2397][POS Refunds M2] Part 1: Refunded items data layer#15488
samiuelson merged 13 commits intotrunkfrom
woomob-2397-data-layer

Conversation

@samiuelson
Copy link
Copy Markdown
Contributor

@samiuelson samiuelson commented Mar 5, 2026

Description

Adds data layer support for refunded line items in POS order details. This is the first of two PRs for WOOMOB-2397.

Changes:

  • Introduce LineItemsState sealed interface (Loading/Loaded) for line items in order details state
  • Add refundedLineItems field to order details
  • Extract WooPosGetNonRefundedItems use-case for filtering out fully refunded items
  • Extract WooPosGroupRefundedItems use-case for aggregating refund data per order item
  • Wire new use-cases into WooPosOrderDetailsMapper and WooPosOrdersViewModel

Functional change: refunded products are now now shown inside Products section in POS Order Details. They are going to be shown in a dedicated Refunded Products section instead.

Testing instructions

  1. Open POS and complete an order
  2. Navigate to order details - products should display correctly
  3. Issue a partial refund, return to order details
  4. Verify the data loads without issues (UI for refunded items section will come in PR 2)

💡 To test the feature E2E, check out the final PR: #15489

Images/Gif

N/A (data layer only, no visual changes)

Introduce LineItemsState sealed interface to support loading/loaded
states for line items. Add WooPosGetNonRefundedItems and
WooPosGroupRefundedItems use-cases, wire them into
WooPosOrderDetailsMapper and WooPosOrdersViewModel.

Includes minimal UI adaptation for the new LineItemsState type.
@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented Mar 5, 2026

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@samiuelson samiuelson changed the title Add refunded items data layer for POS order details [WOOMOB-2397][POS Refunds M2] Part 1: Refunded items data layer Mar 5, 2026
@samiuelson samiuelson requested a review from Copilot March 5, 2026 18:02
@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Mar 5, 2026

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

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Build Number731
Version24.2.1
Application IDcom.woocommerce.android.prealpha
Commita73c3fa
Installation URL275d4g7d3plfg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

This comment was marked as off-topic.

@samiuelson samiuelson requested a review from Copilot March 6, 2026 14:11
@samiuelson samiuelson added this to the 24.4 milestone Mar 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

samiuelson and others added 6 commits March 6, 2026 15:17
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
When mapOrderDetailsWithoutActions sets lineItems to Loading for orders
with refunds, sideLoadBookings early-returns. After sideLoadActions
replaces lineItems with Loaded, booking side-loading was never retried.
The copy() was inheriting price from items.first() which doesn't match
the aggregated total/quantity. Now recomputes price = total / quantity.
Aligns with buildRefundedLineItems which already passes order.currency
to formatPrice for consistency.
…ed items

Zero-quantity items with no refunds are now preserved instead of being
filtered out. Also uses BigDecimal math (multiply then divide) instead
of Float division for proration to avoid precision loss.
@samiuelson samiuelson requested a review from malinajirka March 6, 2026 15:16
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 56.00000% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.55%. Comparing base (e370be1) to head (a73c3fa).
⚠️ Report is 423 commits behind head on trunk.

Files with missing lines Patch % Lines
...oid/ui/woopos/orders/details/WooPosOrderDetails.kt 0.00% 38 Missing ⚠️
.../android/ui/woopos/orders/WooPosOrdersViewModel.kt 25.00% 9 Missing and 6 partials ⚠️
.../woopos/orders/details/WooPosOrderDetailsMapper.kt 80.76% 2 Missing and 8 partials ⚠️
.../woopos/orders/details/WooPosGroupRefundedItems.kt 87.50% 1 Missing and 1 partial ⚠️
...woopos/orders/details/WooPosGetNonRefundedItems.kt 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #15488      +/-   ##
============================================
+ Coverage     39.52%   39.55%   +0.03%     
- Complexity    11203    11220      +17     
============================================
  Files          2250     2252       +2     
  Lines        129313   129413     +100     
  Branches      18091    18115      +24     
============================================
+ Hits          51115    51195      +80     
- Misses        72987    72992       +5     
- Partials       5211     5226      +15     

☔ 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.

@malinajirka malinajirka self-assigned this Mar 9, 2026
Copy link
Copy Markdown
Contributor

@malinajirka malinajirka left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

.fold(0) { acc, item -> acc + item.quantity }

return order.items.mapNotNull { item ->
val refundedQty = abs(refundedByItemId[item.itemId] ?: 0).toFloat()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❓ If quantity can be negative, shouldn't we invoke abs inside the fold on line 19 instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a73c3fa, thanks.

@samiuelson samiuelson merged commit 969ebd6 into trunk Mar 9, 2026
16 checks passed
@samiuelson samiuelson deleted the woomob-2397-data-layer branch March 9, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants