fix(offers): deleting an order returns the source offer to active

deleteOrder only nulled quotations.order_id and left status "ordered" -
a dead end (ordered only transitions to invalidated), so the offer could
never be ordered again and the "Vytvorit objednavku" button stayed
hidden. The delete transaction now reverts ordered -> active together
with the back-reference clear; regression test included.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-06-10 19:02:19 +02:00
parent 5c9ebddf50
commit ffae1a4e74
2 changed files with 48 additions and 1 deletions

View File

@@ -761,7 +761,16 @@ export async function deleteOrder(id: number, deleteFiles = false) {
}
}
// Clear quotation back-reference (matching PHP)
// Clear the quotation back-reference AND revert its status: an
// `ordered` offer with no order is a dead end (the transition table
// only allows ordered -> invalidated), so it goes back to `active`,
// making it orderable again.
await tx.quotations.updateMany({
where: { order_id: id, status: "ordered" },
data: { order_id: null, status: "active", modified_at: new Date() },
});
// Backstop for rows in any other status (shouldn't exist — only an
// ordered offer can hold an order_id).
await tx.quotations.updateMany({
where: { order_id: id },
data: { order_id: null },