Skip to content

Commit

Permalink
Merge pull request #5890 from espoon-voltti/invoice-id
Browse files Browse the repository at this point in the history
Käytetään tietokannan generoimia ID:itä laskuille ja laskuriveille + pikkuparannuksia
  • Loading branch information
akheron authored Nov 1, 2024
2 parents ec04132 + 219aa17 commit c75113d
Show file tree
Hide file tree
Showing 24 changed files with 708 additions and 1,028 deletions.
17 changes: 9 additions & 8 deletions frontend/src/e2e-test/dev-api/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
FeeDecisionStatus,
FeeThresholds,
IncomeNotification,
Invoice
InvoiceStatus
} from 'lib-common/generated/api-types/invoicing'
import { PlacementType } from 'lib-common/generated/api-types/placement'
import { DailyReservationRequest } from 'lib-common/generated/api-types/reservations'
Expand Down Expand Up @@ -130,6 +130,7 @@ import {
DevFridgeChild,
DevHoliday,
DevIncome,
DevInvoice,
DevParentship,
DevPayment,
DevPedagogicalDocument,
Expand Down Expand Up @@ -3017,13 +3018,13 @@ export const invoiceFixture = (
childId: UUID,
areaId: UUID,
unitId: UUID,
status: Invoice['status'],
status: InvoiceStatus,
periodStart = LocalDate.of(2019, 1, 1),
periodEnd = LocalDate.of(2019, 1, 1)
): Invoice => ({
): DevInvoice => ({
id: uuidv4(),
status,
headOfFamily: adultId,
headOfFamilyId: adultId,
codebtor: null,
areaId,
periodStart,
Expand All @@ -3033,22 +3034,22 @@ export const invoiceFixture = (
number: null,
sentAt: null,
sentBy: null,
createdAt: null,
rows: [
{
id: uuidv4(),
child: childId,
idx: 1,
childId,
amount: 1,
unitPrice: 10000,
periodStart: periodStart,
periodEnd: periodEnd,
product: 'DAYCARE',
unitId,
description: '',
price: 10000,
correctionId: null
}
],
totalPrice: 10000
]
})

export const testDaycareGroup: DevDaycareGroup = {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/e2e-test/generated/api-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { DevFridgePartner } from './api-types'
import { DevGuardian } from './api-types'
import { DevHoliday } from './api-types'
import { DevIncome } from './api-types'
import { DevInvoice } from './api-types'
import { DevMobileDevice } from './api-types'
import { DevOtherAssistanceMeasure } from './api-types'
import { DevParentship } from './api-types'
Expand Down Expand Up @@ -82,7 +83,6 @@ import { FixedPeriodQuestionnaireBody } from 'lib-common/generated/api-types/hol
import { GroupNoteBody } from 'lib-common/generated/api-types/note'
import { HolidayPeriodCreate } from 'lib-common/generated/api-types/holidayperiod'
import { IncomeNotification } from 'lib-common/generated/api-types/invoicing'
import { Invoice } from 'lib-common/generated/api-types/invoicing'
import { JsonCompatible } from 'lib-common/json'
import { JsonOf } from 'lib-common/json'
import { MockVtjDataset } from './api-types'
Expand Down Expand Up @@ -1177,14 +1177,14 @@ export async function createIncomeStatements(
*/
export async function createInvoices(
request: {
body: Invoice[]
body: DevInvoice[]
}
): Promise<void> {
try {
const { data: json } = await devClient.request<JsonOf<void>>({
url: uri`/invoices`.toString(),
method: 'POST',
data: request.body satisfies JsonCompatible<Invoice[]>
data: request.body satisfies JsonCompatible<DevInvoice[]>
})
return json
} catch (e) {
Expand Down
61 changes: 61 additions & 0 deletions frontend/src/e2e-test/generated/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { FeeDecisionThresholds } from 'lib-common/generated/api-types/invoicing'
import { IncomeEffect } from 'lib-common/generated/api-types/invoicing'
import { IncomeStatementBody } from 'lib-common/generated/api-types/incomestatement'
import { IncomeValue } from 'lib-common/generated/api-types/invoicing'
import { InvoiceStatus } from 'lib-common/generated/api-types/invoicing'
import { JsonOf } from 'lib-common/json'
import { Language } from 'lib-common/generated/api-types/daycare'
import { MailingAddress } from 'lib-common/generated/api-types/daycare'
Expand Down Expand Up @@ -631,6 +632,43 @@ export interface DevIncome {
worksAtEcha: boolean
}

/**
* Generated from fi.espoo.evaka.shared.dev.DevInvoice
*/
export interface DevInvoice {
areaId: UUID
codebtor: UUID | null
createdAt: HelsinkiDateTime | null
dueDate: LocalDate
headOfFamilyId: UUID
id: UUID
invoiceDate: LocalDate
number: number | null
periodEnd: LocalDate
periodStart: LocalDate
rows: DevInvoiceRow[]
sentAt: HelsinkiDateTime | null
sentBy: UUID | null
status: InvoiceStatus
}

/**
* Generated from fi.espoo.evaka.shared.dev.DevInvoiceRow
*/
export interface DevInvoiceRow {
amount: number
childId: UUID
correctionId: UUID | null
description: string
id: UUID
idx: number | null
periodEnd: LocalDate
periodStart: LocalDate
product: string
unitId: UUID
unitPrice: number
}

/**
* Generated from fi.espoo.evaka.shared.dev.DevMobileDevice
*/
Expand Down Expand Up @@ -1349,6 +1387,29 @@ export function deserializeJsonDevIncome(json: JsonOf<DevIncome>): DevIncome {
}


export function deserializeJsonDevInvoice(json: JsonOf<DevInvoice>): DevInvoice {
return {
...json,
createdAt: (json.createdAt != null) ? HelsinkiDateTime.parseIso(json.createdAt) : null,
dueDate: LocalDate.parseIso(json.dueDate),
invoiceDate: LocalDate.parseIso(json.invoiceDate),
periodEnd: LocalDate.parseIso(json.periodEnd),
periodStart: LocalDate.parseIso(json.periodStart),
rows: json.rows.map(e => deserializeJsonDevInvoiceRow(e)),
sentAt: (json.sentAt != null) ? HelsinkiDateTime.parseIso(json.sentAt) : null
}
}


export function deserializeJsonDevInvoiceRow(json: JsonOf<DevInvoiceRow>): DevInvoiceRow {
return {
...json,
periodEnd: LocalDate.parseIso(json.periodEnd),
periodStart: LocalDate.parseIso(json.periodStart)
}
}


export function deserializeJsonDevOtherAssistanceMeasure(json: JsonOf<DevOtherAssistanceMeasure>): DevOtherAssistanceMeasure {
return {
...json,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import uniqBy from 'lodash/uniqBy'
import React from 'react'
import { useNavigate } from 'react-router-dom'
import styled from 'styled-components'
Expand Down Expand Up @@ -325,12 +324,7 @@ const InvoiceTableBody = React.memo(function InvoiceTableBody({
<NameWithSsn {...item.headOfFamily} i18n={i18n} />
</Td>
<Td>
<ChildrenCell
people={uniqBy(
item.rows.map(({ child }) => child),
({ id }) => id
)}
/>
<ChildrenCell people={item.children} />
</Td>
<Td>{`${item.periodStart.format()} - ${item.periodEnd.format()}`}</Td>
<Td data-qa="invoice-created-at">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { useState } from 'react'
import { Link } from 'react-router-dom'

import { wrapResult } from 'lib-common/api'
import { Invoice } from 'lib-common/generated/api-types/invoicing'
import { formatCents } from 'lib-common/money'
import { UUID } from 'lib-common/types'
import { useApiState } from 'lib-common/utils/useRestApi'
Expand Down Expand Up @@ -58,20 +57,18 @@ export default React.memo(function PersonInvoices({
</Tr>
</Thead>
<Tbody>
{orderBy(invoices, ['sentAt'], ['desc']).map(
(invoice: Invoice) => (
<Tr key={invoice.id} data-qa="table-invoice-row">
<Td>
<Link to={`/finance/invoices/${invoice.id}`}>
Lasku{' '}
{`${invoice.periodStart.format()} - ${invoice.periodEnd.format()}`}
</Link>
</Td>
<Td>{formatCents(invoice.totalPrice)}</Td>
<StatusTd>{i18n.invoice.status[invoice.status]}</StatusTd>
</Tr>
)
)}
{orderBy(invoices, ['sentAt'], ['desc']).map((invoice) => (
<Tr key={invoice.id} data-qa="table-invoice-row">
<Td>
<Link to={`/finance/invoices/${invoice.id}`}>
Lasku{' '}
{`${invoice.periodStart.format()} - ${invoice.periodEnd.format()}`}
</Link>
</Td>
<Td>{formatCents(invoice.totalPrice)}</Td>
<StatusTd>{i18n.invoice.status[invoice.status]}</StatusTd>
</Tr>
))}
</Tbody>
</Table>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { IncomeNotification } from 'lib-common/generated/api-types/invoicing'
import { IncomeRequest } from 'lib-common/generated/api-types/invoicing'
import { IncomeTypeOptions } from 'lib-common/generated/api-types/invoicing'
import { IncomeWithPermittedActions } from 'lib-common/generated/api-types/invoicing'
import { Invoice } from 'lib-common/generated/api-types/invoicing'
import { InvoiceCodes } from 'lib-common/generated/api-types/invoicing'
import { InvoiceCorrectionInsert } from 'lib-common/generated/api-types/invoicing'
import { InvoiceCorrectionWithPermittedActions } from 'lib-common/generated/api-types/invoicing'
import { InvoiceDetailed } from 'lib-common/generated/api-types/invoicing'
import { InvoiceDetailedResponse } from 'lib-common/generated/api-types/invoicing'
import { InvoicePayload } from 'lib-common/generated/api-types/invoicing'
import { JsonCompatible } from 'lib-common/json'
Expand Down Expand Up @@ -53,8 +53,8 @@ import { deserializeJsonFeeDecisionDetailed } from 'lib-common/generated/api-typ
import { deserializeJsonFeeThresholdsWithId } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonIncomeNotification } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonIncomeWithPermittedActions } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonInvoice } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonInvoiceCorrectionWithPermittedActions } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonInvoiceDetailed } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonInvoiceDetailedResponse } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonPagedFeeDecisionSummaries } from 'lib-common/generated/api-types/invoicing'
import { deserializeJsonPagedInvoiceSummaryResponses } from 'lib-common/generated/api-types/invoicing'
Expand Down Expand Up @@ -587,12 +587,12 @@ export async function getHeadOfFamilyInvoices(
request: {
id: UUID
}
): Promise<Invoice[]> {
const { data: json } = await client.request<JsonOf<Invoice[]>>({
): Promise<InvoiceDetailed[]> {
const { data: json } = await client.request<JsonOf<InvoiceDetailed[]>>({
url: uri`/employee/invoices/head-of-family/${request.id}`.toString(),
method: 'GET'
})
return json.map(e => deserializeJsonInvoice(e))
return json.map(e => deserializeJsonInvoiceDetailed(e))
}


Expand Down
Loading

0 comments on commit c75113d

Please sign in to comment.