Skip to content

Commit 0de75f6

Browse files
Ensure refunds are cleared from DB after refresh
1 parent 0578165 commit 0de75f6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCRefundSqlUtils.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ object WCRefundSqlUtils {
2020
fun insertOrUpdate(site: SiteModel, orderId: Long, data: RefundResponse) =
2121
insertOrUpdate(site, orderId, listOf(data))
2222

23+
fun deleteRefunds(site: SiteModel, orderId: Long) {
24+
WellSql.delete(RefundBuilder::class.java)
25+
.where()
26+
.equals(WCRefundsTable.LOCAL_SITE_ID, site.id)
27+
.equals(WCRefundsTable.ORDER_ID, orderId)
28+
.endWhere()
29+
.execute()
30+
}
31+
2332
fun insertOrUpdate(site: SiteModel, orderId: Long, data: List<RefundResponse>) {
2433
data.forEach { item ->
2534
val json = gson.toJson(item)

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WCRefundStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class WCRefundStore @Inject constructor(
116116
return@withDefaultContext when {
117117
response.isError -> WooResult(response.error)
118118
response.result != null -> {
119+
WCRefundSqlUtils.deleteRefunds(site, orderId)
119120
WCRefundSqlUtils.insertOrUpdate(site, orderId, response.result.toList())
120121
WooResult(response.result.map { refundsMapper.map(it) })
121122
}

0 commit comments

Comments
 (0)