-
Notifications
You must be signed in to change notification settings - Fork 137
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
[Woo POS][Non-Simple Products] Remove null price check on Products and Variations screen #13312
Conversation
# Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #13312 +/- ##
============================================
- Coverage 41.10% 41.09% -0.01%
+ Complexity 6421 6417 -4
============================================
Files 1321 1321
Lines 77177 77176 -1
Branches 10643 10645 +2
============================================
- Hits 31722 31718 -4
Misses 42646 42646
- Partials 2809 2812 +3 ☔ View full report in Codecov by Sentry. |
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.
Works well, @AnirudhBhat! Please take a look at a few code improvement ideas I left.
@@ -12,6 +12,7 @@ sealed class WooPosTotalsViewState : Parcelable { | |||
val orderTaxText: String, | |||
val orderTotalText: String, | |||
val readerStatus: ReaderStatus, | |||
val isFreeOrder: Boolean, |
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.
💡 The UI doesn’t really care if the order is free; it only cares whether the reader status is shown or hidden. The state model would be cleaner and more readable if, instead of adding an isFreeOrder property to WooPosTotalsViewState, we changed ReaderStatus to reflect when we don’t want it displayed.
For example, we could add a data object Hidden: ReaderStatus() subclass, rather than relying on WooPosTotalsViewState.isFreeOrder. This approach would also simplify the UI code. What do you think?
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.
💡 It would also be great to add a unit test for orders that include only free products.
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.
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.
After thinking more about this, I feel adding a new Hidden
status to readerStatus
field:
- Introduces complexity in managing a Hidden status, as it’s an artificial state not tied to the actual reader.
- Requires careful handling in the
WooPosTotalsViewModel
to ensure the Hidden status transitions correctly, especially when toggling between free orders and paid orders. - Complicates UI logic to correctly display the cash payment screen when the card reader UI is hidden.
We could probably rename isFreeOrder
into shouldShowReaderStatus
. WDYT?
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.
Feel free to take the approach you think is best 👍
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.
if (cardReaderFacade.readerStatus.value is Connected) { | ||
if ( | ||
cardReaderFacade.readerStatus.value is Connected && | ||
dataState.value.orderTotal?.compareTo(BigDecimal.ZERO) == 1 |
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.
💡 I suggest using >
and <
operators directly improve code readability.
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.
I believe this approach won't work in all cases when dealing with BigDecimal, because these operators internally rely on the exact scale of the BigDecimal values during comparisons. For example:
If totalAmount is BigDecimal("0.00"), it may not behave as expected when compared to BigDecimal.ZERO using > or <, as the comparison might fail due to scale differences.
Using .compareTo(BigDecimal.ZERO) is more robust because it ignores scale differences and focuses solely on the numerical value, ensuring consistent behaviour regardless of how totalAmount is constructed (e.g., 0.00 vs. 0).
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.
I believe this approach won't work in all cases when dealing with BigDecimal, because these operators internally rely on the exact scale of the BigDecimal values during comparisons.
💡 I think this is not true, according to docs:
All comparisons are translated into calls to
compareTo
, which is required to return Int.
As a result, using comparison operators translates to the same call to the compareTo()
function that is used currently.
You can verify that by CMD-clicking the comparison operator (>
) – it will redirect to the underlying compareTo
function implementation in Kotlin std lib.
I suggest using comparisons like that:
dataState.value.orderTotal?.compareTo(BigDecimal.ZERO) == 1 | |
dataState.value.orderTotal!! > BigDecimal.ZERO |
which compiles to:
dataState.value.orderTotal!!.compareTo(BigDecimal.ZERO) > 0
Let me know what you think or if I'm missing something @AnirudhBhat.
💡 Another improvement would be to add a null check (throw IllegalStateException in case orderTotal
) instead of allowing such illegal state in code (comparing potentially null value which will result in NPE thrown from compareTo
function anyway, but throwing it earlier would make potential bug easier to debug).
…te appropriately.
… state appropriately.
Closes: #13293
Description
This PR removes null price filtering we've had for some time on client side. Since we have decided to allow free products to be displayed on POS, we are allowing products whose price are not set to be allowed to display as well considering those to be free products.
Along with this, this PR also hides card payment screen on checkout if the cart items contain only free products.
discussion: p1736504688523299/1736484154.214279-slack-C070SJRA8DP
Steps to reproduce
Empty price
Zero price
Checkout screen for free products
Checkout screen for non-free products
The tests that have been performed
Tested the above scenarios
Images/gif
free_products.mp4
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: