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:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user