Skip to content

Commit

Permalink
new income causes new decision even when data has not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Joosakur committed Feb 18, 2025
1 parent e6c4767 commit dc172ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun mapIncomeToDecisionIncome(
coefficientMultiplierProvider: IncomeCoefficientMultiplierProvider,
): DecisionIncome =
DecisionIncome(
id = income.id,
effect = income.effect,
data =
income.data.mapValues { (_, value) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ enum class FeeDecisionDifference(val contentEquals: (d1: FeeDecision, d2: FeeDec
d1.children.map { it.child.id }.toSet() == d2.children.map { it.child.id }.toSet()
}),
INCOME({ d1, d2 ->
val logic =
if (d2.validFrom < LocalDate.of(2025, 1, 1)) IncomeComparisonVersion.V1
else IncomeComparisonVersion.V2
setOf(
d1.headOfFamilyIncome?.effectiveComparable(),
d1.partnerIncome?.effectiveComparable(),
d1.headOfFamilyIncome?.effectiveComparable(logic),
d1.partnerIncome?.effectiveComparable(logic),
) ==
setOf(
d2.headOfFamilyIncome?.effectiveComparable(),
d2.partnerIncome?.effectiveComparable(),
) && decisionChildrenEquals(d1, d2) { it.childIncome?.effectiveComparable() }
d2.headOfFamilyIncome?.effectiveComparable(logic),
d2.partnerIncome?.effectiveComparable(logic),
) && decisionChildrenEquals(d1, d2) { it.childIncome?.effectiveComparable(logic) }
}),
PLACEMENT({ d1, d2 -> decisionChildrenEquals(d1, d2) { it.placement } }),
SERVICE_NEED({ d1, d2 ->
Expand Down
21 changes: 15 additions & 6 deletions service/src/main/kotlin/fi/espoo/evaka/invoicing/domain/Incomes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,31 @@ data class IncomeRequest(
val attachments: List<Attachment> = listOf(),
)

enum class IncomeComparisonVersion {
V1,
V2,
}

@JsonIgnoreProperties(ignoreUnknown = true)
data class DecisionIncome(
val id: IncomeId?,
val effect: IncomeEffect,
val data: Map<String, Int>,
val totalIncome: Int,
val totalExpenses: Int,
val total: Int,
val worksAtECHA: Boolean,
) {
fun effectiveComparable(): DecisionIncome? {
return when (this.effect) {
IncomeEffect.NOT_AVAILABLE,
IncomeEffect.INCOMPLETE -> null
else -> this
fun effectiveComparable(version: IncomeComparisonVersion): DecisionIncome? =
when (version) {
IncomeComparisonVersion.V1 ->
when (this.effect) {
IncomeEffect.NOT_AVAILABLE,
IncomeEffect.INCOMPLETE -> null
else -> this
}
IncomeComparisonVersion.V2 -> this
}
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,18 @@ enum class VoucherValueDecisionDifference(
setOf(d1.headOfFamilyId, d1.partnerId) == setOf(d2.headOfFamilyId, d2.partnerId)
}),
INCOME({ d1, d2 ->
val logic =
if (d2.validFrom < LocalDate.of(2025, 1, 1)) IncomeComparisonVersion.V1
else IncomeComparisonVersion.V2
setOf(
d1.headOfFamilyIncome?.effectiveComparable(),
d1.partnerIncome?.effectiveComparable(),
d1.headOfFamilyIncome?.effectiveComparable(logic),
d1.partnerIncome?.effectiveComparable(logic),
) ==
setOf(
d2.headOfFamilyIncome?.effectiveComparable(),
d2.partnerIncome?.effectiveComparable(),
) && d1.childIncome?.effectiveComparable() == d2.childIncome?.effectiveComparable()
d2.headOfFamilyIncome?.effectiveComparable(logic),
d2.partnerIncome?.effectiveComparable(logic),
) &&
d1.childIncome?.effectiveComparable(logic) == d2.childIncome?.effectiveComparable(logic)
}),
FAMILY_SIZE({ d1, d2 -> d1.familySize == d2.familySize }),
PLACEMENT({ d1, d2 -> d1.placement == d2.placement }),
Expand Down

0 comments on commit dc172ea

Please sign in to comment.