* feat(dimensions): PR7 producers — invoices/supplier invoices carry dims, generators propagate, BulkBook + templates + MCP bags
Source documents now carry dimension tags and every entry generator
propagates them onto journal lines (dev_docs/dimensions_implementation_plan.md PR7):
- invoices/supplier_invoices.default_dimensions + per-item dimensions
(migration 20260702200000; jsonb DEFAULT '{}' + object CHECK)
- invoice-entries: issuance/payment/cash/credit propagate — item bags merge
over the invoice default per revenue line (account+bag aggregation
identity), payment vouchers re-propagate the linked invoice's bag onto
every leg incl. FX result lines; ROT/RUT 1513 carries the item bag
- supplier-invoice-entries: registration/payment/cash/privately-paid/credit
propagate with the same merge rules (expense buckets keyed account+bag)
- bulk_book_transactions RPC persists per-line bags + derives
cost_center/project mirrors in SQL (migration 20260702201000; malformed
bags rejected with BULK_BOOK_INVALID_DIMENSIONS); route merges the header
default into template/manual lines
- counterparty templates: LinePatternEntry.dimensions learned from SIE
voucher history (kept only when every occurrence agrees), applied to
business lines on booking; QuickReviewDialog shows a dims badge
- categorize: staged dimensions bag tags business lines only (bank/VAT
untagged); credit/convert/inbox copy paths carry bags forward
- propose-payment/send-lines stamp the invoice default so the editable
payment grid books what the preview shows; mark-paid override lines
accept dimensions
- UI: InvoiceEditor + NewSupplierInvoiceForm header KS/Projekt pair with
per-row override; BulkBookDialog header default pair (both tabs)
- MCP: default_dimensions/items[].dimensions on create_invoice +
create_supplier_invoice_from_inbox, dimensions on categorize_transaction,
per-line bags on bulk_book_transactions — resolve-don't-select via the
shared registry helpers, resolutions echoed
32 new propagation unit tests + 4 pg-real tests for the RPC migration.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* test: use roundOre in new dims rounding assertions (ratchet)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: copy dimension bag per payment line, document dimensionsBagKey normalization contract (review)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
55 lines
2.9 KiB
SQL
55 lines
2.9 KiB
SQL
-- Dimensions PR7 (producers): source documents carry dimension tags so the
|
|
-- entry generators can propagate them onto journal lines.
|
|
--
|
|
-- invoices.default_dimensions / supplier_invoices.default_dimensions
|
|
-- {sie_dim_no: code} bag applied to EVERY generated line (issuance,
|
|
-- payment, credit — payment vouchers re-propagate from the linked
|
|
-- invoice under both accounting methods).
|
|
-- invoice_items.dimensions / supplier_invoice_items.dimensions
|
|
-- per-item bag merged OVER the invoice default on the revenue/expense
|
|
-- line that item books to (item wins per key).
|
|
--
|
|
-- Same shape + CHECK as journal_entry_lines.dimensions (20260702084500).
|
|
-- No indexes: these columns are read via their parent row when generating
|
|
-- entries, never containment-queried — reporting queries hit the GIN on
|
|
-- journal_entry_lines. NOT NULL DEFAULT '{}' is metadata-only on PG11+.
|
|
--
|
|
-- pg-test: covered-by — plain column adds with a type CHECK, no
|
|
-- trigger/RPC/RLS/DEFERRABLE change. Propagation logic is TS-side
|
|
-- (lib/bookkeeping/{invoice,supplier-invoice}-entries.ts unit tests).
|
|
|
|
ALTER TABLE public.invoices
|
|
ADD COLUMN default_dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
|
|
ALTER TABLE public.invoices
|
|
ADD CONSTRAINT invoices_default_dimensions_is_object
|
|
CHECK (jsonb_typeof(default_dimensions) = 'object');
|
|
|
|
ALTER TABLE public.invoice_items
|
|
ADD COLUMN dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
|
|
ALTER TABLE public.invoice_items
|
|
ADD CONSTRAINT invoice_items_dimensions_is_object
|
|
CHECK (jsonb_typeof(dimensions) = 'object');
|
|
|
|
ALTER TABLE public.supplier_invoices
|
|
ADD COLUMN default_dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
|
|
ALTER TABLE public.supplier_invoices
|
|
ADD CONSTRAINT supplier_invoices_default_dimensions_is_object
|
|
CHECK (jsonb_typeof(default_dimensions) = 'object');
|
|
|
|
ALTER TABLE public.supplier_invoice_items
|
|
ADD COLUMN dimensions jsonb NOT NULL DEFAULT '{}'::jsonb;
|
|
ALTER TABLE public.supplier_invoice_items
|
|
ADD CONSTRAINT supplier_invoice_items_dimensions_is_object
|
|
CHECK (jsonb_typeof(dimensions) = 'object');
|
|
|
|
COMMENT ON COLUMN public.invoices.default_dimensions IS
|
|
'Dimension bag {sie_dim_no: code} applied to every journal line generated from this invoice; invoice_items.dimensions merges over it per revenue line. See lib/bookkeeping/invoice-entries.ts.';
|
|
COMMENT ON COLUMN public.invoice_items.dimensions IS
|
|
'Per-item dimension bag merged over invoices.default_dimensions on the revenue line this item books to.';
|
|
COMMENT ON COLUMN public.supplier_invoices.default_dimensions IS
|
|
'Dimension bag {sie_dim_no: code} applied to every journal line generated from this supplier invoice; supplier_invoice_items.dimensions merges over it per expense line. See lib/bookkeeping/supplier-invoice-entries.ts.';
|
|
COMMENT ON COLUMN public.supplier_invoice_items.dimensions IS
|
|
'Per-item dimension bag merged over supplier_invoices.default_dimensions on the expense line this item books to.';
|
|
|
|
NOTIFY pgrst, 'reload schema';
|