-
Notifications
You must be signed in to change notification settings - Fork 136
[POS Orders] Fetch refunds remotely if not stored locally #14915
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
[POS Orders] Fetch refunds remotely if not stored locally #14915
Conversation
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
| import javax.inject.Inject | ||
|
|
||
| /** | ||
| * Use case that retrieves all refunds for the given [Order]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: I’m not sure how much value this comment currently adds, as it simply translates to the English code below. However, if the implementation changes in the future, the comment is likely not to be updated and may actually confuse the code reader rather than clarify it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's remove it. I wanted to add information that it's not explicitly stated in the API, but the code is indeed sufficiently clear to obtain that info from there. Done in d6b20cd
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
kidinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@toupper I think we cannot release it like that. Currently, even if all goes well, it can take up to 30 seconds to load the refunds, and all this time an order selection is blocked. Here is a video where I added a 5s delay to WooPosRetrieveOrderRefunds
11-06--15-40.mp4
One option is that we have to have both loading and error states for the details part of the screen. And load or fetch refunds and products for an order when selected.
Another option would be to fetch all the refunds in parallel for all the orders right after a page of orders is fetched. Assuming that most of the orders won't have refunds, maybe this is an even better option.
Also, what we should consider. To show product images, we get products from the in-memory cache right now. But if the store has more than 200 products, then a product may not be in memory, and we'll try to fetch it from the backend as well (WooPosGetProductById) causing the same issue as with the refunds right now. So if we go with the option 2 we'd need to fetch them along with the refunds.
Wdyt?
…historical-orders-show-refunds-net-payment
|
@toupper I played with this and here is the patch: I decided to not touch the products as:
|
|
Thanks for the patch and adding more context @kidinov! I applied and adapted tests. Please take another look |
|
|
||
| private suspend fun mapOrderDetails(order: Order): OrderDetailsViewState.Computed.Details = coroutineScope { | ||
| val statusText = order.status.localizedLabel(resourceProvider, locale) | ||
| // inside WooPosOrdersViewModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: what is this comment about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I removed it in 76683f1
kidinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! There is a comment that is not clear if it was intended to be placed, though.
8834f98
into
fix/pos-historical-orders-fixes-for-beta
Description
With this PR we fix the case when we were not showing refunds in the POS Orders Details screen if they were not shown locally. To fix this, we fetch them remotely if that is the case.
Decisions
I decided to keep fetching refunds synchronously within the order details flow. While this may occasionally delay rendering when a remote fetch is needed, it simplifies the implementation and ensures consistent, complete order details without extra state handling. If we don’t want to block order-details rendering on a possible remote refund fetch, then we need to separate “build the details” from “enrich the details with refunds.” Happy to hear your thoughts on this one.1. Simplicity matters right now. Your ViewModel is already doing a lot (search, pagination, selection, mapping, analytics). If we start doing “show details first, then patch in refunds,” we add another update path to the already big state machine.2. Refunds are a special case. Most orders won’t have refunds (refundTotal == 0), and you already short-circuit those. So the “slow” path only happens on refunded orders — acceptable.3. Consistency > speed (for details). Order details is the kind of screen where people expect numbers to match. Loading everything in one go guarantees the breakdown, refunds, and net payment are in sync.4. You can always optimize later. If QA or users report “refunded orders open slowly,” then we do the split: local details first, then enrich with refunds. That refactor is easy because the logic is already isolated in a use case.Update: Blocking UI is not acceptable. See below for further discussion.
refundTotal == 0guard insideWooPosRetrieveOrderRefundsrather than at the call site. This makes the use case responsible for deciding when refund retrieval is relevant and avoids redundant calls to the store or network for non-refunded orders, simplifying usage for callers.~~Test Steps
Images/gif
Screen_Recording_20251111_152529_Woo.Dev.mp4
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.