feat(orders): reopen cancelled orders only after confirmation; accurate sales
Docker Image bauen und veroeffentlichen / build-and-push (push) Successful in 2m24s

Cancelled orders:
- Moving an order out of STORNIERT is possible again, but only after a
  warning is confirmed in the status form (OrderStatusForm); without
  the confirmation the server changes nothing.
- Reopening books the counter-entry to the cancellation: goods that the
  cancellation restocked are deducted again (atomically, only if enough
  stock is left, otherwise the order stays cancelled). A later second
  cancellation therefore restocks +1 again instead of leaving +2.
- The warning states that no new payment is collected.

Dashboard figures:
- One definition of a counted sale (lib/sales.ts): not unpaid (NEU),
  not cancelled, no refunded return. Used for revenue today/month, sold
  glasses, average cart, top products/categories, revenue trend and
  repeat customers.
- "Verkaufte Gläser" previously summed every order item, including
  cancelled orders and refunded returns.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Opus 5.5 committed 2026-09-27 01:14:12 +02:00
1 parent dc1523aafd
commit e0b47faf45
11 files changed
+243 -82

No files matched your search

+21 -12
View File
@@ -1,5 +1,5 @@
import { describe, test, expect } from "vitest";
import { isOrderStatusChangeAllowed, needsRestockOnCancel, planInventoryEdit } from "./inventory";
import { needsConfirmToChangeStatus, needsReserveOnReopen, needsRestockOnCancel, planInventoryEdit } from "./inventory";
describe("planInventoryEdit", () => {
test("laesst den Bestand unberuehrt, wenn das Feld nicht geaendert wurde", () => {
@@ -44,20 +44,29 @@ describe("needsRestockOnCancel", () => {
});
});
describe("isOrderStatusChangeAllowed", () => {
test("a cancelled order cannot be reopened (else a second cancel restocks again: +2 instead of +1)", () => {
expect(isOrderStatusChangeAllowed("STORNIERT", "BEZAHLT")).toBe(false);
expect(isOrderStatusChangeAllowed("STORNIERT", "NEU")).toBe(false);
expect(isOrderStatusChangeAllowed("STORNIERT", "VERSENDET")).toBe(false);
describe("needsConfirmToChangeStatus", () => {
test("leaving a cancelled order requires an explicit confirmation", () => {
expect(needsConfirmToChangeStatus("STORNIERT", "BEZAHLT")).toBe(true);
expect(needsConfirmToChangeStatus("STORNIERT", "NEU")).toBe(true);
expect(needsConfirmToChangeStatus("STORNIERT", "VERSENDET")).toBe(true);
});
test("re-selecting the cancelled status is a harmless no-op", () => {
expect(isOrderStatusChangeAllowed("STORNIERT", "STORNIERT")).toBe(true);
test("re-selecting the cancelled status or moving active orders needs no confirmation", () => {
expect(needsConfirmToChangeStatus("STORNIERT", "STORNIERT")).toBe(false);
expect(needsConfirmToChangeStatus("BEZAHLT", "VERSENDET")).toBe(false);
expect(needsConfirmToChangeStatus("VERSENDET", "STORNIERT")).toBe(false);
});
});
test("active orders can move between statuses and be cancelled", () => {
expect(isOrderStatusChangeAllowed("BEZAHLT", "VERSENDET")).toBe(true);
expect(isOrderStatusChangeAllowed("VERSENDET", "STORNIERT")).toBe(true);
expect(isOrderStatusChangeAllowed("NEU", "BEZAHLT")).toBe(true);
describe("needsReserveOnReopen", () => {
test("reopening takes back exactly what the cancellation restocked (no +2 on the next cancel)", () => {
for (const status of [null, "ANGEFRAGT", "ANGENOMMEN", "ABGELEHNT", "ERSTATTET"] as const) {
expect(needsReserveOnReopen(status)).toBe(needsRestockOnCancel(status));
}
});
test("an order whose return was refunded was not restocked on cancel, so nothing is deducted", () => {
expect(needsReserveOnReopen("ERSTATTET")).toBe(false);
expect(needsReserveOnReopen(null)).toBe(true);
});
});