Rechnungen: Rabatt je Position

This commit is contained in:
Kundencenter 2026-09-28 11:01:19 +02:00
parent e7e5f31ebe
commit 96df0c334a
5 changed files with 51 additions and 22 deletions

View file

@ -248,3 +248,28 @@ describe('Rechnungen: eingefrorener Absender-/Empfänger-Stand, atomare Statuswe
expect(invAfter.status).toBe('cancelled'); // nicht doppelt storniert, genau ein Storno-Verweis
});
});
describe('Rechnungspositionen: Rabatt je Position', () => {
it('Rabatt mindert Netto/USt/Brutto korrekt, wirkt auf die Summen, wird im PDF ausgeliefert und bei Storno übernommen', async () => {
const admin = await staff('disc-admin@example.com', 'superadmin'); const acc = await staff('disc-acc@example.com', 'accounting');
await call(app, admin, 'PUT', '/admin/company-settings', COMPANY);
const A = await customer(admin, 'Kunde Rabatt', 'disc-a@example.com');
const draft = (await call(app, acc, 'POST', '/invoices', { orgId: A.org })).json();
await call(app, acc, 'PUT', `/invoices/${draft.id}/items`, { items: [
{ description: 'Mit Rabatt', quantity: 1, unitPriceNetCents: 10000, taxBp: 1900, discountBp: 1000 }, // 10 %
{ description: 'Ohne Rabatt', quantity: 1, unitPriceNetCents: 5000, taxBp: 1900 },
] });
const inv = (await call(app, acc, 'GET', `/invoices/${draft.id}`)).json();
expect(inv.items[0]).toMatchObject({ discountBp: 1000, netCents: 9000, taxCents: 1710, grossCents: 10710 });
expect(inv.items[1]).toMatchObject({ discountBp: 0, netCents: 5000 });
expect(inv.totalNetCents).toBe(14000); expect(inv.totalGrossCents).toBe(16660);
await call(app, acc, 'POST', `/invoices/${draft.id}/issue`);
const pdf = await app.inject({ method: 'GET', url: `/v1/invoices/${draft.id}/pdf`, headers: { cookie: acc.cookie, 'x-csrf-token': acc.csrf } });
expect(pdf.statusCode).toBe(200);
const credit = (await call(app, acc, 'POST', `/invoices/${draft.id}/cancel`)).json();
const creditItems = (await call(app, acc, 'GET', `/invoices/${credit.creditInvoiceId}`)).json().items;
expect(creditItems.find((i: any) => i.description === 'Mit Rabatt')).toMatchObject({ discountBp: 1000, netCents: -9000 });
});
});