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

Commit

Permalink
Fix Transactions copy bug (#3581)
Browse files Browse the repository at this point in the history
Co-authored-by: Priyatanu <priyatanu.dey@neugelb.com>
  • Loading branch information
priyatanu and Priyatanu authored Oct 4, 2024
1 parent 5c532c9 commit 9aafa36
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class EditTransactionViewModel @Inject constructor(
transactionAssociatedTags =
tagRepository.findByAssociatedId(AssociationId(loadedTransaction().id)).map(Tag::id)
.toImmutableList()

display(loadedTransaction!!)
}
}
Expand Down Expand Up @@ -622,17 +621,24 @@ class EditTransactionViewModel @Inject constructor(
private fun duplicate() {
viewModelScope.launch {
ioThread {
loadedTransaction()
val id = UUID.randomUUID()
loadedTransaction()
.copy(
id = UUID.randomUUID(),
id = id,
dateTime = timeProvider.utcNow(),
)
.toDomain(transactionMapper)
?.let {
transactionRepo.save(it)
}

tagRepository.findByIds(transactionAssociatedTags).forEach {
associateTagToTransaction(it, id)
}

refreshWidget(WalletBalanceWidgetReceiver::class.java)
}

closeScreen()
}
}
Expand Down Expand Up @@ -930,6 +936,15 @@ class EditTransactionViewModel @Inject constructor(
}
}

private fun associateTagToTransaction(selectedTag: Tag, id: UUID) {
viewModelScope.launch(Dispatchers.IO) {
val associatedId = AssociationId(id)
tagRepository.associateTagToEntity(associatedId, selectedTag.id)
transactionAssociatedTags =
tagRepository.findByAssociatedId(associatedId).map(Tag::id).toImmutableList()
}
}

private fun removeTagAssociation(selectedTag: Tag) {
viewModelScope.launch(Dispatchers.IO) {
val associatedId = AssociationId(loadedTransaction().id)
Expand Down

0 comments on commit 9aafa36

Please sign in to comment.