diff --git a/.changeset/35045-dynamic-summary-tenant-child.md b/.changeset/35045-dynamic-summary-tenant-child.md new file mode 100644 index 00000000000..99a449ececc --- /dev/null +++ b/.changeset/35045-dynamic-summary-tenant-child.md @@ -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. diff --git a/content/docs/data-modeling/currency.mdx b/content/docs/data-modeling/currency.mdx index a548a4dea56..340f9a10e28 100644 --- a/content/docs/data-modeling/currency.mdx +++ b/content/docs/data-modeling/currency.mdx @@ -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 @@ -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: { @@ -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)). diff --git a/content/docs/data-modeling/field-types.mdx b/content/docs/data-modeling/field-types.mdx index a01d55862e0..6acdc1c2ee6 100644 --- a/content/docs/data-modeling/field-types.mdx +++ b/content/docs/data-modeling/field-types.mdx @@ -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` diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index 6696ac79dc3..a786416910c 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -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") | diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index 75c9fbba046..8d7d9a336b5 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -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") | @@ -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") | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index 79de59dda95..4576a62d5da 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -105,7 +105,7 @@ Add a new field to an existing object | **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") | @@ -541,7 +541,7 @@ Add a new field to an existing object | **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") | diff --git a/packages/objectql/src/protocol-batch-object-registration.test.ts b/packages/objectql/src/protocol-batch-object-registration.test.ts index e7def62c570..944fa1376b8 100644 --- a/packages/objectql/src/protocol-batch-object-registration.test.ts +++ b/packages/objectql/src/protocol-batch-object-registration.test.ts @@ -603,10 +603,12 @@ describe('[#33593] an extension\'s record-mode amount on a single save and in th // ── [#33713, ADR-0144 D6 and D8 rule 5] A `dynamic` roll-up on a metadata-API save ── // -// `defineStack` admits a `dynamic` summary only over a stored home amount -// (case (d)); a published save through the metadata API answers the same, -// with the same sentence, through the registry's follow door. -describe('[#33713] a metadata-API save of a `dynamic` roll-up over a child field that is not a stored home amount', () => { +// `defineStack` admits a `dynamic` summary only over an amount in the home +// currency, a `dynamic` `currency` field (case (d); seat ruling record +// 7000258793 widened it from a stored home amount alone); a published save +// through the metadata API answers the same, with the same sentence, through +// the registry's follow door. +describe('[#33713] a metadata-API save of a `dynamic` roll-up over a child field that is not an amount in the home currency', () => { const P = 'com.qa.homeroll'; /** The #33659 probe's child: an amount converted at write into `amount_home`, beside amounts that are not home amounts. */ const expense = { @@ -624,6 +626,7 @@ describe('[#33713] a metadata-API save of a `dynamic` roll-up over a child field eur_amount: { name: 'eur_amount', type: 'currency', label: 'EUR', currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' } }, plain: { name: 'plain', type: 'number', label: 'Plain' }, doubled: { name: 'doubled', type: 'formula', label: 'Doubled', expression: 'record.plain * 2', returnType: 'number' }, + cost: { name: 'cost', type: 'currency', label: 'Cost' }, }, }; const total = (field: string, extra: Record = { currencyConfig: { currencyMode: 'dynamic' } }, fn = 'sum') => ({ @@ -645,7 +648,7 @@ describe('[#33713] a metadata-API save of a `dynamic` roll-up over a child field } return undefined; }; - const DYNAMIC_HEAD = "Object 'homeroll_project' field 'total' currencyConfig: `currencyMode: 'dynamic'` on a summary is admitted only for a roll-up of a stored home amount"; + const DYNAMIC_HEAD = "Object 'homeroll_project' field 'total' currencyConfig: `currencyMode: 'dynamic'` on a summary is admitted only for a roll-up of an amount in the organization's home currency"; async function bootWithExpense(): Promise { const h = await boot(); vi.spyOn(console, 'warn').mockImplementation(() => {}); @@ -655,7 +658,7 @@ describe('[#33713] a metadata-API save of a `dynamic` roll-up over a child field } it('refuses one over a fixed EUR amount, a plain number and a formula 422 INVALID_METADATA, with case (d)\'s sentence, and stores nothing', async () => { - for (const [field, says] of [['eur_amount', 'is fixed to EUR'], ['plain', 'is not a stored home amount'], ['doubled', 'is not a stored home amount']] as const) { + for (const [field, says] of [['eur_amount', 'is fixed to EUR'], ['plain', "is a 'number' field"], ['doubled', "is a 'formula' field"]] as const) { const h = await bootWithExpense(); const err = await caught(() => publish(h, 'object', project({ total: total(field) }))); expect(err, field).toMatchObject({ status: 422, code: 'INVALID_METADATA', name: 'RecordCurrencyFollowRefusedError' }); @@ -668,6 +671,13 @@ describe('[#33713] a metadata-API save of a `dynamic` roll-up over a child field } }); + it('a `dynamic` roll-up over a plain `dynamic` amount no `homeAmount` names saves and is served (seat ruling record 7000258793)', async () => { + const h = await bootWithExpense(); + await publish(h, 'object', project({ total: total('cost') })); + expect(registered(h, 'homeroll_project')?.fields?.total?.currencyConfig).toEqual({ currencyMode: 'dynamic' }); + expect(bodyOf(activeRow(h, 'object', 'homeroll_project', P))?.fields?.total?.summaryOperations?.field).toBe('cost'); + }); + it('CONTROL: the #33659 probe shape, a `dynamic` roll-up over the stored home amount, saves and is served', async () => { const h = await bootWithExpense(); await publish(h, 'object', project({ total: total('amount_home') })); diff --git a/packages/objectql/src/record-currency-aggregate-door.ts b/packages/objectql/src/record-currency-aggregate-door.ts index 302544e9241..3d547dd623e 100644 --- a/packages/objectql/src/record-currency-aggregate-door.ts +++ b/packages/objectql/src/record-currency-aggregate-door.ts @@ -83,10 +83,10 @@ import { StandardErrorCode } from '@objectstack/spec/api'; import { + isTenantCurrencyAmount, recordCurrencyDynamicRollupNotHomeError, recordCurrencyFollowedCodeError, recordCurrencyUnfollowedRollupError, - storedHomeAmountSourceOf, } from '@objectstack/spec/data'; import { recordCurrencyFieldOf, recordCurrencyPathOf, type RecordCurrencyPath } from './validation/record-currency-code.js'; @@ -511,12 +511,12 @@ export interface RecordCurrencyFollowRegistryView { * which refuses any such roll-up whatever it declares; * - (d) a `summary` declaring `currencyMode: 'dynamic'` (or a `currencyConfig` * naming no mode) that rolls up `sum` / `avg` / `min` / `max` of a child - * field that is not a stored home amount: no valid `homeAmount` on the child - * as served names it (`storedHomeAmountSourceOf`, which reads a - * `homeAmount` only where it is valid as declared, so an extension cannot - * make a plain number a home amount by naming it). The faces draw such a - * total in the organization's home currency, which its rows are not known - * to be in (ADR-0144 D8 rule 5). Judged at both ends, as (c) is; a child + * field that is not an amount in the home currency: the child as served + * does not declare it a `currency` field in `dynamic` mode + * (`isTenantCurrencyAmount`, `defineStack`'s own test; a stored home amount + * is one such field, and seat ruling record 7000258793 admits every other). + * The faces draw such a total in the organization's home currency, which + * its rows are not known to be in (ADR-0144 D8 rule 5). Judged at both ends, as (c) is; a child * field the child does not hold is no verdict. A child amount in its own * record currency is D6's first, as for (c). * @@ -617,7 +617,7 @@ function* followRefusalsOf( if (!rollup || !declaresDynamicCurrency(def)) continue; const childFields = rollup.child === name ? own : fieldsOf(view.lookup(rollup.child)); if (!childFields || !Object.prototype.hasOwnProperty.call(childFields, rollup.childField)) continue; - if (storedHomeAmountSourceOf(childFields, rollup.childField) !== undefined) continue; + if (isTenantCurrencyAmount(childFields[rollup.childField])) continue; yield [followPairKey('dynamic', name, summaryField, `${rollup.child}.${rollup.childField}`), new RecordCurrencyFollowRefusedError(name, summaryField, recordCurrencyDynamicRollupNotHomeError( { object: name, field: summaryField, fn: rollup.fn, childObject: rollup.child, childField: rollup.childField }, childFields, @@ -669,7 +669,7 @@ function* followRefusalsOf( const childDef = Object.prototype.hasOwnProperty.call(own, rollup.childField) ? own[rollup.childField] : undefined; if (childDef === undefined) continue; if (declaresDynamicCurrency(def)) { - if (storedHomeAmountSourceOf(own, rollup.childField) !== undefined) continue; + if (isTenantCurrencyAmount(childDef)) continue; yield [followPairKey('dynamic', otherName, field, `${name}.${rollup.childField}`), new RecordCurrencyFollowRefusedError(otherName, field, recordCurrencyDynamicRollupNotHomeError( { object: otherName, field, fn: rollup.fn, childObject: name, childField: rollup.childField }, own, diff --git a/packages/objectql/src/record-currency-guards.test.ts b/packages/objectql/src/record-currency-guards.test.ts index 6446b8e2642..3ba98aba146 100644 --- a/packages/objectql/src/record-currency-guards.test.ts +++ b/packages/objectql/src/record-currency-guards.test.ts @@ -1161,11 +1161,14 @@ describe('a single-object save is refused when the currency it follows is not th // ── [#33713, ADR-0144 D6 and D8 rule 5] A `dynamic` roll-up at the single-object save ── // -// `defineStack`'s case (d) admits a `dynamic` summary only over a stored home -// amount. The follow door asks the same of a single save, a batch writer's row -// and a registration run's end, against the objects as served, in the same -// words (`recordCurrencyDynamicRollupNotHomeError`, `@objectstack/spec/data`). -describe('a single-object save is refused a `dynamic` roll-up over a child field that is not a stored home amount (case (d))', () => { +// `defineStack`'s case (d) admits a `dynamic` summary only over an amount in +// the home currency: a child `currency` field in `dynamic` mode, a stored home +// amount included (seat ruling record 7000258793 widened #33659's home amount +// alone). The follow door asks the same of a single save, a batch writer's row +// and a registration run's end, against the objects as served, through the +// same predicate (`isTenantCurrencyAmount`) and in the same words +// (`recordCurrencyDynamicRollupNotHomeError`, `@objectstack/spec/data`). +describe('a single-object save is refused a `dynamic` roll-up over a child field that is not an amount in the home currency (case (d))', () => { async function bootSealed() { const booted = await bootEngine(); booted.engine.registry.sealBareNameHolders(); @@ -1193,6 +1196,8 @@ describe('a single-object save is refused a `dynamic` roll-up over a child field eur_amount: { type: 'currency', currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' } }, plain: { type: 'number' }, doubled: { type: 'formula', expression: 'plain * 2', returnType: 'number' }, + cost: { type: 'currency' }, + cost_dynamic: { type: 'currency', currencyConfig: { currencyMode: 'dynamic' } }, }, }; /** The parent, rolling `fn(hr_expense.field)` up in `currencyConfig` (dynamic unless given; `null` declares none). */ @@ -1221,8 +1226,8 @@ describe('a single-object save is refused a `dynamic` roll-up over a child field it('a `dynamic` roll-up over a fixed EUR amount, a plain number or a formula is refused 422, whichever end registers second, in defineStack\'s words', async () => { for (const [field, says] of [ ['eur_amount', 'is fixed to EUR'], - ['plain', 'is not a stored home amount'], - ['doubled', 'is not a stored home amount'], + ['plain', "is a 'number' field, not a `currency` field in `dynamic` mode"], + ['doubled', "is a 'formula' field, not a `currency` field in `dynamic` mode"], ] as const) { const parent = project(field); for (const order of [[EXPENSE, parent], [parent, EXPENSE]]) { @@ -1262,6 +1267,22 @@ describe('a single-object save is refused a `dynamic` roll-up over a child field } }); + it('a `dynamic` roll-up of a plain `dynamic` amount no `homeAmount` names registers in either order, as defineStack admits it', async () => { + for (const field of ['cost', 'cost_dynamic']) { + for (const [config, fn] of [[{ currencyMode: 'dynamic' }, 'sum'], [{}, 'sum'], [{ currencyMode: 'dynamic' }, 'min'], [{ currencyMode: 'dynamic' }, 'max'], [{ currencyMode: 'dynamic' }, 'avg']] as const) { + const parent = project(field, config, fn); + expect(() => defineStack({ manifest: { id: 'com.example.dyndoor', name: 'dyn-door', version: '1.0.0', type: 'app' }, objects: [parent, EXPENSE] } as Parameters[0])).not.toThrow(); + for (const order of [[EXPENSE, parent], [parent, EXPENSE]]) { + const { engine } = await bootSealed(); + for (const o of order) save(engine, o); + const at = `${field} ${fn} ${JSON.stringify(config)}`; + expect((engine.registry.getObject('hr_project')?.fields as any)?.total?.currencyConfig, at).toEqual(config); + expect(engine.registry.getObject('hr_expense'), at).toBeDefined(); + } + } + } + }); + it('CONTROL: the #33659 probe shape, a `dynamic` roll-up of the stored home amount, registers in either order', async () => { for (const fn of ['sum', 'min', 'max', 'avg']) { for (const order of [[EXPENSE, project('amount_home', undefined, fn)], [project('amount_home', undefined, fn), EXPENSE]]) { @@ -1283,24 +1304,30 @@ describe('a single-object save is refused a `dynamic` roll-up over a child field } }); - it('the child re-saved so that a registered `dynamic` roll-up no longer reads a home amount is refused, naming the roll-up; a run leaving a refused pair as it found it is not refused for it', async () => { + it('the child re-saved so that a registered `dynamic` roll-up no longer reads an amount in the home currency is refused, naming the roll-up; a run leaving a refused pair as it found it is not refused for it', async () => { const { engine } = await bootSealed(); save(engine, EXPENSE); save(engine, project('amount_home')); - const dehomed = { ...EXPENSE, fields: { ...EXPENSE.fields, amount_home: { type: 'currency' } } }; + // A writable plain amount is still in the home currency (seat ruling + // record 7000258793), so de-homing it alone moves nothing: the roll-up + // reads a `dynamic` amount either way. + const writable = { ...EXPENSE, fields: { ...EXPENSE.fields, amount_home: { type: 'currency' } } }; + expect(engine.registry.objectRegistrationRefusal(writable as any, undefined, 'own', { againstRegistry: true })).toBeNull(); + const dehomed = { ...EXPENSE, fields: { ...EXPENSE.fields, amount_home: { type: 'number', readonly: true } } }; const err = await refusalOf(() => save(engine, dehomed)); expect(envelopeOf(err)).toEqual(INVALID_METADATA); expect(err?.name).toBe(FOLLOW_REFUSED); expect(err?.objectName).toBe('hr_project'); expect(err?.fieldName).toBe('total'); - // `defineStack` never meets this pair: its object door refuses a writable home field first. + // `defineStack` never meets this pair: its object door refuses a home field that is no `currency` field first. expect(err?.message).toBe(recordCurrencyDynamicRollupNotHomeError( { object: 'hr_project', field: 'total', fn: 'sum', childObject: 'hr_expense', childField: 'amount_home' }, dehomed.fields, dehomed.fields.amount_home, )); - expect(err?.message).toContain("'hr_expense' stores no home amount"); - expect((engine.registry.getObject('hr_expense')?.fields as any)?.amount_home?.readonly).toBe(true); + expect(err?.message).toContain("'hr_expense.amount_home' is a 'number' field, not a `currency` field in `dynamic` mode"); + expect(err?.message).toContain("The amounts of 'hr_expense' in the home currency are 'cost', 'cost_dynamic'; roll up one of them"); + expect((engine.registry.getObject('hr_expense')?.fields as any)?.amount_home?.type).toBe('currency'); // A roll-up registered past the door (a stored row's hydration): a run that // re-registers the child unchanged leaves the pair as it found it, so its @@ -1312,7 +1339,7 @@ describe('a single-object save is refused a `dynamic` roll-up over a child field second.engine.registry.registerObject(project('amount_home') as any); const run = await refusalOf(() => second.engine.registry.restoringOnRefusal(() => second.engine.registry.registerObject(dehomed as any))); expect(run?.name).toBe(FOLLOW_REFUSED); - expect((second.engine.registry.getObject('hr_expense')?.fields as any)?.amount_home?.readonly).toBe(true); + expect((second.engine.registry.getObject('hr_expense')?.fields as any)?.amount_home?.type).toBe('currency'); }); it('[N6] an `object_extension` adding the roll-up to the parent is judged as the parent is served', async () => { diff --git a/packages/spec/api-surface/data.json b/packages/spec/api-surface/data.json index 324ab151298..8f66581fc7e 100644 --- a/packages/spec/api-surface/data.json +++ b/packages/spec/api-surface/data.json @@ -1047,6 +1047,7 @@ "isSeedFilePath (function)", "isSeedFileReference (function)", "isTenancyDisabled (function)", + "isTenantCurrencyAmount (function)", "isTextFilterOperator (function)", "isTitleEligible (function)", "isUnboundedAbove (function)", diff --git a/packages/spec/export-origins/data.json b/packages/spec/export-origins/data.json index d47139f2136..95141e03536 100644 --- a/packages/spec/export-origins/data.json +++ b/packages/spec/export-origins/data.json @@ -1033,6 +1033,7 @@ "isSeedFilePath": "src/data/seed-file.zod.ts#isSeedFilePath (function)", "isSeedFileReference": "src/data/seed-file.zod.ts#isSeedFileReference (function)", "isTenancyDisabled": "src/data/object.zod.ts#isTenancyDisabled (function)", + "isTenantCurrencyAmount": "src/data/record-currency-path.ts#isTenantCurrencyAmount (function)", "isTextFilterOperator": "src/data/filter-text-operator-declared-type.ts#isTextFilterOperator (function)", "isTitleEligible": "src/data/display-name.ts#isTitleEligible (function)", "isUnboundedAbove": "src/data/calendar-day.ts#isUnboundedAbove (function)", diff --git a/packages/spec/liveness/field.json b/packages/spec/liveness/field.json index e31930cc71b..6873b9a37a5 100644 --- a/packages/spec/liveness/field.json +++ b/packages/spec/liveness/field.json @@ -436,7 +436,7 @@ "verifiedAt": "2026-09-27", "evidenceScope": "in-repo", "evidence": "ui/packages/i18n/src/currency.ts:60 reads field.currencyConfig.defaultCurrency ONLY when currencyConfig.currencyMode is 'fixed' — the second step of resolveFieldCurrency's precedence chain; a 'dynamic' config, or one naming no mode, skips it for the tenant default localization.currency; ui/packages/fields/src/widgets/CurrencyField.tsx:55 calls resolveFieldCurrency and applies the resolved code at :91 through formatAmount, which passes it to Intl.NumberFormat via formatDisplayNumber — measured objectui @25c7d584", - "note": "NARROWED 2026-11-15 (#33713, spec seat 4 claim 6893268160): the engine registry now judges a `dynamic` summary roll-up as `defineStack` does, at a single-object save or publish on a running server and at the end of an install or upgrade run (packages/objectql/src/record-currency-aggregate-door.ts#recordCurrencyFollowRefusal, case (d), against the objects as served, extensions included), in the same words (packages/spec/src/data/record-currency-path.ts#recordCurrencyDynamicRollupNotHomeError). A stored home amount now counts only where its `homeAmount` is valid as declared (packages/spec/src/data/record-currency-path.ts#storedHomeAmountSourceOf), at both doors. The reader is unchanged; verdict unchanged: LIVE. WIDENED 2026-11-15 (#33659, spec seat 4 claim 6890000941): a `summary` with `function` `sum` / `min` / `max` / `avg` that rolls up a stored home amount (a child field some `homeAmount.field` on the child object names) is admitted with `currencyMode: 'dynamic'` and no `defaultCurrency`, the roll-up of ADR-0144 D6's consolidation path in the home currency without metadata naming it (D8 rule 5). The reader that now consumes `dynamic` on a summary is ui/packages/fields/src/currency.ts#summaryDeclaresCurrency, read by both roll-up faces (ui/packages/fields/src/widgets/SummaryField.tsx#SummaryField and ui/packages/fields/src/index.tsx#FormulaCellRenderer), which draw the total through resolveFieldCurrency in the tenant default `localization.currency`, the code ObjectMetricWidget resolves for a tile over the same home field. Judged at the object door (`refuseUnadmittedSummaryCurrency`: a `dynamic` summary naming no child field, or carrying a `defaultCurrency`, stays refused, and a `count` refuses every mode as before) and in `defineStack` (case (d) of `collectRecordCurrencyPathErrors`: any other `dynamic` roll-up is refused). service-analytics is unchanged: `sourceFieldMeta` relays no code for `dynamic`, as for the home field itself. Verdict unchanged: LIVE. NARROWED 2026-11-09 (#31958, claim amend 1, record 6746006322): on a `summary` field the config is refused outside the ADR-0144 D6 admitted roll-up. A `count` roll-up refuses every mode, `fixed` included (a count is never an amount); `dynamic` is refused on every summary, since no reader consumes it there (the Console's roll-up faces read no `currencyConfig`; service-analytics relays only `fixed` and `record`); `record` is refused unless the roll-up runs through the `master_detail` its child amount follows (object door `refuseUnadmittedSummaryCurrency` in data/object.zod.ts, stack door case (c) of `collectRecordCurrencyPathErrors` in stack.zod.ts). `fixed` stays accepted on sum / min / max / avg because a reader consumes it: packages/services/service-analytics/src/plugin.ts sourceFieldMeta relays its `defaultCurrency` for any field type and packages/services/service-analytics/src/measure-currency-coherence.ts#assertMeasureCurrenciesCoherent refuses a measure labelling it another code. The container stays one blanket row and its keys are unchanged, so the verdict stays LIVE. WIDENED 2026-11-09 (#31910, ADR-0144 D2 as amended by #31743, ruling A recorded in 6739066323): a `record`-mode `currencyField` may be the two-segment path `PARENT_FIELD.CODE_FIELD` through a `master_detail` field of the same object, and a `summary` rolled up through that same `master_detail` declares its currency here as `currencyMode: 'record'` naming the parent's own code field. The row's verdict stays LIVE, since this container is one blanket row (`field/currencyConfig` in undrilled-containers.baseline.json) and the keys it reads are unchanged; the two new SHAPES are PLANNED, with no reader yet: the objectql projection, code guard, backfill, roll-up admission and the parent's code lock are #31911's, and the Console drawing the child amount and the roll-up in the parent's currency is #31912's. Until #31911 lands, the engine still reads a path pointer as a sibling field name. NARROWED 2026-10-28 (#27157, ruling 6464202770 on #27119, Q2 = X): `defaultCurrency` lost its `'CNY'` default and is required under `fixed` (a `fixed` config without a code is refused with the prescription); a `dynamic` config parses with no `defaultCurrency`, and stored rows lose the baked code through the ADR-0087 conversion `currency-config-dynamic-default-currency-removed`. The reader is unchanged and was re-read on this date: ui/packages/i18n/src/currency.ts#resolveFieldCurrency still takes the code only under `fixed`, so a `dynamic` config that no longer carries `CNY` displays exactly as before. Verdict unchanged: LIVE. RE-CITED 2026-09-27 (#20126): since objectui#10461 the reader takes defaultCurrency only under currencyMode 'fixed', and the chain no longer cites the date/datetime-semantics ADR, which never names currency; line pointers moved with it (currency.ts :32 → :60, CurrencyField.tsx :45/:51 → :55/:91). Verdict unchanged: LIVE. RE-CITED 2026-08-10 (#7133/#7142): the old pointer 'packages/fields/src/index.tsx:469' now lands in formatRelativeDays, a date-phrase helper with no currency involvement — the resolver moved to @object-ui/i18n and packages/fields/src/currency.ts:14 only re-exports it, which is why the old line drifted onto unrelated code rather than disappearing. Verdict unchanged: LIVE, and now cited at both the reader that consumes the key and the widget that applies the resolved currency. The removed `currencyConfig.precision` (#19992; packages/spec/src/data/field.zod.ts; moved out of spec source, #23434): the widget's one width is the currency's CLDR fraction digits, objectui @b9814b334 packages/fields/src/widgets/CurrencyField.tsx#CurrencyField through objectui @b9814b334 packages/fields/src/widgets/number-format.ts#currencyDisplayWidth over objectui @b9814b334 packages/fields/src/currency.ts#currencyFractionDigits, and no objectui code reads `currencyConfig.precision`; re-read 2026-10-15, first cited sha-less (the source then named `currencyFractionDigits(currency)` as the widget's own line)." + "note": "WIDENED 2026-11-19 (#35045, seat ruling record 7000258793): a `summary` with `function` `sum` / `min` / `max` / `avg` declaring `currencyMode: 'dynamic'` is now admitted over any child `currency` field in `dynamic` mode, not only a stored home amount: a `dynamic` amount displays in the tenant default `localization.currency`, the one setting ADR-0144 D4 names the home currency, so its total is in that currency too. Both doors read one predicate (packages/spec/src/data/record-currency-path.ts#isTenantCurrencyAmount), in defineStack case (d) and in the engine registry (packages/objectql/src/record-currency-aggregate-door.ts#recordCurrencyFollowRefusal); a `record` or `fixed` child, a number, a formula and another summary stay refused. The reader is unchanged (ui/packages/fields/src/currency.ts#summaryDeclaresCurrency already answers true for any `dynamic` summary); a summary declaring no `currencyConfig` still has no currency. Verdict unchanged: LIVE. NARROWED 2026-11-15 (#33713, spec seat 4 claim 6893268160): the engine registry now judges a `dynamic` summary roll-up as `defineStack` does, at a single-object save or publish on a running server and at the end of an install or upgrade run (packages/objectql/src/record-currency-aggregate-door.ts#recordCurrencyFollowRefusal, case (d), against the objects as served, extensions included), in the same words (packages/spec/src/data/record-currency-path.ts#recordCurrencyDynamicRollupNotHomeError). A stored home amount now counts only where its `homeAmount` is valid as declared (packages/spec/src/data/record-currency-path.ts#storedHomeAmountSourceOf), at both doors. The reader is unchanged; verdict unchanged: LIVE. WIDENED 2026-11-15 (#33659, spec seat 4 claim 6890000941): a `summary` with `function` `sum` / `min` / `max` / `avg` that rolls up a stored home amount (a child field some `homeAmount.field` on the child object names) is admitted with `currencyMode: 'dynamic'` and no `defaultCurrency`, the roll-up of ADR-0144 D6's consolidation path in the home currency without metadata naming it (D8 rule 5). The reader that now consumes `dynamic` on a summary is ui/packages/fields/src/currency.ts#summaryDeclaresCurrency, read by both roll-up faces (ui/packages/fields/src/widgets/SummaryField.tsx#SummaryField and ui/packages/fields/src/index.tsx#FormulaCellRenderer), which draw the total through resolveFieldCurrency in the tenant default `localization.currency`, the code ObjectMetricWidget resolves for a tile over the same home field. Judged at the object door (`refuseUnadmittedSummaryCurrency`: a `dynamic` summary naming no child field, or carrying a `defaultCurrency`, stays refused, and a `count` refuses every mode as before) and in `defineStack` (case (d) of `collectRecordCurrencyPathErrors`: any other `dynamic` roll-up is refused). service-analytics is unchanged: `sourceFieldMeta` relays no code for `dynamic`, as for the home field itself. Verdict unchanged: LIVE. NARROWED 2026-11-09 (#31958, claim amend 1, record 6746006322): on a `summary` field the config is refused outside the ADR-0144 D6 admitted roll-up. A `count` roll-up refuses every mode, `fixed` included (a count is never an amount); `dynamic` is refused on every summary, since no reader consumes it there (the Console's roll-up faces read no `currencyConfig`; service-analytics relays only `fixed` and `record`); `record` is refused unless the roll-up runs through the `master_detail` its child amount follows (object door `refuseUnadmittedSummaryCurrency` in data/object.zod.ts, stack door case (c) of `collectRecordCurrencyPathErrors` in stack.zod.ts). `fixed` stays accepted on sum / min / max / avg because a reader consumes it: packages/services/service-analytics/src/plugin.ts sourceFieldMeta relays its `defaultCurrency` for any field type and packages/services/service-analytics/src/measure-currency-coherence.ts#assertMeasureCurrenciesCoherent refuses a measure labelling it another code. The container stays one blanket row and its keys are unchanged, so the verdict stays LIVE. WIDENED 2026-11-09 (#31910, ADR-0144 D2 as amended by #31743, ruling A recorded in 6739066323): a `record`-mode `currencyField` may be the two-segment path `PARENT_FIELD.CODE_FIELD` through a `master_detail` field of the same object, and a `summary` rolled up through that same `master_detail` declares its currency here as `currencyMode: 'record'` naming the parent's own code field. The row's verdict stays LIVE, since this container is one blanket row (`field/currencyConfig` in undrilled-containers.baseline.json) and the keys it reads are unchanged; the two new SHAPES are PLANNED, with no reader yet: the objectql projection, code guard, backfill, roll-up admission and the parent's code lock are #31911's, and the Console drawing the child amount and the roll-up in the parent's currency is #31912's. Until #31911 lands, the engine still reads a path pointer as a sibling field name. NARROWED 2026-10-28 (#27157, ruling 6464202770 on #27119, Q2 = X): `defaultCurrency` lost its `'CNY'` default and is required under `fixed` (a `fixed` config without a code is refused with the prescription); a `dynamic` config parses with no `defaultCurrency`, and stored rows lose the baked code through the ADR-0087 conversion `currency-config-dynamic-default-currency-removed`. The reader is unchanged and was re-read on this date: ui/packages/i18n/src/currency.ts#resolveFieldCurrency still takes the code only under `fixed`, so a `dynamic` config that no longer carries `CNY` displays exactly as before. Verdict unchanged: LIVE. RE-CITED 2026-09-27 (#20126): since objectui#10461 the reader takes defaultCurrency only under currencyMode 'fixed', and the chain no longer cites the date/datetime-semantics ADR, which never names currency; line pointers moved with it (currency.ts :32 → :60, CurrencyField.tsx :45/:51 → :55/:91). Verdict unchanged: LIVE. RE-CITED 2026-08-10 (#7133/#7142): the old pointer 'packages/fields/src/index.tsx:469' now lands in formatRelativeDays, a date-phrase helper with no currency involvement — the resolver moved to @object-ui/i18n and packages/fields/src/currency.ts:14 only re-exports it, which is why the old line drifted onto unrelated code rather than disappearing. Verdict unchanged: LIVE, and now cited at both the reader that consumes the key and the widget that applies the resolved currency. The removed `currencyConfig.precision` (#19992; packages/spec/src/data/field.zod.ts; moved out of spec source, #23434): the widget's one width is the currency's CLDR fraction digits, objectui @b9814b334 packages/fields/src/widgets/CurrencyField.tsx#CurrencyField through objectui @b9814b334 packages/fields/src/widgets/number-format.ts#currencyDisplayWidth over objectui @b9814b334 packages/fields/src/currency.ts#currencyFractionDigits, and no objectui code reads `currencyConfig.precision`; re-read 2026-10-15, first cited sha-less (the source then named `currencyFractionDigits(currency)` as the widget's own line)." }, "dimensions": { "status": "live", diff --git a/packages/spec/src/data/currency-config-record-mode.test.ts b/packages/spec/src/data/currency-config-record-mode.test.ts index bf24641793b..f5539b404c0 100644 --- a/packages/spec/src/data/currency-config-record-mode.test.ts +++ b/packages/spec/src/data/currency-config-record-mode.test.ts @@ -457,18 +457,19 @@ describe('defineStack: a roll-up through that master_detail declares the parent\ expect(finding).toContain("It names 'billing_currency' instead"); }); - it('names the mode a roll-up declared instead; `dynamic` is refused as no home amount, prescribing `record`', () => { + it('names the mode a roll-up declared instead; `dynamic` over a following amount is refused, prescribing `record`', () => { const fixed = stackRefusal([ salesOrder({ currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'USD' } }), region, orderLine(), ]); expect(fixed).toContain("It declares `currencyMode: 'fixed'`, and would show in that one currency"); expect(fixed).not.toContain('bare number'); // Since #33659 the object lets a `dynamic` roll-up naming a child field - // through, and the stack admits it only over a stored home amount: a - // following amount is not one, and the finding prescribes `record`. + // through, and the stack admits it only over an amount in the home + // currency (a `dynamic` `currency` field): a following amount is not one, + // and the finding prescribes `record`. expect(objectIssues(salesOrder({ currencyConfig: { currencyMode: 'dynamic' } }))).toEqual([]); const dynamic = stackRefusal([salesOrder({ currencyConfig: { currencyMode: 'dynamic' } }), region, orderLine()]); - expect(dynamic).toContain("`currencyMode: 'dynamic'` on a summary is admitted only for a roll-up of a stored home amount"); + expect(dynamic).toContain("`currencyMode: 'dynamic'` on a summary is admitted only for a roll-up of an amount in the organization's home currency"); expect(dynamic).toContain("is an amount in its parent's currency"); expect(dynamic).toContain("declare `currencyMode: 'record'` naming this object's own code field"); }); @@ -553,7 +554,7 @@ describe('the object refuses a summary currency it can see is not admitted', () /^`rollup` is a `summary` field of object `sales_order` declaring `currencyMode: 'dynamic'` \(an absent `currencyMode` is `dynamic`\) with no `summaryOperations` naming a child field/, ); // Naming a child field, it is the stack's to judge (#33659): only a - // roll-up of a stored home amount is admitted there. + // roll-up of an amount in the home currency is admitted there. expect(objectIssues(orderWith({ summaryOperations: SUM_LINES, currencyConfig }))).toEqual([]); } }); diff --git a/packages/spec/src/data/currency-summary-home-rollup.test.ts b/packages/spec/src/data/currency-summary-home-rollup.test.ts index 17c432d02a6..e1edd7b03ce 100644 --- a/packages/spec/src/data/currency-summary-home-rollup.test.ts +++ b/packages/spec/src/data/currency-summary-home-rollup.test.ts @@ -11,7 +11,9 @@ * code ("Metadata never names the home currency"). The object door lets a * `dynamic` roll-up through only when it names a child field and no * `defaultCurrency`; `defineStack`'s cross-reference pass admits it only when - * that child field is one some `homeAmount.field` on the child object names. + * that child field is an amount in the home currency: a `currency` field in + * `dynamic` mode, of which a stored home amount is one (widened from the home + * amount alone by seat ruling record 7000258793). * * The probe shape is HotCRM's PSA phase-0 probe (hotcrm#2316): expenses in * their own currencies, each converted at write into `amount_home`, rolled up @@ -106,7 +108,10 @@ function objectRefusal(input: unknown): string { } const DYNAMIC_PREFIX = "Object 'crm_probe_project' field 'home_expense_total' currencyConfig: `currencyMode: 'dynamic'` on a " - + 'summary is admitted only for a roll-up of a stored home amount'; + + "summary is admitted only for a roll-up of an amount in the organization's home currency"; + +/** `summaryOperations` rolling `sum(crm_probe_expense.FIELD)` up through `project`. */ +const sumOf = (field: string) => ({ summaryOperations: { object: 'crm_probe_expense', field, function: 'sum', relationshipField: 'project' } }); describe('a roll-up of a stored home amount declares `dynamic`', () => { it('admits the probe shape: sum over the home field, `currencyMode: \'dynamic\'`', () => { @@ -126,13 +131,76 @@ describe('a roll-up of a stored home amount declares `dynamic`', () => { }); }); +/** + * [Seat ruling record 7000258793, ADR-0144 D8 rule 5 read as written] A plain + * `dynamic` amount is in the tenant (home) currency by definition: `dynamic` + * "amounts display in the tenant default currency (the `localization.currency` + * setting)". So a total of such amounts is too, and the roll-up declares it + * the way a roll-up of a stored home amount does. The probe shape is HotCRM's + * (hotcrm#2569): a timesheet total over the time entries' plain cost amount. + */ +describe('a roll-up of a plain `dynamic` amount declares `dynamic` too', () => { + it('admits sum / min / max / avg over a child `currency` field with no `currencyConfig`, which no `homeAmount` names', () => { + for (const fn of ['sum', 'min', 'max', 'avg']) { + const summaryOperations = { object: 'crm_probe_expense', field: 'note_amount', function: fn, relationshipField: 'project' }; + expect(() => buildStack([project({ summaryOperations }), expense()]), fn).not.toThrow(); + } + expect(() => buildStack([project({ ...sumOf('note_amount'), currencyConfig: {} }), expense()])).not.toThrow(); + }); + + it('admits one over a child amount declaring `currencyMode: \'dynamic\'`, writable, readonly or computed by an `expression`', () => { + for (const def of [ + { type: 'currency', label: 'Cost', currencyConfig: DYNAMIC }, + { type: 'currency', label: 'Cost', readonly: true }, + { type: 'currency', label: 'Cost', expression: 'record.amount_home * 2' }, + ]) { + expect(() => buildStack([project(sumOf('cost_amount')), expense({ cost_amount: def })]), JSON.stringify(def)).not.toThrow(); + } + }); + + it('admits one over the readonly plain amount of a child whose record-mode amount declares no `homeAmount`', () => { + const noHome = expense({ + amount: { type: 'currency', label: 'Amount', currencyConfig: { currencyMode: 'record', currencyField: 'currency_code' } }, + }); + expect(() => buildStack([project(), noHome])).not.toThrow(); + }); + + it('CONTROL: a summary that declares nothing still has no currency (no published default moves)', () => { + const bare = ObjectSchema.parse(project({ ...sumOf('note_amount'), currencyConfig: undefined })) as { fields: Record }; + expect(bare.fields.home_expense_total!.currencyConfig).toBeUndefined(); + expect(() => buildStack([project({ ...sumOf('note_amount'), currencyConfig: undefined }), expense()])).not.toThrow(); + }); +}); + describe('every other `dynamic` summary stays refused', () => { - it('refuses a `dynamic` roll-up over a plain currency field that no `homeAmount` names, naming the home amounts', () => { - const summaryOperations = { object: 'crm_probe_expense', field: 'note_amount', function: 'sum', relationshipField: 'project' }; - const finding = stackRefusal([project({ summaryOperations }), expense()]); + it('refuses a `dynamic` roll-up over a `number` field, naming the child\'s amounts in the home currency', () => { + const finding = stackRefusal([project(sumOf('rate_used')), expense()]); expect(finding.startsWith(DYNAMIC_PREFIX)).toBe(true); - expect(finding).toContain("This summary rolls up sum(crm_probe_expense.note_amount), and 'crm_probe_expense.note_amount' is not a stored home amount"); - expect(finding).toContain("The home amounts of 'crm_probe_expense' are 'amount_home'"); + expect(finding).toContain( + "This summary rolls up sum(crm_probe_expense.rate_used), and 'crm_probe_expense.rate_used' is a 'number' field, " + + 'not a `currency` field in `dynamic` mode', + ); + expect(finding).toContain("The amounts of 'crm_probe_expense' in the home currency are 'amount_home', 'note_amount'; roll up one of them"); + }); + + it('refuses one over a `summary` of the child, even one declaring `dynamic` itself: a roll-up of a roll-up is not admitted', () => { + const line = { + name: 'crm_probe_line', label: 'Line', + fields: { + expense: { type: 'master_detail', label: 'Expense', reference: 'crm_probe_expense' }, + cost: { type: 'currency', label: 'Cost' }, + }, + }; + const nested = expense({ + lines_total: { + type: 'summary', label: 'Lines', + summaryOperations: { object: 'crm_probe_line', field: 'cost', function: 'sum', relationshipField: 'expense' }, + currencyConfig: DYNAMIC, + }, + }); + const finding = stackRefusal([project(sumOf('lines_total')), nested, line]); + expect(finding.startsWith(DYNAMIC_PREFIX)).toBe(true); + expect(finding).toContain("'crm_probe_expense.lines_total' is a 'summary' field, not a `currency` field in `dynamic` mode"); }); it('refuses a `dynamic` roll-up over the record-mode amount itself, prescribing its home field', () => { @@ -143,13 +211,13 @@ describe('every other `dynamic` summary stays refused', () => { expect(finding).toContain("Roll up its stored home amount 'crm_probe_expense.amount_home' instead"); }); - it('refuses a `dynamic` roll-up over a child that stores no home amount', () => { + it('refuses a `dynamic` roll-up over a record-mode amount that stores no home amount, prescribing `homeAmount`', () => { const plain = expense({ amount: { type: 'currency', label: 'Amount', currencyConfig: { currencyMode: 'record', currencyField: 'currency_code' } }, }); - const finding = stackRefusal([project(), plain]); + const finding = stackRefusal([project(sumOf('amount')), plain]); expect(finding.startsWith(DYNAMIC_PREFIX)).toBe(true); - expect(finding).toContain("'crm_probe_expense' stores no home amount"); + expect(finding).toContain('Roll up a stored home amount of the child instead (declare `homeAmount` on the amount)'); }); it('refuses a `dynamic` roll-up over a fixed child amount, prescribing that code', () => { @@ -166,7 +234,10 @@ describe('every other `dynamic` summary stays refused', () => { /^`home_expense_total` is a `summary` field of object `crm_probe_project` declaring `currencyMode: 'dynamic'` \(an absent `currencyMode` is `dynamic`\) with no `summaryOperations` naming a child field/, ); expect(message).toContain('A roll-up carries a currency in three cases only'); - expect(message).toContain("`currencyMode: 'dynamic'` (no `defaultCurrency`) when it rolls up a stored home amount"); + expect(message).toContain( + "`currencyMode: 'dynamic'` (no `defaultCurrency`) when it rolls up an amount in the organization's home currency, " + + 'a child `currency` field in `dynamic` mode (a stored home amount included)', + ); }); it('the object refuses a `dynamic` summary that names a `defaultCurrency`: metadata never names the home currency', () => { @@ -225,35 +296,30 @@ describe('a `homeAmount` makes a home amount only where it is valid as declared' return String(refusal!.issues![0]); }; - it('refuses a `dynamic` roll-up over a writable plain amount an extension names as a home field', () => { - const finding = refusalOf(stackWith(forging('note_amount'))); - expect(finding.startsWith(DYNAMIC_PREFIX)).toBe(true); - expect(finding).toContain("'crm_probe_expense.note_amount' is not a stored home amount"); - // The forged pointer is not offered as a home amount either. - expect(finding).toContain("The home amounts of 'crm_probe_expense' are 'amount_home';"); + it('a forged `homeAmount` makes no `number` field or `fixed` amount admissible: both stay refused', () => { + const readonlyFixed = { type: 'currency', label: 'Fixed', readonly: true, currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' } }; + for (const [target, extra, says] of [ + ['rate_used', {}, "is a 'number' field"], + ['fixed_amount', { fixed_amount: readonlyFixed }, 'is fixed to EUR'], + ] as const) { + const finding = refusalOf(stackWith({ ...extra, ...forging(target) }, sumOf(target))); + expect(finding.startsWith(DYNAMIC_PREFIX), target).toBe(true); + expect(finding, target).toContain(says); + } }); - it('refuses one over a `number` field, a `fixed` amount, or a field with an `expression`, each named by an extension', () => { - const readonlyFixed = { type: 'currency', label: 'Fixed', readonly: true, currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' } }; + it('a plain `dynamic` amount is admitted whatever a `homeAmount` says of it: writable, computed, or claimed twice', () => { const computed = { type: 'currency', label: 'Computed', readonly: true, expression: 'amount * 2' }; for (const [target, extra] of [ - ['rate_used', {}], - ['fixed_amount', { fixed_amount: readonlyFixed }], + ['note_amount', {}], ['computed_amount', { computed_amount: computed }], + ['amount_home', {}], ] as const) { - const summaryOperations = { object: 'crm_probe_expense', field: target, function: 'sum', relationshipField: 'project' }; - const finding = refusalOf(stackWith({ ...extra, ...forging(target) }, { summaryOperations })); - expect(finding.startsWith(DYNAMIC_PREFIX), target).toBe(true); + expect(() => defineStack(stackWith({ ...extra, ...forging(target) }, sumOf(target)) as Parameters[0]), target) + .not.toThrow(); } }); - it('refuses one over a home field two amounts claim: one column, two writers', () => { - const summaryOperations = { object: 'crm_probe_expense', field: 'amount_home', function: 'sum', relationshipField: 'project' }; - const finding = refusalOf(stackWith(forging('amount_home'), { summaryOperations })); - expect(finding.startsWith(DYNAMIC_PREFIX)).toBe(true); - expect(finding).toContain("'crm_probe_expense' stores no home amount"); - }); - it('CONTROL: an extension declaring a valid home amount on the child is admitted, as an authored one is', () => { const home = { ext_home: { type: 'currency', label: 'Home', readonly: true }, ...forging('ext_home') }; const summaryOperations = { object: 'crm_probe_expense', field: 'ext_home', function: 'sum', relationshipField: 'project' }; @@ -278,7 +344,7 @@ describe('a `homeAmount` makes a home amount only where it is valid as declared' describe('case (d) is worded once', () => { it('defineStack prints `recordCurrencyDynamicRollupNotHomeError` for each refused child field', () => { const fixedChild = expense({ note_amount: { type: 'currency', label: 'Plain', currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' } } }); - for (const [field, child] of [['note_amount', expense()], ['note_amount', fixedChild], ['amount', expense()], ['rate_used', expense()]] as const) { + for (const [field, child] of [['note_amount', fixedChild], ['amount', expense()], ['rate_used', expense()]] as const) { const summaryOperations = { object: 'crm_probe_expense', field, function: 'sum', relationshipField: 'project' }; const childFields = (child as { fields: Record }).fields; expect(stackRefusal([project({ summaryOperations }), child]), field).toBe(recordCurrencyDynamicRollupNotHomeError( diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index 16dcd985356..237f7da7d42 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -716,11 +716,13 @@ function refuseSummaryWithoutField( * amount resolves the roll-up the same way and no key is added. Whether the * child amount it rolls up follows that very code through that very * `master_detail` is a question about two objects, answered where both are - * held, never by this one-config shape. A roll-up of a stored home amount (a - * child field some `homeAmount.field` names) declares `currencyMode: 'dynamic'` - * with no `defaultCurrency`: the home field is a `dynamic` field in the - * organization's home currency (ADR-0144 D8 rule 5), so its total is too, and - * the Console draws it in that currency without metadata naming it (#33659). + * held, never by this one-config shape. A roll-up of an amount in the home + * currency (a child `currency` field in `dynamic` mode, a stored home amount + * included) declares `currencyMode: 'dynamic'` with no `defaultCurrency`: a + * `dynamic` amount is in the organization's home currency (ADR-0144 D8 rule 5, + * `localization.currency`), so its total is too, and the Console draws it in + * that currency without metadata naming it (#33659; widened to every `dynamic` + * child amount by seat ruling record 7000258793). * Outside those two roll-ups a `summary` may declare only `fixed` (read by the * analytics layer); a `count` roll-up, every other `dynamic` config and every * other `record` roll-up are refused at the object door @@ -2444,7 +2446,7 @@ export const FieldSchema = lazySchema(() => { // Currency config — read for a `currency` field and for a `formula` whose // `returnType` is `currency` (#22727): one shape for both, never a second one. - currencyConfig: CurrencyConfigSchema.optional().describe('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: CurrencyConfigSchema.optional().describe('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.'), // Vector field — flat dimensionality (the live authoring path). // The renderer reads this flat sibling (read point recorded in diff --git a/packages/spec/src/data/object.zod.ts b/packages/spec/src/data/object.zod.ts index 110122cbe81..aa4d6db8f86 100644 --- a/packages/spec/src/data/object.zod.ts +++ b/packages/spec/src/data/object.zod.ts @@ -2251,14 +2251,15 @@ function summaryRollupOf(field: unknown): { function?: unknown; object?: unknown * number of rows, never an amount, so a currency on it is wrong whichever * reader sees it (the analytics layer relays both a `fixed` code and a * `record` pointer for any field type); - * - `dynamic` is admitted on a `sum` / `min` / `max` / `avg` roll-up of a - * stored home amount only (#33659): a child field some - * `homeAmount.field` on the child object names. Such a field is "a - * `dynamic`-mode currency field" (ADR-0144 D8 rule 5), every row of it is - * in the organization's home currency (`localization.currency`), so its - * total is too, and the Console's roll-up faces draw a `dynamic` summary in - * that currency, as a metric tile over the same home field does. Whether the - * child field is a home field needs the child object, so this door lets a + * - `dynamic` is admitted on a `sum` / `min` / `max` / `avg` roll-up of an + * amount in the home currency only: a child `currency` field in `dynamic` + * mode (#33659 admitted a stored home amount, "a `dynamic`-mode currency + * field" by ADR-0144 D8 rule 5; seat ruling record 7000258793 admits every + * such field). Every row of it is in the organization's home currency + * (`localization.currency`), so its total is too, and the Console's roll-up + * faces draw a `dynamic` summary in that currency, as a metric tile over the + * same field does. Whether the child field is such an amount needs the + * child object, so this door lets a * `dynamic` roll-up through only when its `summaryOperations` names a child * object and field, and `defineStack`'s cross-reference pass judges the * rest (`collectRecordCurrencyPathErrors`, stack.zod.ts). A `dynamic` @@ -2300,9 +2301,9 @@ function refuseUnadmittedSummaryCurrency( 'A roll-up carries a currency in three cases only: `currencyMode: \'fixed\'` when every amount it reads is in that ' + 'one currency; `currencyMode: \'record\'` naming this object\'s own code field when it rolls up, through a ' + '`master_detail`, child amounts whose `currencyField` follows this record through that very field ' - + '(`MASTER_DETAIL_FIELD.CODE_FIELD`); and `currencyMode: \'dynamic\'` (no `defaultCurrency`) when it rolls up a ' - + 'stored home amount, a child field that a `homeAmount.field` on the child object names, which is in the ' - + 'organization\'s home currency.'; + + '(`MASTER_DETAIL_FIELD.CODE_FIELD`); and `currencyMode: \'dynamic\'` (no `defaultCurrency`) when it rolls up an ' + + 'amount in the organization\'s home currency, a child `currency` field in `dynamic` mode (a stored home amount ' + + 'included).'; if (ops?.function === 'count') { ctx.addIssue({ code: 'custom', @@ -2316,8 +2317,9 @@ function refuseUnadmittedSummaryCurrency( if (mode === 'dynamic') { const namesChild = ops !== undefined && typeof ops.object === 'string' && typeof ops.field === 'string'; const named = (config as { defaultCurrency?: unknown }).defaultCurrency; - // [#33659] The admitted `dynamic` roll-up reads a stored home amount; the - // child object says whether it does, so the stack pass judges that half. + // [#33659] The admitted `dynamic` roll-up reads an amount in the home + // currency; the child object says whether it does, so the stack pass + // judges that half. if (namesChild && named === undefined) continue; ctx.addIssue({ code: 'custom', @@ -2327,8 +2329,8 @@ function refuseUnadmittedSummaryCurrency( ? ` with \`defaultCurrency: '${String(named)}'\`. \`dynamic\` reads no \`defaultCurrency\`, and metadata never ` + 'names the home currency: delete `defaultCurrency`, or declare `currencyMode: \'fixed\'` if every amount ' + 'it reads is in that one currency. ' - : ' with no `summaryOperations` naming a child field, so it rolls up no stored home amount that would put it ' - + 'in the organization\'s home currency: delete `currencyConfig`, or declare the roll-up. ') + : ' with no `summaryOperations` naming a child field, so it rolls up no amount in the organization\'s home ' + + 'currency that would put it there: delete `currencyConfig`, or declare the roll-up. ') + admitted, }); continue; diff --git a/packages/spec/src/data/record-currency-path.ts b/packages/spec/src/data/record-currency-path.ts index 45ae471e08d..557f1887812 100644 --- a/packages/spec/src/data/record-currency-path.ts +++ b/packages/spec/src/data/record-currency-path.ts @@ -23,11 +23,14 @@ * - {@link recordCurrencyUnfollowedRollupError}: (c), the arm of a * `currencyMode: 'record'` roll-up whose child amount follows no parent. * - {@link storedHomeAmountSourceOf}: is a child field a stored home amount, - * named by a `homeAmount` that is valid where it is declared? The test (d) - * reads. + * named by a `homeAmount` that is valid where it is declared? The (d) + * refusal of a record-mode child reads it to name the home amount to roll up. + * - {@link isTenantCurrencyAmount}: is a child field an amount in the + * organization's home (tenant) currency by declaration, a stored `currency` + * field in `dynamic` mode? The test (d) reads. * - {@link recordCurrencyDynamicRollupNotHomeError}: (d), a - * `currencyMode: 'dynamic'` roll-up over a child field that is not a stored - * home amount. + * `currencyMode: 'dynamic'` roll-up over a child field that is not such an + * amount. * * Messages only and two predicates: each door decides when a pair is judged. */ @@ -187,7 +190,8 @@ function claimsHomeField(def: unknown, target: string): boolean { /** * [ADR-0144 D5] The amount field of `fields` whose `currencyConfig.homeAmount` * stores its home-currency value in `field`, or `undefined` when `field` is - * not a stored home amount: the test (d) reads for "a stored home amount". + * not a stored home amount: the reading the (d) refusal of a record-mode child + * amount uses to name the home amount to roll up instead. * * A `homeAmount` counts only where it is valid as declared, the reading the * object door (`refuseDishonestHomeAmount`, `data/object.zod.ts`) guarantees @@ -206,14 +210,40 @@ export function storedHomeAmountSourceOf(fields: Record, field: return claimants.length === 1 ? claimants[0] : undefined; } +/** + * [ADR-0144 D8 rule 5, seat ruling record 7000258793] Is `def` an amount in the + * organization's home currency by declaration: a stored `currency` field in + * `dynamic` mode (an absent `currencyConfig` or `currencyMode` is `dynamic`)? + * The test (d) reads for the child field a `dynamic` summary may roll up. + * + * `dynamic` means "the field has no currency of its own — amounts display in + * the tenant default currency (the `localization.currency` setting)" + * (`CurrencyConfigSchema.currencyMode`), the one setting ADR-0144 D4 names the + * home currency, so every row of such a field is in that currency and a total + * of them is too. A stored home amount ({@link storedHomeAmountSourceOf}) is + * one such field (D8 rule 5: "the home field is a `dynamic`-mode currency + * field"). A `record` or `fixed` amount, a plain `number`, a `formula` and a + * `summary` are not: the first two name another currency, and the others + * declare no `currency` amount the roll-up reads. + */ +export function isTenantCurrencyAmount(def: unknown): boolean { + if (!isRecord(def) || def.type !== 'currency') return false; + return (currencyConfigOf(def)?.currencyMode ?? 'dynamic') === 'dynamic'; +} + +/** The fields of `fields` that {@link isTenantCurrencyAmount} admits, as the (d) prescription names them. */ +function tenantCurrencyAmountsOf(fields: Record): string[] { + return Object.keys(fields).filter((name) => isTenantCurrencyAmount(fields[name])); +} + /** * [ADR-0144 D6, D8 rule 5] (d): a `summary` (`sum`, `min`, `max`, `avg`) * declaring `currencyMode: 'dynamic'` (or a `currencyConfig` with no - * `currencyMode`) rolls up `childDef`, a field of `childFields` that is not a - * stored home amount ({@link storedHomeAmountSourceOf}), with the declaration - * the child field does support. The faces draw a `dynamic` summary in the - * organization's home currency, which the amounts it reads are not known to - * be in. + * `currencyMode`) rolls up `childDef`, a field of `childFields` that is not an + * amount in the home currency ({@link isTenantCurrencyAmount}), with the + * declaration the child field does support. The faces draw a `dynamic` summary + * in the organization's home currency, which the amounts it reads are not + * known to be in. */ export function recordCurrencyDynamicRollupNotHomeError( rollup: RecordCurrencyRecordRollup, @@ -226,7 +256,8 @@ export function recordCurrencyDynamicRollupNotHomeError( const home = declaredHome !== undefined && storedHomeAmountSourceOf(childFields, declaredHome) === rollup.childField ? declaredHome : undefined; - const homes = Object.keys(childFields).filter((name) => storedHomeAmountSourceOf(childFields, name) !== undefined); + const amounts = tenantCurrencyAmountsOf(childFields); + const kind = isRecord(childDef) && typeof childDef.type === 'string' ? `a '${childDef.type}' field` : 'not a field'; const why = config?.currencyMode === 'record' ? `${named} is an amount in ${typeof config.currencyField === 'string' && config.currencyField.includes('.') ? 'its parent\'s' : 'each record\'s own'} ` + `currency (\`currencyMode: 'record'\`), not the home currency. ` @@ -238,14 +269,15 @@ export function recordCurrencyDynamicRollupNotHomeError( : config?.currencyMode === 'fixed' && typeof config.defaultCurrency === 'string' ? `${named} is fixed to ${config.defaultCurrency}. Declare \`currencyConfig: { currencyMode: 'fixed', defaultCurrency: ` + `'${config.defaultCurrency}' }\` on the summary instead.` - : `${named} is not a stored home amount, so its rows are not known to be in the home currency. ` - + (homes.length > 0 - ? `The home amounts of '${rollup.childObject}' are ${homes.map((h) => `'${h}'`).join(', ')}; roll up one of them, ` - : `'${rollup.childObject}' stores no home amount; `) + : `${named} is ${kind}, not a \`currency\` field in \`dynamic\` mode, so its rows are not known to be in the home currency. ` + + (amounts.length > 0 + ? `The amounts of '${rollup.childObject}' in the home currency are ${amounts.map((h) => `'${h}'`).join(', ')}; ` + + 'roll up one of them, ' + : `'${rollup.childObject}' has no amount in the home currency; `) + 'or delete `currencyConfig` on the summary, or declare `currencyMode: \'fixed\'` if every amount it reads is in ' + 'one currency.'; return `Object '${rollup.object}' field '${rollup.field}' currencyConfig: \`currencyMode: 'dynamic'\` on a summary is ` - + 'admitted only for a roll-up of a stored home amount (a child field that a `homeAmount.field` on the child object ' - + 'names), whose every row is in the organization\'s home currency. This summary rolls up ' - + `${rollup.fn}(${rollup.childObject}.${rollup.childField}), and ${why}`; + + '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, whose every row is in that ' + + `currency. This summary rolls up ${rollup.fn}(${rollup.childObject}.${rollup.childField}), and ${why}`; } diff --git a/packages/spec/src/stack.zod.ts b/packages/spec/src/stack.zod.ts index 222a98e9c4f..eb0cbc7ac11 100644 --- a/packages/spec/src/stack.zod.ts +++ b/packages/spec/src/stack.zod.ts @@ -46,11 +46,11 @@ import { externalBindingDatasourceRefusal } from './data/external-binding-dataso import { InlineGridColumnSchema, summaryFunctionReadsField } from './data/field.zod'; import { isRecordCurrencyCodeField, + isTenantCurrencyAmount, recordCurrencyDynamicRollupNotHomeError, recordCurrencyFollowedCodeError, recordCurrencyRecordRollupError, recordCurrencyUnfollowedRollupError, - storedHomeAmountSourceOf, } from './data/record-currency-path'; import { AUDIT_FIELD_DEFS } from './data/injected-system-column-provenance'; import { pageComponentSlotPositions } from './ui/component.zod'; @@ -4743,19 +4743,19 @@ function recordCurrencyPathOf(field: unknown): { via: string; code: string } | u * * (d) A `summary` (`sum`, `min`, `max`, `avg`) declaring * `currencyMode: 'dynamic'` (or a `currencyConfig` with no `currencyMode`, - * which is `dynamic`) is admitted only when the child field it rolls up is a - * stored home amount: a field that some `currencyConfig.homeAmount.field` on - * the child object names (#33659), where that `homeAmount` is valid as declared - * (`storedHomeAmountSourceOf`: a field merged in from an extension never had - * the object door's reading, so a `homeAmount` naming a plain number, a `fixed` - * amount or a writable field does not make it a home amount). ADR-0144 D6 has consolidated totals read - * that home field, and D8 rule 5 makes it "a `dynamic`-mode currency field", - * displayed in the organization's home currency (`localization.currency`); - * every row of it is in that one currency, so its total is too, and declaring - * `dynamic` on the roll-up says so without naming the code (D8 rule 5: - * "Metadata never names the home currency"). Any other `dynamic` roll-up is - * refused: the faces would draw it in the home currency, which the amounts it - * reads are not known to be in. The object door has already refused a + * which is `dynamic`) is admitted only when the child field it rolls up is an + * amount in the organization's home currency by declaration: a stored + * `currency` field in `dynamic` mode (`isTenantCurrencyAmount`). A `dynamic` + * amount displays in the tenant default currency, `localization.currency`, + * the one setting ADR-0144 D4 names the home currency, so every row of it is + * in that currency and its total is too (seat ruling record 7000258793, which + * widened #33659's admission of a stored home amount alone: D8 rule 5 makes + * the home field "a `dynamic`-mode currency field", one such amount). + * Declaring `dynamic` on the roll-up says so without naming the code (D8 + * rule 5: "Metadata never names the home currency"). Any other `dynamic` + * roll-up is refused: over a `record` or `fixed` amount, a plain number, a + * formula or another summary, the faces would draw it in the home currency, + * which the amounts it reads are not known to be in. The object door has already refused a * `dynamic` summary that names no child field or carries a `defaultCurrency`, * and a `count` (`refuseUnadmittedSummaryCurrency`). * @@ -4810,15 +4810,16 @@ function collectRecordCurrencyPathErrors(config: ObjectStackDefinition): string[ const childField = hasOwnKey(child, ops.field) ? child[ops.field] : undefined; const judgeRecord = summaryCurrency?.currencyMode === 'record' && declared.has(ops.object) && childField !== undefined; const rollup = { object: objectName, field: fieldName, fn: String(ops.function), childObject: ops.object, childField: ops.field }; - // (d) A `dynamic` roll-up is admitted over a stored home amount only - // (#33659), judged against a child this stack declares and a child field - // it holds, as (c) is; a home field is admitted whatever else it is, so - // nothing below judges it again. + // (d) A `dynamic` roll-up is admitted over an amount in the home + // currency only (a `dynamic` `currency` field, a stored home amount + // included), judged against a child this stack declares and a child + // field it holds, as (c) is; such an amount is admitted whatever else it + // is, so nothing below judges it again. if ( summaryCurrency !== undefined && (summaryCurrency.currencyMode ?? 'dynamic') === 'dynamic' && declared.has(ops.object) && childField !== undefined ) { - if (storedHomeAmountSourceOf(child, ops.field) === undefined) { + if (!isTenantCurrencyAmount(childField)) { errors.push(recordCurrencyDynamicRollupNotHomeError(rollup, child, childField)); } continue;