Skip to content

Commit

Permalink
Review comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akheron committed Nov 1, 2024
1 parent c3f7193 commit 219aa17
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ fun Database.Transaction.insertDraftInvoices(
relatedFeeDecisions: Map<PersonId, List<FeeDecisionId>> = emptyMap(),
): List<InvoiceId> {
val invoiceIds = insertInvoicesWithoutRows(invoices)
check(invoiceIds.size == invoices.size)

insertInvoiceRows(
invoices.zip(invoiceIds).map { (invoice, invoiceId) -> invoiceId to invoice.rows }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class InvoiceCorrection(
val note: String,
@Nested("invoice") val invoice: InvoiceWithCorrection?, // should later be a list?
) {
fun toInvoiceRow() =
fun toDraftInvoiceRow() =
DraftInvoiceRow(
childId = childId,
amount = amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class InvoiceGenerator(
.sortedByDescending { abs(it.amount * it.unitPrice) }
.partition { it.unitPrice > 0 }
val withAdditions =
invoice.copy(rows = invoice.rows + additions.map { it.toInvoiceRow() })
invoice.copy(rows = invoice.rows + additions.map { it.toDraftInvoiceRow() })

subtractions.fold(withAdditions) { invoiceWithSubtractions, subtraction ->
if (invoiceWithSubtractions.totalPrice == 0)
Expand All @@ -230,7 +230,7 @@ class InvoiceGenerator(
invoiceWithSubtractions.copy(
rows =
invoiceWithSubtractions.rows +
subtractionWithMaxApplicableAmount.toInvoiceRow()
subtractionWithMaxApplicableAmount.toDraftInvoiceRow()
)
} else { // apply partial unit price
val maxUnitPrice =
Expand All @@ -242,7 +242,7 @@ class InvoiceGenerator(
invoiceWithSubtractions.copy(
rows =
invoiceWithSubtractions.rows +
subtractionWithMaxUnitPrice.toInvoiceRow()
subtractionWithMaxUnitPrice.toDraftInvoiceRow()
)
}
}
Expand Down

0 comments on commit 219aa17

Please sign in to comment.