feat(recurring): carry dimension bags on recurring invoice schedules (#1272)
Schedules and their template items now store {sie_dim_no: code} bags
(default_dimensions / dimensions), and the cron generator copies them
onto every spawned invoice + item, so recurring invoices book with the
same projekt/kostnadsstalle tags a manual invoice would. Wired through
the web CRUD routes, the staged-operation executors, and the MCP
create/update/list schedule tools (resolve-don't-select, resolutions
echoed in the preview).
Migration 20260728090000 adds the two jsonb columns (same shape+CHECK
as invoices/invoice_items, PR7 producer parity).
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
65c6d4c178
commit
951b33363b
@@ -0,0 +1,37 @@
|
||||
-- Recurring schedules carry dimension tags so cron-generated invoices are
|
||||
-- born with the same {sie_dim_no: code} bags a manually created invoice
|
||||
-- would have (dimensions PR7 producer parity).
|
||||
--
|
||||
-- recurring_invoice_schedules.default_dimensions
|
||||
-- copied verbatim onto invoices.default_dimensions at spawn time; the
|
||||
-- invoice entry generators then apply it to every journal line.
|
||||
-- recurring_invoice_schedule_items.dimensions
|
||||
-- copied onto invoice_items.dimensions per generated item; merged OVER
|
||||
-- the invoice default on the revenue line that item books to.
|
||||
--
|
||||
-- Same shape + CHECK as invoices/invoice_items (20260702200000). No indexes:
|
||||
-- read via their parent row when spawning invoices, never containment-queried.
|
||||
-- NOT NULL DEFAULT '{}' is metadata-only on PG11+ (no table rewrite).
|
||||
--
|
||||
-- pg-test: covered-by — plain column adds with a type CHECK, no
|
||||
-- trigger/RPC/RLS/DEFERRABLE change. Propagation logic is TS-side
|
||||
-- (lib/invoices/recurring-schedule-service.ts unit tests).
|
||||
|
||||
ALTER TABLE public.recurring_invoice_schedules
|
||||
ADD COLUMN default_dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||
ALTER TABLE public.recurring_invoice_schedules
|
||||
ADD CONSTRAINT recurring_invoice_schedules_default_dimensions_is_object
|
||||
CHECK (jsonb_typeof(default_dimensions) = 'object');
|
||||
|
||||
ALTER TABLE public.recurring_invoice_schedule_items
|
||||
ADD COLUMN dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||
ALTER TABLE public.recurring_invoice_schedule_items
|
||||
ADD CONSTRAINT recurring_invoice_schedule_items_dimensions_is_object
|
||||
CHECK (jsonb_typeof(dimensions) = 'object');
|
||||
|
||||
COMMENT ON COLUMN public.recurring_invoice_schedules.default_dimensions IS
|
||||
'Dimension bag {sie_dim_no: code} copied onto invoices.default_dimensions for every invoice this schedule generates. See lib/invoices/recurring-schedule-service.ts.';
|
||||
COMMENT ON COLUMN public.recurring_invoice_schedule_items.dimensions IS
|
||||
'Per-item dimension bag copied onto invoice_items.dimensions for the generated item; merges over the schedule default on the revenue line.';
|
||||
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
Reference in New Issue
Block a user