Skip to content

Commit 03402e6

Browse files
authored
Merge pull request #5925 from espoon-voltti/replacement-invoices
Oikaisulaskut, osa 1: Laskujen yöllinen generointi (ei vielä käytössä)
2 parents aac4250 + b9a54fa commit 03402e6

File tree

21 files changed

+647
-225
lines changed

21 files changed

+647
-225
lines changed

frontend/src/e2e-test/dev-api/fixtures.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,8 @@ export const invoiceFixture = (
30453045
sentAt: null,
30463046
sentBy: null,
30473047
createdAt: null,
3048+
replacedInvoiceId: null,
3049+
revisionNumber: 0,
30483050
rows: [
30493051
{
30503052
id: uuidv4(),

frontend/src/e2e-test/generated/api-types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ export interface DevInvoice {
648648
number: number | null
649649
periodEnd: LocalDate
650650
periodStart: LocalDate
651+
replacedInvoiceId: UUID | null
652+
revisionNumber: number
651653
rows: DevInvoiceRow[]
652654
sentAt: HelsinkiDateTime | null
653655
sentBy: UUID | null

frontend/src/lib-common/generated/api-types/invoicing.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ export interface InvoiceDetailed {
570570
periodEnd: LocalDate
571571
periodStart: LocalDate
572572
relatedFeeDecisions: RelatedFeeDecision[]
573+
replacedInvoiceId: UUID | null
574+
revisionNumber: number
573575
rows: InvoiceRowDetailed[]
574576
sentAt: HelsinkiDateTime | null
575577
sentBy: UUID | null
@@ -645,7 +647,8 @@ export type InvoiceStatus =
645647
| 'DRAFT'
646648
| 'WAITING_FOR_SENDING'
647649
| 'SENT'
648-
| 'CANCELED'
650+
| 'REPLACEMENT_DRAFT'
651+
| 'REPLACED'
649652

650653
/**
651654
* Generated from fi.espoo.evaka.invoicing.domain.InvoiceSummary
@@ -657,6 +660,7 @@ export interface InvoiceSummary {
657660
id: UUID
658661
periodEnd: LocalDate
659662
periodStart: LocalDate
663+
revisionNumber: number
660664
sentAt: HelsinkiDateTime | null
661665
sentBy: UUID | null
662666
status: InvoiceStatus

frontend/src/lib-customizations/defaults/employee/i18n/fi.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -2726,13 +2726,15 @@ export const fi = {
27262726
DRAFT: 'Luonnos',
27272727
WAITING_FOR_SENDING: 'Siirretään manuaalisesti',
27282728
SENT: 'Siirretty',
2729-
CANCELED: 'Peruutettu'
2729+
REPLACEMENT_DRAFT: 'Oikaisuluonnos',
2730+
REPLACED: 'Oikaistu'
27302731
},
27312732
title: {
27322733
DRAFT: 'Laskuluonnos',
27332734
WAITING_FOR_SENDING: 'Siirtoa odottava lasku',
27342735
SENT: 'Siirretty lasku',
2735-
CANCELED: 'Peruutettu lasku'
2736+
REPLACEMENT_DRAFT: 'Oikaisulaskuluonnos',
2737+
REPLACED: 'Oikaistu lasku'
27362738
},
27372739
form: {
27382740
nav: {

service/src/integrationTest/kotlin/fi/espoo/evaka/invoicing/InvoiceIntegrationTest.kt

+7-31
Original file line numberDiff line numberDiff line change
@@ -234,49 +234,22 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
234234
assertEqualEnough(sent.map(::toSummary), result)
235235
}
236236

237-
@Test
238-
fun `search works with canceled status parameter`() {
239-
db.transaction { tx -> tx.insert(testInvoices) }
240-
val canceled = testInvoices.filter { it.status == InvoiceStatus.CANCELED }
241-
242-
val result =
243-
searchInvoices(SearchInvoicesRequest(page = 1, status = listOf(InvoiceStatus.CANCELED)))
244-
245-
assertEqualEnough(canceled.map(::toSummary), result)
246-
}
247-
248237
@Test
249238
fun `search works with multiple status parameters`() {
250239
db.transaction { tx -> tx.insert(testInvoices) }
251-
val sentAndCanceled =
240+
val sentAndDraft =
252241
testInvoices.filter {
253-
it.status == InvoiceStatus.SENT || it.status == InvoiceStatus.CANCELED
242+
it.status == InvoiceStatus.SENT || it.status == InvoiceStatus.DRAFT
254243
}
255244

256245
val result =
257246
searchInvoices(
258247
SearchInvoicesRequest(
259248
page = 1,
260-
status = listOf(InvoiceStatus.SENT, InvoiceStatus.CANCELED),
261-
)
262-
)
263-
assertEqualEnough(sentAndCanceled.map(::toSummary), result)
264-
}
265-
266-
@Test
267-
fun `search works with all status parameters`() {
268-
val testInvoiceSubset = testInvoices.take(2)
269-
db.transaction { tx -> tx.insert(testInvoiceSubset) }
270-
val invoices = testInvoiceSubset.sortedBy { it.status }.reversed()
271-
272-
val result =
273-
searchInvoices(
274-
SearchInvoicesRequest(
275-
page = 1,
276-
status = listOf(InvoiceStatus.DRAFT, InvoiceStatus.SENT, InvoiceStatus.CANCELED),
249+
status = listOf(InvoiceStatus.SENT, InvoiceStatus.DRAFT),
277250
)
278251
)
279-
assertEqualEnough(invoices.map(::toSummary), result)
252+
assertEqualEnough(sentAndDraft.map(::toSummary), result)
280253
}
281254

282255
@Test
@@ -819,6 +792,8 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
819792
InvoiceDetailed(
820793
id = invoice.id,
821794
status = invoice.status,
795+
revisionNumber = invoice.revisionNumber,
796+
replacedInvoiceId = invoice.replacedInvoiceId,
822797
periodStart = invoice.periodStart,
823798
periodEnd = invoice.periodEnd,
824799
dueDate = invoice.dueDate,
@@ -866,6 +841,7 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
866841
InvoiceSummary(
867842
id = invoice.id,
868843
status = invoice.status,
844+
revisionNumber = invoice.revisionNumber,
869845
periodStart = invoice.periodStart,
870846
periodEnd = invoice.periodEnd,
871847
headOfFamily = allAdults.find { it.id == invoice.headOfFamilyId }!!.toPersonDetailed(),

service/src/integrationTest/kotlin/fi/espoo/evaka/invoicing/data/InvoiceQueriesTest.kt

-11
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ class InvoiceQueriesTest : PureJdbiTest(resetDbBeforeEach = true) {
8080
}
8181
}
8282

83-
@Test
84-
fun `search canceled`() {
85-
db.transaction { tx ->
86-
tx.insert(testInvoices)
87-
88-
val result = tx.searchInvoices(InvoiceStatus.CANCELED)
89-
assertEquals(0, result.size)
90-
}
91-
}
92-
93-
@Test
9483
fun `search sent`() {
9584
db.transaction { tx ->
9685
tx.insert(testInvoices)

service/src/integrationTest/kotlin/fi/espoo/evaka/invoicing/service/InvoiceCorrectionsIntegrationTest.kt

+14-21
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
package fi.espoo.evaka.invoicing.service
66

7-
import fi.espoo.evaka.PureJdbiTest
7+
import fi.espoo.evaka.FullApplicationTest
88
import fi.espoo.evaka.TestInvoiceProductProvider
99
import fi.espoo.evaka.invoicing.data.insertDraftInvoices
1010
import fi.espoo.evaka.invoicing.domain.DraftInvoice
1111
import fi.espoo.evaka.invoicing.domain.DraftInvoiceRow
12-
import fi.espoo.evaka.invoicing.integration.InvoiceIntegrationClient
12+
import fi.espoo.evaka.invoicing.domain.InvoiceStatus
1313
import fi.espoo.evaka.placement.PlacementType
14-
import fi.espoo.evaka.shared.FeatureConfig
1514
import fi.espoo.evaka.shared.InvoiceCorrectionId
1615
import fi.espoo.evaka.shared.auth.UserRole
17-
import fi.espoo.evaka.shared.config.defaultJsonMapperBuilder
18-
import fi.espoo.evaka.shared.config.testFeatureConfig
1916
import fi.espoo.evaka.shared.dev.DevCareArea
2017
import fi.espoo.evaka.shared.dev.DevDaycare
2118
import fi.espoo.evaka.shared.dev.DevEmployee
@@ -24,27 +21,21 @@ import fi.espoo.evaka.shared.dev.DevPerson
2421
import fi.espoo.evaka.shared.dev.DevPersonType
2522
import fi.espoo.evaka.shared.dev.insert
2623
import fi.espoo.evaka.shared.domain.FiniteDateRange
27-
import fi.espoo.evaka.shared.domain.RealEvakaClock
24+
import fi.espoo.evaka.shared.domain.MockEvakaClock
2825
import java.time.Month
2926
import java.time.YearMonth
3027
import kotlin.test.assertEquals
3128
import org.junit.jupiter.api.BeforeEach
3229
import org.junit.jupiter.api.Test
30+
import org.springframework.beans.factory.annotation.Autowired
31+
32+
class InvoiceCorrectionsIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
33+
@Autowired private lateinit var generator: InvoiceGenerator
34+
@Autowired private lateinit var invoiceService: InvoiceService
3335

34-
class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true) {
3536
private val productProvider: InvoiceProductProvider = TestInvoiceProductProvider()
36-
private val featureConfig: FeatureConfig = testFeatureConfig
37-
private val draftInvoiceGenerator: DraftInvoiceGenerator =
38-
DraftInvoiceGenerator(productProvider, featureConfig)
39-
private val generator: InvoiceGenerator =
40-
InvoiceGenerator(draftInvoiceGenerator, featureConfig, DefaultInvoiceGenerationLogic)
41-
private val invoiceService =
42-
InvoiceService(
43-
InvoiceIntegrationClient.MockClient(defaultJsonMapperBuilder().build()),
44-
TestInvoiceProductProvider(),
45-
featureConfig,
46-
)
47-
private val clock = RealEvakaClock()
37+
38+
private val clock = MockEvakaClock(2024, 10, 1, 12, 0)
4839

4940
val employee = DevEmployee(roles = setOf(UserRole.FINANCE_ADMIN))
5041
val area = DevCareArea()
@@ -415,7 +406,9 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
415406
month: YearMonth,
416407
): List<DraftInvoice> =
417408
db.read { tx ->
418-
generator.applyCorrections(tx, invoices, month, mapOf(daycare.id to area.id)).shuffled()
409+
generator
410+
.applyUnappliedCorrections(tx, month, invoices, mapOf(daycare.id to area.id))
411+
.shuffled()
419412
}
420413

421414
private fun createTestInvoice(total: Int, month: YearMonth): DraftInvoice =
@@ -441,7 +434,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
441434

442435
private fun insertAndSendInvoice(invoice: DraftInvoice) {
443436
db.transaction { tx ->
444-
val invoiceId = tx.insertDraftInvoices(listOf(invoice)).single()
437+
val invoiceId = tx.insertDraftInvoices(listOf(invoice), InvoiceStatus.DRAFT).single()
445438
invoiceService.sendInvoices(
446439
tx,
447440
employee.evakaUserId,

0 commit comments

Comments
 (0)