Skip to content

Commit 9a2ef7e

Browse files
authored
Merge pull request #14940 from woocommerce/fix/pos-historical-orders-remove-0-lines
[POS Orders] Hide lines with zero value
2 parents 8593c08 + c507227 commit 9a2ef7e

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosOrdersViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@ class WooPosOrdersViewModel @Inject constructor(
625625

626626
return OrderDetailsViewState.Computed.Details.TotalsBreakdown(
627627
products = formatPrice(order.productsTotal),
628-
discount = order.discountTotal.takeIf { it != BigDecimal.ZERO }?.let { "-${formatPrice(it)}" },
628+
discount = order.discountTotal.takeIf { !it.isZero() }?.let { "-${formatPrice(it)}" },
629629
discountCode = discountCode,
630630
taxes = formatPrice(order.totalTax),
631-
shipping = order.shippingTotal.takeIf { it != BigDecimal.ZERO }?.let { formatPrice(it) },
631+
shipping = order.shippingTotal.takeIf { !it.isZero() }?.let { formatPrice(it) },
632632
refunds = refundInfo.refundAmounts,
633633
netPayment = netPayment
634634
)
@@ -648,3 +648,5 @@ private fun Order.Status.localizedLabel(resourceProvider: ResourceProvider, loca
648648
Order.Status.Refunded -> resourceProvider.getString(R.string.woopos_orders_status_refunded)
649649
}
650650
}
651+
652+
private fun BigDecimal.isZero() = this.compareTo(BigDecimal.ZERO) == 0

WooCommerce/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,8 +3826,8 @@
38263826
<string name="woopos_orders_details_totals_title">Totals</string>
38273827
<string name="woopos_orders_details_qty_unit_price_format">%1$d x %2$s</string>
38283828
<string name="woopos_orders_details_breakdown_products_label">Products</string>
3829-
<string name="woopos_orders_details_breakdown_discount_label">Discount</string>
3830-
<string name="woopos_orders_details_breakdown_discount_with_code_label">Discount (%1$s)</string>
3829+
<string name="woopos_orders_details_breakdown_discount_label">Discount total</string>
3830+
<string name="woopos_orders_details_breakdown_discount_with_code_label">Discount total (%1$s)</string>
38313831
<string name="woopos_orders_details_breakdown_taxes_label">Taxes</string>
38323832
<string name="woopos_orders_details_breakdown_shipping_label">Shipping</string>
38333833
<string name="woopos_orders_details_total_label">Total</string>

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosOrdersViewModelTest.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,4 +844,57 @@ class WooPosOrdersViewModelTest {
844844
// THEN
845845
verify(ordersAnalyticsTracker).trackOrdersListSearchResultsFetched(any())
846846
}
847+
848+
@Test
849+
fun `given order with zero discount and zero shipping, when mapped, then discount and shipping are absent`() = runTest {
850+
// GIVEN
851+
val base = order(1)
852+
val withZeros = base.copy(
853+
discountTotal = BigDecimal("0.00"),
854+
shippingTotal = BigDecimal("0.00")
855+
)
856+
857+
// WHEN
858+
whenever(dataSource.loadOrders()).thenReturn(
859+
flow { emit(LoadOrdersResult.SuccessRemote(ordersMap(withZeros))) }
860+
)
861+
862+
viewModel = createViewModel()
863+
advanceUntilIdle()
864+
865+
// THEN
866+
val content = viewModel.state.value as WooPosOrdersState.Content
867+
val breakdown = content.selectedDetails.breakdown
868+
assertThat(breakdown.discount).isNull()
869+
assertThat(breakdown.shipping).isNull()
870+
}
871+
872+
@Test
873+
fun `given order with non-zero discount and shipping, when mapped, then discount and shipping are formatted`() = runTest {
874+
// GIVEN
875+
val base = order(2)
876+
val withValues = base.copy(
877+
discountTotal = BigDecimal("3.50"),
878+
shippingTotal = BigDecimal("4.00")
879+
)
880+
881+
// WHEN
882+
runBlocking {
883+
whenever(formatPrice.invoke(BigDecimal("3.50"))).thenReturn("$3.50")
884+
whenever(formatPrice.invoke(BigDecimal("4.00"))).thenReturn("$4.00")
885+
}
886+
887+
whenever(dataSource.loadOrders()).thenReturn(
888+
flow { emit(LoadOrdersResult.SuccessRemote(ordersMap(withValues))) }
889+
)
890+
891+
viewModel = createViewModel()
892+
advanceUntilIdle()
893+
894+
// THEN
895+
val content = viewModel.state.value as WooPosOrdersState.Content
896+
val breakdown = content.selectedDetails.breakdown
897+
assertThat(breakdown.discount).isEqualTo("-$3.50")
898+
assertThat(breakdown.shipping).isEqualTo("$4.00")
899+
}
847900
}

0 commit comments

Comments
 (0)