From 7e53eea27a6b7d23edb4e00102d33a909e2ab2eb Mon Sep 17 00:00:00 2001 From: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Date: Sun, 7 Jun 2026 15:41:26 +0800 Subject: [PATCH] feat(showcase): make invoice line amount a computed (expression) currency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give showcase_invoice_line.amount an `expression` (quantity × unit_price). It stays a stored currency column — the server only treats `type: 'formula'` as computed, so the client-sent value is persisted and the parent Invoice.total summary still rolls it up — but the new line-item grid reads the expression to render Amount read-only and recompute it live as quantity/unit_price change. Co-Authored-By: Claude Opus 4.8 --- .../app-showcase/src/objects/invoice.object.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/app-showcase/src/objects/invoice.object.ts b/examples/app-showcase/src/objects/invoice.object.ts index 0e4746850..93c1d35e1 100644 --- a/examples/app-showcase/src/objects/invoice.object.ts +++ b/examples/app-showcase/src/objects/invoice.object.ts @@ -61,6 +61,18 @@ export const InvoiceLine = ObjectSchema.create({ product: Field.text({ label: 'Product', required: true, maxLength: 200 }), quantity: Field.number({ label: 'Qty', required: true, min: 0, defaultValue: 1 }), unit_price: Field.currency({ label: 'Unit Price', scale: 2, min: 0 }), - amount: Field.currency({ label: 'Amount', scale: 2, min: 0 }), + // Amount = Qty × Unit Price. Kept as a *stored* currency column (so the + // parent Invoice.total summary can roll it up — summary aggregation reads + // stored columns, not on-read formula fields), but the `expression` makes + // the line-item grid render it READ-ONLY and recompute it live client-side + // as quantity/unit_price change, then persist the computed value. The + // server does not treat a non-`formula` field's expression as computed, so + // the client-sent value is stored as-is. + amount: Field.currency({ + label: 'Amount', + scale: 2, + min: 0, + expression: 'record.quantity * record.unit_price', + }), }, });