Skip to content

Commit

Permalink
Merge pull request #5955 from espoon-voltti/fix-invoices-no-rows
Browse files Browse the repository at this point in the history
Korjaus laskuhakun tuloksiin, kun löydetyissä laskuissa ei ole yhtään riviä
  • Loading branch information
akheron authored Nov 11, 2024
2 parents 720e575 + 1314587 commit 11300e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,21 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
assertEqualEnough(testInvoices.take(2).map(::toSummary), result)
}

@Test
fun `search returns invoices without rows correctly`() {
val testInvoice =
DevInvoice(
status = InvoiceStatus.DRAFT,
headOfFamilyId = testAdult_1.id,
areaId = testArea.id,
rows = emptyList(),
)
db.transaction { tx -> tx.insert(listOf(testInvoice)) }

val result = searchInvoices(SearchInvoicesRequest(page = 1))
assertEqualEnough(listOf(toSummary(testInvoice)), result)
}

@Test
fun `search gives correct total and page composition when using filters`() {
db.transaction { tx -> tx.insert(testInvoices) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ JOIN invoice ON invoice_ids.id = invoice.id
JOIN person as head ON invoice.head_of_family = head.id
JOIN LATERAL (
SELECT
jsonb_agg(DISTINCT jsonb_build_object(
coalesce(jsonb_agg(DISTINCT jsonb_build_object(
'id', row.child,
'dateOfBirth', child.date_of_birth,
'firstName', child.first_name,
'lastName', child.last_name,
'ssn', child.social_security_number
)) AS children,
SUM(row.amount * row.unit_price) AS total_price
)), '[]'::jsonb) AS children,
coalesce(sum(row.amount * row.unit_price), 0) AS total_price
FROM invoice_row AS row
JOIN person AS child ON row.child = child.id
WHERE row.invoice_id = invoice.id
Expand Down

0 comments on commit 11300e5

Please sign in to comment.