Skip to content

Commit 884c020

Browse files
biplab1niyajali
authored andcommitted
refactor(feature:client): merge ViewModels, add charge validation, fix empty chargeOptions crash (openMF#2430)
Co-authored-by: Sk Niyaj Ali <niyaj639@gmail.com>
1 parent 21908ae commit 884c020

9 files changed

Lines changed: 333 additions & 292 deletions

File tree

core/model/src/commonMain/kotlin/com/mifos/core/model/objects/template/client/ChargeOptions.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import kotlinx.serialization.Serializable
2020
@Serializable
2121
@Parcelize
2222
data class ChargeOptions(
23-
val id: Int,
24-
val name: String,
25-
val active: Boolean,
26-
val penalty: Boolean,
27-
val currency: Currency,
28-
val amount: Double,
29-
val chargeTimeType: ChargeTimeType,
30-
val chargeAppliesTo: ChargeAppliesTo,
31-
val chargeCalculationType: ChargeCalculationType,
32-
val chargePaymentMode: ChargePaymentMode,
33-
val incomeOrLiabilityAccount: IncomeOrLiabilityAccount,
23+
val id: Int? = null,
24+
val name: String? = null,
25+
val active: Boolean? = null,
26+
val penalty: Boolean? = null,
27+
val currency: Currency? = null,
28+
val amount: Double? = null,
29+
val chargeTimeType: ChargeTimeType? = null,
30+
val chargeAppliesTo: ChargeAppliesTo? = null,
31+
val chargeCalculationType: ChargeCalculationType? = null,
32+
val chargePaymentMode: ChargePaymentMode? = null,
33+
val incomeOrLiabilityAccount: IncomeOrLiabilityAccount? = null,
3434
) : Parcelable

feature/client/src/androidMain/kotlin/com/mifos/feature/client/clientCharges/ClientChargesScreen.android.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ actual fun ClientChargeContent(
5858
icon = MifosIcons.Payments,
5959
)
6060
} else {
61+
// Use a composite key of id and index to guarantee uniqueness,
62+
// preventing LazyColumn crashes when duplicate ids are present in paged data.
6163
LazyColumn {
6264
items(
6365
chargesPagingList.itemCount,
64-
key = { index -> chargesPagingList[index]?.id ?: index },
66+
key = { index ->
67+
val id = chargesPagingList[index]?.id
68+
if (id != null) "id_${id}_index_$index" else "index_$index"
69+
},
6570
) { index ->
6671
chargesPagingList[index]?.let { ChargesItems(it) }
6772
}

feature/client/src/commonMain/composeResources/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<string name="feature_client_charge_name">Charge Name</string>
5858
<string name="feature_client_charge_amount">Amount</string>
5959
<string name="feature_client_due_date">Due Date</string>
60+
<string name="feature_client_charge_invalid_amount_format">Invalid amount format</string>
6061
<string name="feature_client_no_more_charges_available">No More Charges Available!</string>
6162
<string name="feature_client_failed_to_load_more_charges">Failed to load more Charges</string>
6263

0 commit comments

Comments
 (0)