Skip to content

Commit 740720c

Browse files
fix(components): the edit form's subtotal reads the record's currency, as the record page does (#36293)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XP3RHGWUG7UH3fNa4tBa9UC)_ Part of #36249 Builds Done-when item 2 only. Item 1 (a product's price copied across currencies) stays open on the card for the maintainer's rule. Clause-②: no Metadata-protocol: none ## 维护者速读 在编辑发票表单里,欧元发票的小计原来显示成没有货币符号的「230.00」,现在显示「€230.00」,和记录页、含税合计一致。 这是多币种发票的后续问题,替在示例应用里录入外币发票的用户解决小计看不出币种的问题。 只影响编辑表单里汇总金额的显示,不改存储的数字;出问题可以直接撤回,回到原来的无符号显示。 卡片的另一半(选产品时把本币单价原样抄进欧元明细)需要你定规则,选项和建议在报告里。 ## What changes - `ui/packages/components/src/renderers/form/form.tsx`: `RECORD_CURRENCY_WIDGET_TYPES` gains `summary`. The form renderer hands the live form record (`dependentValues`) to a registered widget only when its type is in that set; `currency` and `formula` were in it, `summary` was not. `SummaryField` already formats a roll-up that declares its currency (ADR-0144 D6 as amended) with `resolveFieldCurrency(field, tenant, dependentValues)`, the same call the record page's cell (`FormulaCellRenderer` → `CurrencyCellRenderer`) makes; with no record, a `record`-mode config resolves to no code and `formatCurrency` prints a bare `230.00`. Now the edit form's subtotal is drawn by that same code path with the record it needs. The fix is in the shared host, so every `summary` field that declares a currency on any form (New / Edit, drawer, modal) gets it; the showcase fixture was already right (PR #36233 declared `currencyConfig: { currencyMode: 'record', currencyField: 'currency_code' }` on `total`). - `ui/packages/fields/src/__tests__/parentCurrency.faces-31912.test.tsx`: a new top-level `describe` in the existing D6 harness drives the real form renderer with the real `SummaryField` / `CurrencyField` / `TextField`: a EUR record's subtotal reads `€230.00` and its tax-inclusive total `€276.00`; a USD record reads `$230.00` / `$276.00`. - `.changeset/36249-form-subtotal-currency.md`: `@object-ui/components` patch. Read first, by risk: (1) the one-line set change in `form.tsx` (`SummaryField` spreads no leftover props onto the DOM, so the new prop leaks nowhere); (2) the new `describe` at the end of the faces harness. Two-minute check: `pnpm --dir ui exec vitest run packages/fields/src/__tests__/parentCurrency.faces-31912.test.tsx` passes 11/11; remove `'summary'` from the set and the two new cases fail with `expected 'Subtotal230.00' to contain '€230.00'`. ## Tests <details><summary>Pin and ablation at d5c341f</summary> - With the fix: `Test Files 1 passed (1)`, `Tests 11 passed (11)`. - Ablation (`scripts/ablation-replace.mjs`, anchor hit x1 -> x0, blob 44f1fec -> cee0c300): `Tests 2 failed | 9 passed (11)`, `AssertionError: expected 'Subtotal230.00' to contain '€230.00'` and `expected 'Subtotal230.00' to contain '$230.00'`. The tax-inclusive total cases stayed green in both legs (that face already had the record). Restored: blob == HEAD, `git diff HEAD` empty. The ui test config aliases `@object-ui/components` to `src`, so no rebuild sits between the mutation and the run. </details> ## Acceptance notes - Item 1 of the card (a picked product's home-currency `unit_price` copied into a EUR line) is not built here, as the claim says. The measurement and the options go to the seat in the report. - Before this change a home-currency (USD) invoice's subtotal was also bare on the edit form (`230.00`); it now reads `$230.00`, the record page's format. - Seen while verifying, not fixed here: the showcase `en` translation bundle labels `showcase_invoice.total` "Total" while the object metadata labels it "Subtotal", so the record page and the edit form show the pre-tax roll-up as "Total" next to "Total incl. Tax", and the line-grid stack calls the same figure "Subtotal". Listed in the report for the seat. ## Verification <details><summary>Booted showcase, INV-1010 (EUR), edit form, 1280 px</summary> Own stack: `objectstack dev --seed-admin --fresh -p 4361` in `examples/app-showcase` on this branch's build, the Console from this tree's source (`vite --port 5361`, `DEV_PROXY_TARGET` at the backend), admin, Playwright with the preinstalled Chromium. Both servers stopped after. - Before (the fix ablated in the source the Console serves): edit form `total` reads `Total 230.00`; `Total incl. Tax €276.00`; the line-grid stack `Subtotal €230.00`. - After: edit form `total` reads `Total €230.00`; the tax-inclusive total unchanged at `€276.00`. - Record page on the same boot: `Total €230.00`. - Screenshots in the project files: `build-seat4/36249/before-edit-form-1280.png`, `after-edit-form-1280.png`. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 46ad134 commit 740720c

3 files changed

Lines changed: 74 additions & 6 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
fix(components): the edit form's roll-up subtotal reads the record's currency, as the record page and the form's tax-inclusive total do
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- A `summary` field that declares its currency (`currencyConfig`, ADR-0144 D6 as amended) now receives the live form record from the form renderer, the way a `currency` field and a `formula` field already do. A `record`-mode roll-up on the New / Edit form therefore draws in the currency its record's code field holds: a EUR invoice's Subtotal reads `€230.00` instead of a bare `230.00`, and it follows the code the user picks.
11+
- Not changed: a roll-up that declares no currency still reads as a number; the record page, the list cell and the line-item grid already drew the record's currency and draw it as before; no metadata changes.

‎ui/packages/components/src/renderers/form/form.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,12 +1379,13 @@ function renderFieldDescription(
13791379

13801380
/**
13811381
* Widget keys whose DISPLAY reads a sibling field's value: a `record`-mode
1382-
* amount (ADR-0144 D2) shows the currency its record's code field holds, and a
1383-
* `formula` declaring `returnType: 'currency'` is drawn by the same widget.
1384-
* They get the live record (`dependentValues`) and nothing else from the
1385-
* data-source family — they query nothing.
1382+
* amount (ADR-0144 D2) shows the currency its record's code field holds, a
1383+
* `formula` declaring `returnType: 'currency'` is drawn by the same widget, and
1384+
* a roll-up `summary` declaring its currency (D6 as amended) reads the same code
1385+
* off the record. They get the live record (`dependentValues`) and nothing else
1386+
* from the data-source family — they query nothing.
13861387
*/
1387-
const RECORD_CURRENCY_WIDGET_TYPES = new Set(['currency', 'formula']);
1388+
const RECORD_CURRENCY_WIDGET_TYPES = new Set(['currency', 'formula', 'summary']);
13881389

13891390
function stripRegisteredFieldProps(type: string, props: RenderFieldProps): RenderFieldProps {
13901391
const {

‎ui/packages/fields/src/__tests__/parentCurrency.faces-31912.test.tsx‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
* draws a column in the currency its host names.
1616
*/
1717

18-
import { describe, it, expect, afterEach, vi } from 'vitest';
18+
import { describe, it, expect, afterEach, beforeAll, vi } from 'vitest';
1919
import React from 'react';
2020
import { render, cleanup, waitFor } from '@testing-library/react';
2121
import '@testing-library/jest-dom';
22+
import { ComponentRegistry } from '@object-ui/core';
2223
import { LocalizationProvider } from '@object-ui/i18n';
24+
// Module scope: pulls in the form renderer's registration side effect.
25+
import '@object-ui/components';
2326
import { FormulaCellRenderer, withFollowedParentObject } from '../index';
2427
import { CurrencyField } from '../widgets/CurrencyField';
2528
import { SummaryField } from '../widgets/SummaryField';
2629
import { GridField } from '../widgets/GridField';
30+
import { TextField } from '../widgets/TextField';
2731

2832
afterEach(cleanup);
2933

@@ -130,3 +134,55 @@ describe('inline grid: a column in the currency its host names (ADR-0144 D2 as a
130134
expect(text(grid().container.textContent)).toContain('$1,234.50');
131135
});
132136
});
137+
138+
describe('the edit form hands a roll-up its record, so the subtotal reads the record\'s currency (ADR-0144 D6 as amended)', () => {
139+
// The real form renderer hosting the real widgets, registered raw (not
140+
// through `registerAllFields()`, whose lazy loaders put a module load inside
141+
// a bounded `findBy` window).
142+
beforeAll(() => {
143+
for (const [type, Component] of Object.entries({ text: TextField, currency: CurrencyField, summary: SummaryField })) {
144+
ComponentRegistry.register(type, Component as any, { namespace: 'field', skipFallback: true });
145+
}
146+
}, 30000);
147+
148+
const CODE = { name: 'currency_code', label: 'Currency', type: 'text' };
149+
// The form's read-only roll-up, as the edit form generates it: disabled.
150+
const SUBTOTAL = {
151+
name: 'total',
152+
label: 'Subtotal',
153+
type: 'summary',
154+
disabled: true,
155+
summaryOperations: { object: 'inv_line', field: 'amount', function: 'sum' },
156+
currencyConfig: { currencyMode: 'record', currencyField: 'currency_code' },
157+
};
158+
// The tax-inclusive total: a computed `currency` field of the same record.
159+
const TOTAL_INCL_TAX = {
160+
name: 'amount',
161+
label: 'Total incl. Tax',
162+
type: 'currency',
163+
readonly: true,
164+
currencyConfig: { currencyMode: 'record', currencyField: 'currency_code' },
165+
};
166+
167+
function editForm(record: Record<string, unknown>) {
168+
const Form = ComponentRegistry.get('form')!;
169+
return render(
170+
<LocalizationProvider value={TENANT}>
171+
<Form schema={{ type: 'form', mode: 'edit', showSubmit: false, showCancel: false, defaultValues: record, fields: [CODE, SUBTOTAL, TOTAL_INCL_TAX] }} />
172+
</LocalizationProvider>,
173+
);
174+
}
175+
const item = (name: string) => text(document.querySelector(`[data-field="${name}"]`)?.textContent);
176+
177+
it('a EUR record: the subtotal reads EUR, as the record page and the total incl. tax do', () => {
178+
editForm({ currency_code: 'EUR', total: 230, amount: 276 });
179+
expect(item('total')).toContain('€230.00');
180+
expect(item('amount')).toContain('€276.00');
181+
});
182+
183+
it('a record in the home currency keeps its format', () => {
184+
editForm({ currency_code: 'USD', total: 230, amount: 276 });
185+
expect(item('total')).toContain('$230.00');
186+
expect(item('amount')).toContain('$276.00');
187+
});
188+
});

0 commit comments

Comments
 (0)