Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
[FEATURE] Added a $MONTH variable to ta recurring monthly payment (#3215
Browse files Browse the repository at this point in the history
)

* [FEATURE] Added a $MONTH variable to ta recurring monthly payment

* [FEATURE] Issue 3209, Changes made to take care timezone and TransactionMetaData

* [FEATURE] Issue 3209, Detekt and Lint Updates

* [FEATURE] Issue 3209,Unit test updates

* Add Compose Stability baseline

* Update Screenshots for Paparazzi tests

* [FEATURE] compose stability baseline file addition

* [FEATURE] Checking for compose stability

* [FEATURE] Checking for compose stability

* [FEATURE] Paparazzi update

* [FEATURE] Naming conventions, unnecessary UI Spacing, Paparazzi screenshot updates
  • Loading branch information
rishi2062 authored May 31, 2024
1 parent 5eb0e0d commit 2ca6117
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ com.ivy.design.utils.keyboardVisibleState
com.ivy.legacy.ivyWalletCtx
com.ivy.legacy.rootView
com.ivy.legacy.rootActivity
com.ivy.legacy.ui.component.transaction.getTransactionDescription
com.ivy.legacy.rootScreen
com.ivy.frp.view.FRP
com.ivy.wallet.ui.theme.pureBlur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class EditTransactionViewModel @Inject constructor(
private val description = mutableStateOf<String?>(null)
private val dateTime = mutableStateOf<LocalDateTime?>(null)
private val dueDate = mutableStateOf<LocalDateTime?>(null)
private val paidHistory = mutableStateOf<LocalDateTime?>(null)
private val date = MutableStateFlow<LocalDate?>(null)
private val time = MutableStateFlow<LocalTime?>(null)
private val accounts = mutableStateOf<ImmutableList<Account>>(persistentListOf())
Expand Down Expand Up @@ -373,6 +374,7 @@ class EditTransactionViewModel @Inject constructor(
dateTime.value = transaction.dateTime
description.value = transaction.description
dueDate.value = transaction.dueDate
paidHistory.value = transaction.paidFor
val selectedAccount = accountByIdAct(transaction.accountId)!!
account.value = selectedAccount
toAccount.value = transaction.toAccountId?.let {
Expand Down Expand Up @@ -578,6 +580,7 @@ class EditTransactionViewModel @Inject constructor(
syncTransaction = false
) { paidTransaction ->
loadedTransaction = paidTransaction
paidHistory.value = paidTransaction.paidFor
dueDate.value = paidTransaction.dueDate
dateTime.value = paidTransaction.dateTime

Expand Down Expand Up @@ -674,6 +677,7 @@ class EditTransactionViewModel @Inject constructor(
amount = amount,
type = transactionType.value,
dueDate = dueDate.value,
paidFor = paidHistory.value,
dateTime = when {
loadedTransaction().dateTime == null &&
dueDate.value == null -> {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions shared/base/src/main/java/com/ivy/base/legacy/Transaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ data class Transaction(
val time: LocalTime? = null,
val recurringRuleId: UUID? = null,

/** to store the date for which the payment was made. */
@Suppress("DataClassDefaultValues")
val paidFor: LocalDateTime? = null,

val attachmentUrl: String? = null,

// This refers to the loan id that is linked with a transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.ivy.data.db.entity.UserEntity
import com.ivy.data.db.migration.Migration123to124_LoanIncludeDateTime
import com.ivy.data.db.migration.Migration124to125_LoanEditDateTime
import com.ivy.data.db.migration.Migration126to127_LoanRecordType
import com.ivy.data.db.migration.Migration127to128_PaidForDateRecord
import com.ivy.domain.db.RoomTypeConverters
import com.ivy.domain.db.migration.Migration105to106_TrnRecurringRules
import com.ivy.domain.db.migration.Migration106to107_Wishlist
Expand Down Expand Up @@ -75,7 +76,7 @@ import com.ivy.domain.db.migration.Migration125to126_Tags
spec = IvyRoomDatabase.DeleteSEMigration::class
)
],
version = 127,
version = 128,
exportSchema = true
)
@TypeConverters(RoomTypeConverters::class)
Expand Down Expand Up @@ -129,7 +130,8 @@ abstract class IvyRoomDatabase : RoomDatabase() {
Migration123to124_LoanIncludeDateTime(),
Migration124to125_LoanEditDateTime(),
Migration125to126_Tags(),
Migration126to127_LoanRecordType()
Migration126to127_LoanRecordType(),
Migration127to128_PaidForDateRecord()
)

@Suppress("SpreadOperator")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.serialization.Serializable
import java.time.LocalDateTime
import java.util.*

@Suppress("DataClassDefaultValues")
@Keep
@Serializable
@Entity(tableName = "transactions")
Expand Down Expand Up @@ -43,6 +44,9 @@ data class TransactionEntity(
@SerialName("recurringRuleId")
@Serializable(with = KSerializerUUID::class)
val recurringRuleId: UUID? = null,
@SerialName("paidForDateTime")
@Serializable(with = KSerializerLocalDateTime::class)
val paidForDateTime: LocalDateTime? = null,
@SerialName("attachmentUrl")
val attachmentUrl: String? = null,
// This refers to the loan id that is linked with a transaction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ivy.data.db.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

@Suppress("MagicNumber", "ClassNaming")
class Migration127to128_PaidForDateRecord : Migration(127, 128) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE transactions ADD COLUMN paidForDateTime INTEGER")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TransactionMapper @Inject constructor(
): Either<String, Transaction> = either {
val metadata = TransactionMetadata(
recurringRuleId = recurringRuleId,
paidForDateTime = paidForDateTime?.atZone(timeProvider.getZoneId())?.toInstant(),
loanId = loanId,
loanRecordId = loanRecordId
)
Expand Down Expand Up @@ -68,7 +69,7 @@ class TransactionMapper @Inject constructor(
metadata = metadata,
lastUpdated = Instant.EPOCH,
removed = isDeleted,
tags = tags
tags = tags,
)
}

Expand All @@ -85,7 +86,7 @@ class TransactionMapper @Inject constructor(
metadata = metadata,
lastUpdated = Instant.EPOCH,
removed = isDeleted,
tags = tags
tags = tags,
)
}

Expand Down Expand Up @@ -124,7 +125,7 @@ class TransactionMapper @Inject constructor(
fromValue = fromValue,
toAccount = toAccountId,
toValue = toValue,
tags = tags
tags = tags,
)
}
}
Expand Down Expand Up @@ -161,6 +162,7 @@ class TransactionMapper @Inject constructor(
dateTime = dateTime.takeIf { settled },
categoryId = category?.value,
dueDate = dateTime.takeIf { !settled },
paidForDateTime = metadata.paidForDateTime?.atZone(timeProvider.getZoneId())?.toLocalDateTime(),
recurringRuleId = metadata.recurringRuleId,
attachmentUrl = null,
loanId = metadata.loanId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ fun Arb.Companion.validTransfer(): Arb<TransactionEntity> = arbitrary {
dueDate = Arb.localDateTime().bind().takeIf {
isPlannedPayment || Arb.boolean().bind()
},
paidForDateTime = Arb.localDateTime().bind().takeIf {
!isPlannedPayment || Arb.boolean().bind()
},
categoryId = Arb.maybe(Arb.uuid()).bind(),
recurringRuleId = Arb.maybe(Arb.uuid()).bind(),
attachmentUrl = Arb.maybe(Arb.string()).bind(),
Expand Down Expand Up @@ -128,6 +131,9 @@ fun Arb.Companion.validIncomeOrExpense(): Arb<TransactionEntity> = arbitrary {
dueDate = Arb.localDateTime().bind().takeIf {
isPlannedPayment || Arb.boolean().bind()
},
paidForDateTime = Arb.localDateTime().bind().takeIf {
!isPlannedPayment || Arb.boolean().bind()
},
categoryId = Arb.maybe(Arb.uuid()).bind(),
recurringRuleId = Arb.maybe(Arb.uuid()).bind(),
attachmentUrl = Arb.maybe(Arb.string()).bind(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class TransactionMapperTest {
metadata = TransactionMetadata(
recurringRuleId = RecurringRuleId,
loanId = LoanId,
paidForDateTime = PaidForDateTime,
loanRecordId = LoanRecordId
),
lastUpdated = InstantNow,
Expand Down Expand Up @@ -102,6 +103,7 @@ class TransactionMapperTest {
dateTime = dateTime.takeIf { settled },
categoryId = CategoryId.value,
dueDate = dateTime.takeIf { !settled },
paidForDateTime = PaidForDateTime.atZone(timeProvider.getZoneId()).toLocalDateTime(),
recurringRuleId = RecurringRuleId,
attachmentUrl = null,
loanId = LoanId,
Expand All @@ -128,6 +130,7 @@ class TransactionMapperTest {
metadata = TransactionMetadata(
recurringRuleId = RecurringRuleId,
loanId = LoanId,
paidForDateTime = PaidForDateTime,
loanRecordId = LoanRecordId
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -156,6 +159,7 @@ class TransactionMapperTest {
dateTime = dateTime.takeIf { settled },
categoryId = CategoryId.value,
dueDate = dateTime.takeIf { !settled },
paidForDateTime = PaidForDateTime.atZone(timeProvider.getZoneId()).toLocalDateTime(),
recurringRuleId = RecurringRuleId,
attachmentUrl = null,
loanId = LoanId,
Expand All @@ -182,6 +186,7 @@ class TransactionMapperTest {
metadata = TransactionMetadata(
recurringRuleId = RecurringRuleId,
loanId = LoanId,
paidForDateTime = PaidForDateTime,
loanRecordId = LoanRecordId
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -215,6 +220,7 @@ class TransactionMapperTest {
dateTime = dateTime.takeIf { settled },
categoryId = CategoryId.value,
dueDate = dateTime.takeIf { !settled },
paidForDateTime = PaidForDateTime.atZone(timeProvider.getZoneId()).toLocalDateTime(),
recurringRuleId = RecurringRuleId,
attachmentUrl = null,
loanId = LoanId,
Expand Down Expand Up @@ -254,6 +260,7 @@ class TransactionMapperTest {
metadata = TransactionMetadata(
recurringRuleId = RecurringRuleId,
loanId = LoanId,
paidForDateTime = PaidForDateTime,
loanRecordId = LoanRecordId
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -380,6 +387,7 @@ class TransactionMapperTest {
metadata = TransactionMetadata(
recurringRuleId = RecurringRuleId,
loanId = LoanId,
paidForDateTime = PaidForDateTime,
loanRecordId = LoanRecordId
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -511,6 +519,7 @@ class TransactionMapperTest {
metadata = TransactionMetadata(
recurringRuleId = RecurringRuleId,
loanId = LoanId,
paidForDateTime = PaidForDateTime,
loanRecordId = LoanRecordId
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -691,6 +700,7 @@ class TransactionMapperTest {
val ToAccountId = AccountId(UUID.randomUUID())
val CategoryId = CategoryId(UUID.randomUUID())
val RecurringRuleId = UUID.randomUUID()
val PaidForDateTime: Instant = Instant.now()
val LoanId = UUID.randomUUID()
val LoanRecordId = UUID.randomUUID()
val TransactionId = TransactionId(UUID.randomUUID())
Expand All @@ -707,6 +717,7 @@ class TransactionMapperTest {
dateTime = DateTime,
categoryId = CategoryId.value,
dueDate = null,
paidForDateTime = PaidForDateTime.atZone(ZoneId.of("UTC")).toLocalDateTime(),
recurringRuleId = RecurringRuleId,
attachmentUrl = null,
loanId = LoanId,
Expand All @@ -727,6 +738,7 @@ class TransactionMapperTest {
dateTime = DateTime,
categoryId = CategoryId.value,
dueDate = null,
paidForDateTime = PaidForDateTime.atZone(ZoneId.of("UTC")).toLocalDateTime(),
recurringRuleId = RecurringRuleId,
attachmentUrl = null,
loanId = LoanId,
Expand All @@ -747,6 +759,7 @@ class TransactionMapperTest {
dateTime = DateTime,
categoryId = CategoryId.value,
dueDate = null,
paidForDateTime = PaidForDateTime.atZone(ZoneId.of("UTC")).toLocalDateTime(),
recurringRuleId = RecurringRuleId,
attachmentUrl = null,
loanId = LoanId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun Arb.Companion.income(
metadata = TransactionMetadata(
recurringRuleId = null,
loanId = null,
paidForDateTime = null,
loanRecordId = null
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -77,6 +78,7 @@ fun Arb.Companion.expense(
metadata = TransactionMetadata(
recurringRuleId = null,
loanId = null,
paidForDateTime = null,
loanRecordId = null
),
lastUpdated = Instant.EPOCH,
Expand Down Expand Up @@ -111,6 +113,7 @@ fun Arb.Companion.transfer(
metadata = TransactionMetadata(
recurringRuleId = null,
loanId = null,
paidForDateTime = null,
loanRecordId = null
),
lastUpdated = Instant.EPOCH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ data class Transfer(
@Suppress("DataClassTypedIDs")
data class TransactionMetadata(
val recurringRuleId: UUID?,
val paidForDateTime: Instant?,
// This refers to the loan id that is linked with a transaction
val loanId: UUID? = null,
// This refers to the loan record id that is linked with a transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class TransactionTest {
metadata = TransactionMetadata(
recurringRuleId = null,
loanId = null,
paidForDateTime = null,
loanRecordId = null
),
lastUpdated = Instant.EPOCH,
Expand All @@ -161,6 +162,7 @@ class TransactionTest {
metadata = TransactionMetadata(
recurringRuleId = null,
loanId = null,
paidForDateTime = null,
loanRecordId = null
),
lastUpdated = Instant.EPOCH,
Expand All @@ -183,6 +185,7 @@ class TransactionTest {
metadata = TransactionMetadata(
recurringRuleId = null,
loanId = null,
paidForDateTime = null,
loanRecordId = null
),
lastUpdated = Instant.EPOCH,
Expand Down
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,5 @@
<string name="import_csv_continue">Continue</string>
<string name="warning_import_csv_file">"\n!!!⚠️WARNING: Importing may duplicate transactions!!!\nDuplicate transactions can NOT be easily deleted and you'll need to remove manually each one of them! \nReason: We can't parse transaction ids because Ivy Wallet works only with UUID and other apps don't.\nIf you're starting fresh, no worries - kindly ignore this message."</string>
<string name="select_tags">Select Tags</string>
<string name="bill_paid">Your bill for %1$s %2$d has been paid</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fun Transaction.toEntity(): TransactionEntity = TransactionEntity(
categoryId = categoryId,
dueDate = dueDate,
recurringRuleId = recurringRuleId,
paidForDateTime = paidFor,
attachmentUrl = attachmentUrl,
loanId = loanId,
loanRecordId = loanRecordId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fun TransactionEntity.toLegacyDomain(
categoryId = categoryId,
dueDate = dueDate,
recurringRuleId = recurringRuleId,
paidFor = paidForDateTime,
attachmentUrl = attachmentUrl,
loanId = loanId,
loanRecordId = loanRecordId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class PlannedPaymentsGenerator @Inject constructor(
dueDate = dueDate,
dateTime = null,
toAccountId = null,

isSynced = false
).toEntity()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class PlannedPaymentsLogic @Inject constructor(
if (transaction.dueDate == null || transaction.dateTime != null) return

val paidTransaction = transaction.copy(
paidFor = transaction.dueDate,
dueDate = null,
dateTime = timeNowUTC(),
isSynced = false,
Expand Down
Loading

0 comments on commit 2ca6117

Please sign in to comment.