[Woo POS][Refunds] Allow adding refund reason#15173
Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
…nds-allow-adding-a-refund-reason-while-creating-a
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Pull request overview
This PR adds functionality to the WooCommerce POS refund flow that allows users to add an optional refund reason. Users can click "Edit reason" (or "Add") on the review refund screen to enter a reason, which is then passed to the refund store when confirming the refund.
Key Changes:
- Added refund reason state management with edit/save/cancel operations
- Created a new full-screen reason entry interface with keyboard focus
- Refactored event handling in the ViewModel for better organization
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| WooPosRefundUIEvent.kt | Added four new UI events for handling refund reason editing (EditReasonClicked, SaveReasonClicked, CancelReasonEditClicked, OnRefundReasonChanged) |
| WooPosRefundState.kt | Added refundReason and isEditingReason properties to Content state with appropriate defaults |
| WooPosRefundViewModel.kt | Refactored event handling into separate methods and integrated refund reason into the refund creation flow |
| WooPosRefundReasonScreen.kt | New composable screen for entering/editing refund reason with auto-focus and keyboard support |
| WooPosIssueRefundDialog.kt | Integrated reason screen as an overlay, added Edit reason button with accessibility support, and removed placeholder reason text |
| WooPosRefundViewModelTest.kt | Added comprehensive tests for reason editing state transitions and refund creation with/without reason |
| strings.xml | Added four new string resources for refund reason UI elements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Outdated
Show resolved
Hide resolved
...mmerce/src/test/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModelTest.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosIssueRefundDialog.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundReasonScreen.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #15173 +/- ##
============================================
- Coverage 38.67% 38.66% -0.02%
- Complexity 10534 10537 +3
============================================
Files 2193 2194 +1
Lines 124768 124847 +79
Branches 17251 17267 +16
============================================
+ Hits 48257 48267 +10
- Misses 71630 71700 +70
+ Partials 4881 4880 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Version |
| handleDismiss() | ||
| } | ||
|
|
||
| Box(modifier = Modifier.fillMaxSize()) { |
There was a problem hiding this comment.
Why is this box needed here?
| } | ||
| val stateSnapshot = state | ||
| if (stateSnapshot is WooPosRefundState.Content && stateSnapshot.isEditingReason) { | ||
| WooPosRefundReasonScreen( |
| val formattedTotal: String, | ||
| val paymentMethod: String, | ||
| val refundReason: String = "", | ||
| val isEditingReason: Boolean = false, |
There was a problem hiding this comment.
Having a boolean variable like that doesn't make the code look better - one more reason to have the reason as a separate screen that returns a result back.
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundState.kt
Show resolved
Hide resolved
kidinov
left a comment
There was a problem hiding this comment.
I left a couple of questions, and I noticed a few things, which could be due to WIP, but just letting you know:
- The loading dialog fills all the screen and is even partially hidden below the bottom system bar
- There is no animation between sizes of the dialogs - check how it's done on the barcode scanner setup flow
- There is no animation of the opening of the full "reason" screen, so it doesn't match with cash and email screens, which visually are the same. Overall, we animate from left to right when we go somewhere.
- Even if it will be decided to keep this link like based approach "edit/add reason" button, we at least can make the whole refund reason row clickable to make it easier to use
01-09--15-52.mp4
...ommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundReasonScreen.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModelTest.kt:482
- This test verifies that the step changes correctly when navigating back, but it doesn't verify that the refundReason is preserved during this navigation. Consider adding an assertion to verify that the refundReason remains unchanged after navigating back to SelectItems, especially since users may have entered a reason before navigating back. This would ensure the refund reason isn't accidentally lost during navigation between steps.
fun `given content state at ReviewRefund step, when BackToSelectItemsClicked event, then step changes to SelectItems`() =
runTest {
// GIVEN
val refundableItems = listOf(testRefundableItem)
whenever(ordersDataSource.refreshOrderById(testOrderId)).thenReturn(Result.success(testOrder))
whenever(retrieveOrderRefunds.invoke(testOrder)).thenReturn(Result.success(emptyList()))
whenever(getRefundableItems.invoke(any(), any())).thenReturn(refundableItems)
viewModel = createViewModel()
advanceUntilIdle()
viewModel.onUIEvent(WooPosRefundUIEvent.ContinueToReviewClicked)
val reviewState = viewModel.state.value as WooPosRefundState.Content
assertThat(reviewState.step).isEqualTo(WooPosRefundState.Content.RefundStep.ReviewRefund)
// WHEN
viewModel.onUIEvent(WooPosRefundUIEvent.BackToSelectItemsClicked)
// THEN
val updatedState = viewModel.state.value as WooPosRefundState.Content
assertThat(updatedState.step).isEqualTo(WooPosRefundState.Content.RefundStep.SelectItems)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...rce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundReasonNavigation.kt
Outdated
Show resolved
Hide resolved
...rce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundReasonNavigation.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosIssueRefundDialog.kt
Show resolved
Hide resolved
…efund-reason-while-creating-a

WOOMOB-1775
Figma: DK955L5K0bTfkjrHTBLmqo-fi-315_28376
Description
This PR adds the possibility to add a refund reason when creating a refund in POS. Additionally, it adds support for handling system back press.
💡 The UI was made consistent with
WooPosEmailReceiptScreen. That's reason why some details from Figma were omitted, e.g. redundant X button.💡 Do not merge until parent branch is
trunk.Test Steps
Images/gif
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.