JEISA-WEBAPP/pocketbase/pb_migrations/1786500001_added_quote_deleted_flag.js
Dave 9d2ba5a430 feat(quotes): delete quotes from the app, add customer inline with full details
Two things that meant going into PocketBase by hand or jumping between
screens.

Deleting a quote
- Quotes had no delete action - a test quote could only be removed
  through the PocketBase admin UI. Purchase orders already soft delete
  by flipping a `deleted` flag, so quotes now do the same: the Delete
  action confirms first, then hides the quote from the list while the
  record and its PDF stay in PocketBase for audit.
- The quotes list filters out soft-deleted quotes, so a deleted quote
  is out of the way but recoverable by clearing the flag.

Adding a customer while writing a quote
- Typing a customer name that was not in the list used to create a
  name-only stub, which then had to be edited from the Customers screen
  before the quote could show an address or VAT number.
- The picker now opens the full customer form right there - address,
  VAT number, email and phone - with the name pre-filled. The new
  customer is created, added to the list and selected, so the quote
  carries on and the PDF has the details.
2026-10-21 05:09:11 +02:00

50 lines
1.7 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
// =========================================================================
// quotes — add a `deleted` flag for soft delete
// =========================================================================
//
// Purchase orders already soft delete by flipping a `deleted` boolean:
// the record and its PDF stay in PocketBase for audit, but the list
// hides it. Quotes had no such flag, so a test quote could only be
// removed by opening the PocketBase admin UI by hand.
//
// This adds the same flag to `quotes` so the quote list can hide a
// deleted quote the same way, and gives the app a Delete action.
//
// Existing quotes keep deleted = false (the field default), so nothing
// disappears from the list.
//
// NOTE: this migration is applied directly to the live PB instance by
// scripts/add-quote-deleted-flag.mjs.
// =========================================================================
migrate((app) => {
const collection = app.findCollectionByNameOrId("pbc_134296766"); // quotes
if (!collection) {
throw new Error("quotes collection not found — aborting.");
}
if (!collection.fields.some((f) => f.name === "deleted")) {
collection.fields.push({
hidden: false,
id: "bool_quote_deleted",
name: "deleted",
presentable: false,
required: false,
system: false,
type: "bool",
});
}
return app.save(collection);
}, (app) => {
// Rollback: drop the `deleted` field we added.
const collection = app.findCollectionByNameOrId("pbc_134296766"); // quotes
if (!collection) return;
collection.fields = collection.fields.filter((f) => f.name !== "deleted");
return app.save(collection);
});