Skip to content

Commit 6ebddf5

Browse files
Calculate tax IDs when refunding items
1 parent 1575a13 commit 6ebddf5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/refunds/IssueRefundViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ class IssueRefundViewModel @Inject constructor(
539539

540540
// Update the subtotal and taxes based on the new quantity
541541
val subtotal = newItem.calculateTotalSubtotal()
542-
val taxes = listOf(TaxRefund(0L, newItem.calculateTotalTaxes()))
542+
val taxes = newItem.calculateTotalTaxes()
543543
newItem = newItem.copy(subtotal = subtotal, taxes = taxes)
544544

545545
newItems.add(newItem)
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.woocommerce.android.ui.payments.refunds
22

3+
import org.wordpress.android.fluxc.utils.sumBy
34
import java.math.BigDecimal
45
import java.math.RoundingMode.HALF_UP
56

@@ -8,7 +9,7 @@ fun List<ProductRefundListItem>.calculateTotals(): Pair<BigDecimal, BigDecimal>
89
var subtotal = BigDecimal.ZERO
910
this.forEach { item ->
1011
subtotal += item.calculateTotalSubtotal()
11-
taxes += item.calculateTotalTaxes()
12+
taxes += item.calculateTotalTaxes().sumBy { it.tax }
1213
}
1314
return Pair(subtotal, taxes)
1415
}
@@ -18,9 +19,12 @@ fun ProductRefundListItem.calculateTotalSubtotal(): BigDecimal {
1819
return quantity.times(orderItem.price)
1920
}
2021

21-
fun ProductRefundListItem.calculateTotalTaxes(): BigDecimal {
22+
fun ProductRefundListItem.calculateTotalTaxes(): List<TaxRefund> {
2223
val quantity = quantity.toBigDecimal()
24+
val taxes = orderItem.taxes
2325

24-
val singleItemTax = orderItem.totalTax.divide(orderItem.quantity.toBigDecimal(), 2, HALF_UP)
25-
return quantity.times(singleItemTax)
26+
return taxes.map {
27+
val tax = it.taxAmount.divide(orderItem.quantity.toBigDecimal(), 2, HALF_UP)
28+
TaxRefund(it.rateId, quantity.times(tax))
29+
}
2630
}

0 commit comments

Comments
 (0)