Skip to content

Commit

Permalink
Merge pull request #5925 from espoon-voltti/replacement-invoices
Browse files Browse the repository at this point in the history
Oikaisulaskut, osa 1: Laskujen yöllinen generointi (ei vielä käytössä)
  • Loading branch information
akheron authored Nov 8, 2024
2 parents aac4250 + b9a54fa commit 03402e6
Show file tree
Hide file tree
Showing 21 changed files with 647 additions and 225 deletions.
2 changes: 2 additions & 0 deletions frontend/src/e2e-test/dev-api/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,8 @@ export const invoiceFixture = (
sentAt: null,
sentBy: null,
createdAt: null,
replacedInvoiceId: null,
revisionNumber: 0,
rows: [
{
id: uuidv4(),
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/e2e-test/generated/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ export interface DevInvoice {
number: number | null
periodEnd: LocalDate
periodStart: LocalDate
replacedInvoiceId: UUID | null
revisionNumber: number
rows: DevInvoiceRow[]
sentAt: HelsinkiDateTime | null
sentBy: UUID | null
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/lib-common/generated/api-types/invoicing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ export interface InvoiceDetailed {
periodEnd: LocalDate
periodStart: LocalDate
relatedFeeDecisions: RelatedFeeDecision[]
replacedInvoiceId: UUID | null
revisionNumber: number
rows: InvoiceRowDetailed[]
sentAt: HelsinkiDateTime | null
sentBy: UUID | null
Expand Down Expand Up @@ -645,7 +647,8 @@ export type InvoiceStatus =
| 'DRAFT'
| 'WAITING_FOR_SENDING'
| 'SENT'
| 'CANCELED'
| 'REPLACEMENT_DRAFT'
| 'REPLACED'

/**
* Generated from fi.espoo.evaka.invoicing.domain.InvoiceSummary
Expand All @@ -657,6 +660,7 @@ export interface InvoiceSummary {
id: UUID
periodEnd: LocalDate
periodStart: LocalDate
revisionNumber: number
sentAt: HelsinkiDateTime | null
sentBy: UUID | null
status: InvoiceStatus
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/lib-customizations/defaults/employee/i18n/fi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2726,13 +2726,15 @@ export const fi = {
DRAFT: 'Luonnos',
WAITING_FOR_SENDING: 'Siirretään manuaalisesti',
SENT: 'Siirretty',
CANCELED: 'Peruutettu'
REPLACEMENT_DRAFT: 'Oikaisuluonnos',
REPLACED: 'Oikaistu'
},
title: {
DRAFT: 'Laskuluonnos',
WAITING_FOR_SENDING: 'Siirtoa odottava lasku',
SENT: 'Siirretty lasku',
CANCELED: 'Peruutettu lasku'
REPLACEMENT_DRAFT: 'Oikaisulaskuluonnos',
REPLACED: 'Oikaistu lasku'
},
form: {
nav: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,49 +234,22 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
assertEqualEnough(sent.map(::toSummary), result)
}

@Test
fun `search works with canceled status parameter`() {
db.transaction { tx -> tx.insert(testInvoices) }
val canceled = testInvoices.filter { it.status == InvoiceStatus.CANCELED }

val result =
searchInvoices(SearchInvoicesRequest(page = 1, status = listOf(InvoiceStatus.CANCELED)))

assertEqualEnough(canceled.map(::toSummary), result)
}

@Test
fun `search works with multiple status parameters`() {
db.transaction { tx -> tx.insert(testInvoices) }
val sentAndCanceled =
val sentAndDraft =
testInvoices.filter {
it.status == InvoiceStatus.SENT || it.status == InvoiceStatus.CANCELED
it.status == InvoiceStatus.SENT || it.status == InvoiceStatus.DRAFT
}

val result =
searchInvoices(
SearchInvoicesRequest(
page = 1,
status = listOf(InvoiceStatus.SENT, InvoiceStatus.CANCELED),
)
)
assertEqualEnough(sentAndCanceled.map(::toSummary), result)
}

@Test
fun `search works with all status parameters`() {
val testInvoiceSubset = testInvoices.take(2)
db.transaction { tx -> tx.insert(testInvoiceSubset) }
val invoices = testInvoiceSubset.sortedBy { it.status }.reversed()

val result =
searchInvoices(
SearchInvoicesRequest(
page = 1,
status = listOf(InvoiceStatus.DRAFT, InvoiceStatus.SENT, InvoiceStatus.CANCELED),
status = listOf(InvoiceStatus.SENT, InvoiceStatus.DRAFT),
)
)
assertEqualEnough(invoices.map(::toSummary), result)
assertEqualEnough(sentAndDraft.map(::toSummary), result)
}

@Test
Expand Down Expand Up @@ -819,6 +792,8 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
InvoiceDetailed(
id = invoice.id,
status = invoice.status,
revisionNumber = invoice.revisionNumber,
replacedInvoiceId = invoice.replacedInvoiceId,
periodStart = invoice.periodStart,
periodEnd = invoice.periodEnd,
dueDate = invoice.dueDate,
Expand Down Expand Up @@ -866,6 +841,7 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
InvoiceSummary(
id = invoice.id,
status = invoice.status,
revisionNumber = invoice.revisionNumber,
periodStart = invoice.periodStart,
periodEnd = invoice.periodEnd,
headOfFamily = allAdults.find { it.id == invoice.headOfFamilyId }!!.toPersonDetailed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,6 @@ class InvoiceQueriesTest : PureJdbiTest(resetDbBeforeEach = true) {
}
}

@Test
fun `search canceled`() {
db.transaction { tx ->
tx.insert(testInvoices)

val result = tx.searchInvoices(InvoiceStatus.CANCELED)
assertEquals(0, result.size)
}
}

@Test
fun `search sent`() {
db.transaction { tx ->
tx.insert(testInvoices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

package fi.espoo.evaka.invoicing.service

import fi.espoo.evaka.PureJdbiTest
import fi.espoo.evaka.FullApplicationTest
import fi.espoo.evaka.TestInvoiceProductProvider
import fi.espoo.evaka.invoicing.data.insertDraftInvoices
import fi.espoo.evaka.invoicing.domain.DraftInvoice
import fi.espoo.evaka.invoicing.domain.DraftInvoiceRow
import fi.espoo.evaka.invoicing.integration.InvoiceIntegrationClient
import fi.espoo.evaka.invoicing.domain.InvoiceStatus
import fi.espoo.evaka.placement.PlacementType
import fi.espoo.evaka.shared.FeatureConfig
import fi.espoo.evaka.shared.InvoiceCorrectionId
import fi.espoo.evaka.shared.auth.UserRole
import fi.espoo.evaka.shared.config.defaultJsonMapperBuilder
import fi.espoo.evaka.shared.config.testFeatureConfig
import fi.espoo.evaka.shared.dev.DevCareArea
import fi.espoo.evaka.shared.dev.DevDaycare
import fi.espoo.evaka.shared.dev.DevEmployee
Expand All @@ -24,27 +21,21 @@ import fi.espoo.evaka.shared.dev.DevPerson
import fi.espoo.evaka.shared.dev.DevPersonType
import fi.espoo.evaka.shared.dev.insert
import fi.espoo.evaka.shared.domain.FiniteDateRange
import fi.espoo.evaka.shared.domain.RealEvakaClock
import fi.espoo.evaka.shared.domain.MockEvakaClock
import java.time.Month
import java.time.YearMonth
import kotlin.test.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

class InvoiceCorrectionsIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
@Autowired private lateinit var generator: InvoiceGenerator
@Autowired private lateinit var invoiceService: InvoiceService

class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true) {
private val productProvider: InvoiceProductProvider = TestInvoiceProductProvider()
private val featureConfig: FeatureConfig = testFeatureConfig
private val draftInvoiceGenerator: DraftInvoiceGenerator =
DraftInvoiceGenerator(productProvider, featureConfig)
private val generator: InvoiceGenerator =
InvoiceGenerator(draftInvoiceGenerator, featureConfig, DefaultInvoiceGenerationLogic)
private val invoiceService =
InvoiceService(
InvoiceIntegrationClient.MockClient(defaultJsonMapperBuilder().build()),
TestInvoiceProductProvider(),
featureConfig,
)
private val clock = RealEvakaClock()

private val clock = MockEvakaClock(2024, 10, 1, 12, 0)

val employee = DevEmployee(roles = setOf(UserRole.FINANCE_ADMIN))
val area = DevCareArea()
Expand Down Expand Up @@ -415,7 +406,9 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
month: YearMonth,
): List<DraftInvoice> =
db.read { tx ->
generator.applyCorrections(tx, invoices, month, mapOf(daycare.id to area.id)).shuffled()
generator
.applyUnappliedCorrections(tx, month, invoices, mapOf(daycare.id to area.id))
.shuffled()
}

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

private fun insertAndSendInvoice(invoice: DraftInvoice) {
db.transaction { tx ->
val invoiceId = tx.insertDraftInvoices(listOf(invoice)).single()
val invoiceId = tx.insertDraftInvoices(listOf(invoice), InvoiceStatus.DRAFT).single()
invoiceService.sendInvoices(
tx,
employee.evakaUserId,
Expand Down
Loading

0 comments on commit 03402e6

Please sign in to comment.