Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/35045-dynamic-summary-tenant-child.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/spec': minor
'@objectstack/objectql': patch
---

feat(spec, objectql): a `summary` over a plain `dynamic` currency amount may declare `currencyMode: 'dynamic'`

Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up owed — skills/objectstack-data/evals/objects-fields-relationships.json (eval 20's expected output still says `dynamic` is admitted only on a roll-up of a home amount; no SKILL.md teaches a summary's currency, and content/docs/data-modeling/currency.mdx is updated here)

A `summary` (`sum`, `min`, `max`, `avg`) that totals a child `currency` field in `dynamic` mode (no `currencyConfig`, or `currencyMode: 'dynamic'`) may now declare `currencyConfig: { currencyMode: 'dynamic' }`, with no `defaultCurrency`. A `dynamic` amount is in the tenant default currency, `localization.currency`, by definition, so its total is too, and the Console's roll-up faces draw it in that currency, as they already draw a roll-up of a stored home amount. Before, `defineStack` (`os validate`, the build) and a save or publish through the metadata API refused it with "… is not a stored home amount, so its rows are not known to be in the home currency", so a total of tenant-currency amounts (a timesheet's cost over its time entries' cost) rendered as a bare number beside currency cells.

Levels follow the metadata protocol: `@objectstack/spec` takes `minor` for the newly accepted declaration and the new export; `@objectstack/objectql` takes `patch` (its door reads the spec predicate, no protocol of its own moves).

Both doors read one new predicate, `isTenantCurrencyAmount` (`@objectstack/spec/data`): a stored `currency` field in `dynamic` mode, of which a stored home amount is one. Unchanged:

- A summary that declares no `currencyConfig` still has no currency: nothing is inferred.
- `dynamic` over a record-mode child amount is refused as before, prescribing its stored home amount (or `currencyMode: 'record'` when the amounts follow this record through the roll-up's master_detail); over a `fixed` child amount it is refused prescribing that code; over a plain `number`, a `formula` or another `summary` it is refused.

The refusal's wording moves with the admitted set: its head now reads "`currencyMode: 'dynamic'` on a summary is admitted only for a roll-up of an amount in the organization's home currency: a child `currency` field in `dynamic` mode (an absent `currencyMode` is `dynamic`), a stored home amount included, …", a child that is not a `currency` field is named by its type ("is a 'number' field, not a `currency` field in `dynamic` mode"), and the prescription lists the child's amounts in the home currency instead of its home amounts alone. The object door's list of admitted roll-up currencies says the same.
31 changes: 17 additions & 14 deletions content/docs/data-modeling/currency.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,17 @@ that column. A `count` column never carries `currencyField`. See the
it with **`INVALID_METADATA` / 422** and the same message, whichever object is saved
second.
- **A `summary` declaring `currencyMode: 'dynamic'`** (or a `currencyConfig` with no
`currencyMode`) is admitted only for a `sum`, `avg`, `min` or `max` of a stored home
amount, a child field that a `homeAmount.field` on the child object names (see
[Totals in the home currency](#totals-in-the-home-currency)), and naming no currency
code. One over any other child field is refused, naming the child's home amounts:
`defineStack` (`os validate` and the build) refuses it, and on a running server a save or
publish through the metadata API refuses it with **`INVALID_METADATA` / 422** and the
same message, whichever object is saved second, judging each object as the server serves
it, extensions included. A `homeAmount` makes a field a home amount only where it is
valid as declared, so an extension cannot make a plain number one by naming it. The
object itself refuses one that names no child field, one that names a currency code, and
a `count` in every mode, at every door.
`currencyMode`) is admitted only for a `sum`, `avg`, `min` or `max` of an amount in the
home currency, a child `currency` field in `dynamic` mode, a stored home amount
included (see [Totals in the home currency](#totals-in-the-home-currency)), and naming
no currency code. One over any other child field (a record-mode or `fixed` amount, a
plain number, a formula, another roll-up) is refused, naming the child's amounts in the
home currency: `defineStack` (`os validate` and the build) refuses it, and on a running
server a save or publish through the metadata API refuses it with
**`INVALID_METADATA` / 422** and the same message, whichever object is saved second,
judging each object as the server serves it, extensions included. The object itself
refuses one that names no child field, one that names a currency code, and a `count` in
every mode, at every door.
- **A dataset measure that declares `currency` over a record-mode amount** is refused at
compile with **`DATASET_INVALID` / 400**, and so is a `currency` on a derived measure that
sums record-mode amounts. One code cannot label amounts in several currencies: delete
Expand Down Expand Up @@ -460,7 +460,9 @@ A `summary` stores one number and says its currency only through its own `curren
To draw a roll-up of the home field as money in the home currency, declare
`currencyMode: 'dynamic'` on it, with no code: every row of the home field is in the
organization's home currency, so the total is too, and the metadata never names which
currency that is.
currency that is. The same holds for a roll-up of any plain `dynamic` amount, such as a
timesheet's total of its time entries' cost: a `dynamic` amount is in the tenant default
currency by definition, the one setting that is the home currency, so its total is too.

```typescript
actual_cost: {
Expand All @@ -474,8 +476,9 @@ actual_cost: {
The Console then draws the total in `localization.currency` on the record page and in the
list cell (`$250.00` under a USD home currency, `CN¥1,800.00` under CNY), the same currency
a dashboard metric over `amount_home` shows. Without the declaration the roll-up stays a
bare number. `dynamic` on any other roll-up is refused, because the amounts it reads are
not known to be in the home currency: by `defineStack` (`os validate` and the build), and
bare number. `dynamic` on a roll-up of any other child field (a record-mode or `fixed`
amount, a plain number, a formula, another roll-up) is refused, because the amounts it
reads are not known to be in the home currency: by `defineStack` (`os validate` and the build), and
by a save or publish through the metadata API on a running server (see
[Roll-ups and datasets](#roll-ups-and-datasets)).

Expand Down
3 changes: 2 additions & 1 deletion content/docs/data-modeling/field-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@ grid cell: a number is formatted as a number field formats it, keeping its own p
the field sets a `scale` (`15750.5` reads `15,750.5`; at `scale: 2`, `15,750.50`), and anything
else is shown as text. A roll-up that declares its currency in `currencyConfig` is drawn as
money instead: `fixed` in its code, `record` in the parent's code, and `dynamic`, admitted
only on a roll-up of a stored home amount, in the organization's home currency
only on a roll-up of an amount in the home currency (a `dynamic` `currency` field, a stored
home amount included), in the organization's home currency
([Currency fields](/docs/data-modeling/currency#totals-in-the-home-currency)).

### `autonumber`
Expand Down
2 changes: 1 addition & 1 deletion content/docs/references/data/field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const result = CurrencyConfigSchema.parse(data);
| **summaryOperations** | `{ object: string; field?: string; function: Enum<'count' \| 'sum' \| 'min' \| 'max' \| 'avg'>; relationshipField?: string; … }` | optional | Roll-up summary definition. The engine recomputes the value when child records are inserted/updated/deleted. |
| **language** | `string` | optional | Programming language for syntax highlighting (e.g., javascript, python, sql) |
| **step** | `number` | optional | Step increment for slider (default: 1) |
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up a stored home amount (a child field some `homeAmount.field` names) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up an amount in the home currency (a child `currency` field in `dynamic` mode, a stored home amount included) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
| **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) |
| **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. |
| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") |
Expand Down
4 changes: 2 additions & 2 deletions content/docs/references/data/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const result = ApiMethod.parse(data);
| **summaryOperations** | `{ object: string; field?: string; function: Enum<'count' \| 'sum' \| 'min' \| 'max' \| 'avg'>; relationshipField?: string; … }` | optional | Roll-up summary definition. The engine recomputes the value when child records are inserted/updated/deleted. |
| **language** | `string` | optional | Programming language for syntax highlighting (e.g., javascript, python, sql) |
| **step** | `number` | optional | Step increment for slider (default: 1) |
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up a stored home amount (a child field some `homeAmount.field` names) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up an amount in the home currency (a child `currency` field in `dynamic` mode, a stored home amount included) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
| **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) |
| **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. |
| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") |
Expand Down Expand Up @@ -660,7 +660,7 @@ const result = ApiMethod.parse(data);
| **summaryOperations** | `{ object: string; field?: string; function: Enum<'count' \| 'sum' \| 'min' \| 'max' \| 'avg'>; relationshipField?: string; … }` | optional | Roll-up summary definition. The engine recomputes the value when child records are inserted/updated/deleted. |
| **language** | `string` | optional | Programming language for syntax highlighting (e.g., javascript, python, sql) |
| **step** | `number` | optional | Step increment for slider (default: 1) |
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up a stored home amount (a child field some `homeAmount.field` names) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up an amount in the home currency (a child `currency` field in `dynamic` mode, a stored home amount included) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
| **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) |
| **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. |
| **group** | `string` | optional | Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system") |
Expand Down
Loading
Loading