Repository navigation
Commit 12b69e1
feat(formula): rmbUpper(amount) writes an amount in Chinese capital numerals (人民币大写) for printed quotes and invoices (#34433)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XD1C1qPMRfafpYhtS1pHdu4)_
Fixes #34332
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: updated here — `skills/objectstack-formula/SKILL.md` lists
`rmbUpper(x)` in the stdlib Numbers table (pinned by
`skill-catalog-sync.test.ts`), and
`content/docs/data-modeling/formulas.mdx` adds the catalog row and an
"Amount in Chinese capitals" cookbook entry.
## 维护者速读
- **改了什么**:公式标准库新增 `rmbUpper(金额)`,把金额写成人民币大写,如 `245000` →
`贰拾肆万伍仟元整`、`10500.5` → `壹万零伍佰元伍角`;报价单、合同、发票的打印页用一个公式字段就能显示「大写金额」。
- **为什么改**:中文商务单据都要在数字下面再印一行大写金额,平台原来没有这个函数,应用自己用 CEL
写既长又容易在「零」、万/亿、角分规则上出错;本卡由你升为 p1(记录 6918041400)。
- **风险与回滚**:只新增一个函数,已有公式的取值都不变;回滚即撤掉本 PR。金额按精确小数四舍五入到分(`1.005` →
`壹元零壹分`),空值显示空,非数字或 10^16 元以上报运行时错误,不会印出错的金额。
- **先看**:`packages/formula/src/rmb-upper.ts`(零与万/亿规则、取整)→
`packages/formula/src/stdlib-rmb-upper.test.ts`(期望值表)→
`skills/objectstack-formula/SKILL.md`(新增一行,删掉一句面向平台开发者的旧建议来付 token 预算)。
- **两分钟验证**:`pnpm --filter @objectstack/formula exec vitest run
src/stdlib-rmb-upper.test.ts`,预期全部通过,表中可见 `245000` → `贰拾肆万伍仟元整`。
- **需要你做的**:本 PR 碰受管面 `skills/**`,契约审核(contract review owed)PASS
后由席位请你批准,在此之前无需动作。
## What changes
- **`rmbUpper(dyn): string`** (`packages/formula/src/rmb-upper.ts`,
registered in `registerBoundStdLib` beside the other number helpers). An
amount as Chinese capital numerals:
- digits 零壹贰叁肆伍陆柒捌玖, places 拾佰仟, groups 万 and 亿; a ten is `壹拾`;
- one `零` per run of zeros inside the number, none at the end of a group
or of the yuan part (`1005` → `壹仟零伍元整`, `10500` → `壹万零伍佰元整`, `100000001`
→ `壹亿零壹元整`, `1000000` → `壹佰万元整`); a full low group takes no `零`
(`107000` → `壹拾万柒仟元整`);
- above 亿 the count of 亿 is written with 万 (`10000100000000` →
`壹拾万零壹亿元整`); 10^16 yuan and above is refused rather than written as 亿亿;
- a whole amount ends in `整`; 角 with no 分 ends at the 角 (`伍角`, as on the
card); 分 with no 角 writes `零` for the 角 (`壹元零伍分`); under one yuan is 角
and 分 alone (`0.5` → `伍角`);
- `0` → `零元整`, a negative is prefixed `负` (one that rounds to zero is
`零元整`), `null` → `''`.
- **Rounding** reads the value's own spelling and rounds with the
home-amount arithmetic's `divideToPlaces` (ADR-0144 D5): the exact
decimal the value spells, rounded once to 分, half away from zero. A
number, a bigint (an int literal) and decimal text (a currency column
answered as `"245000.00"`) are read; text that spells no decimal, a
boolean, a list or a map throws, which the engine reports as a runtime
error.
- **Catalog**: `CEL_STDLIB_FUNCTIONS` advertises `rmbUpper`; its
docblock tallies move 77 to 78 registered, 42 to 43 bare-callable, 30 to
31 added by `registerStdLib`. `cel-engine.test.ts`'s
every-advertised-entry probe gains `rmbUpper(10500.5)`.
- **Docs**: the formula skill's Numbers table, `formulas.mdx`'s stdlib
table and a cookbook entry.
- **Platform checklist**: `api-backend.formula-stdlib-matrix` revision 8
counts 31 functions and adds the `rmbUpper` known answers.
## Why
Chinese quotes, contracts, order confirmations and invoices print the
total in capital numerals beside the figures, and the stdlib had no
function for it. Hand-writing the zero, 万/亿 and 角/分 rules in CEL is long
and easy to get wrong, and every app printing a Chinese document would
copy it. Grade: maintainer ruling 6918041400 (「按价值挑五张升 p1」). It pairs
with #34228 (Chinese print layout, PR #34422), which it does not touch.
## Tests
- `packages/formula/src/stdlib-rmb-upper.test.ts`, every row evaluated
through `celEngine.evaluate` the way a formula field reads it: the
card's amounts; places, groups and 零 (28 rows up to `9999999999999999`);
角/分/整 (10 rows); rounding on the exact decimal (`1.005`, `2.675`,
`9.995`, `-1.005`); negatives; int and double literals, decimal text,
record arithmetic (`3 × 0.1` rounds to `叁角`), `null`; refusals (text,
`¥100`, a boolean, a list, 10^16 with a control one 分 below); authoring
(`validateExpression('value', 'rmbUpper(record.total)')` with a currency
field has no error or warning, and `inferExpressionType` answers
`text`).
- Drift pins: `cel-stdlib-drift.test.ts` (catalog equals the
bare-callable registrations), `skill-catalog-sync.test.ts` (the skill
documents every entry), `cel-engine.test.ts` (every entry resolves).
<details><summary>Test readings at head 4fffca7</summary>
```text
pnpm --filter @objectstack/formula test && pnpm --filter @objectstack/formula typecheck (under os-verify-lock)
Test Files 68 passed (68)
Tests 1822 passed (1822)
os-verify-lock: VERDICT command-exit 0
```
Ablation (one, source-resolved: the test imports `./cel-engine`
relatively, so no dist is involved), through
`scripts/ablation-replace.mjs`: the anchor `return head + (low < 1_000n
? '零' : '') + group(Number(low));` replaced by `return head +
group(Number(low));` (anchor 1 to 0, blob `22257fca` to `93e3b5cf`).
`stdlib-rmb-upper.test.ts` went red on 10 tests, among them `10500.5 →
壹万零伍佰元伍角`, `10001 → 壹万零壹元整`, `1000100 → 壹佰万零壹佰元整` and `10000100000000 →
壹拾万零壹亿元整`. Restored: the file's blob is `22257fca`, equal to
`HEAD:packages/formula/src/rmb-upper.ts`, and `git diff HEAD` is empty.
</details>
## Acceptance notes
- **Name.** `rmbUpper` is the card's own suggestion and reads beside
`upper()`; nothing in the stdlib, spec or ui names a Chinese-numeral
function today. A reviewer who prefers another name can veto it here: it
is one registration, one catalog entry and the docs rows.
- **The optional 零.** The rules allow writing or omitting a `零` where
the 元 or 万 place is zero but the next lower place is not (`1680.32` →
`壹仟陆佰捌拾元叁角贰分` or `…元零叁角贰分`; `107000` → `壹拾万柒仟` or `壹拾万零柒仟`). This writes
the form without it. The `零` the rules require (a group starting with
zeros after a higher group, `壹万零伍佰`, and an empty 角 before a 分, `壹元零伍分`)
is written.
- **`null` reads `''`**, as `trim(null)` and `label()` of an empty field
do, so an empty total prints an empty line rather than failing the
formula.
- **Skill token budget.** `skills/objectstack-formula/SKILL.md` had 7
tokens of headroom. The new row is paid by deleting the sentence "If you
need a helper that doesn't exist, prefer adding it to the stdlib (small,
pure, dependency-free) over inlining a complex CEL expression." The
skill ships to app authors whose `@objectstack/formula` is dist-only
(the same section says "there is no `src/` to read"), so that advice
addresses platform contributors; `formulas.mdx` keeps its "Add new
helpers in `packages/formula/src/stdlib.ts`" note for them. Readings:
the file 494 to 492 lines, 5990 to 5988 tokens (ceiling 5997); the
bundle's SKILL.md files 4594 to 4592 lines.
- **Not measured:** no live REST read of a formula field calling
`rmbUpper` (the checklist item's live leg); every row runs through the
same `celEngine.evaluate` the read path calls.
## Verification
<details><summary>Local gates at head 4fffca7 (base 9e6fee1)</summary>
- Build closure: `pnpm --filter '@objectstack/formula^...' build`, then
`turbo run build --filter=@objectstack/lint...
--filter=@objectstack/client-react...` (exit 0) for the gates that read
dist.
- `node scripts/pm/dispatch-gates.mjs --commands` derived 107 families;
all 107 ran (`--ran` reconciliation: 107 derived, 107 run, 0 unrun). 104
exited 0.
- `node scripts/check-plugin-teardown-shape.mjs --self-test` exited 3 on
the shallow clone (its pinned fixture commit was absent); after `git
fetch --depth=1 origin 621a487` it
exits 0 (48 cases pass).
- `pnpm check:dual-build-cjs-loads`: NOT MEASURED, reason: exit 3
`PREREQUISITE NOT MET`, it reads every package's dist and only the lint
and client-react closures were built. CI's run is the reading.
- `pnpm check:platform-checklist` exits 1 on one problem that is **not
this diff's**: `approvals.json · approvals.approver-resolution-matrix:
VARIANTS STALE — ApproverType … now has 11 members but this item's
variants were authored against 10`. It exits 1 with the same problem on
`origin/main` 9e6fee1 itself (the shared checkout, untouched by this
branch); `ApproverType` last changed in 27c0b20 (#34300). This diff
edits only the formula stdlib item, which the gate does not flag.
Reported to the seat; not fixed here (out of scope).
- `node scripts/check-platform-checklist.mjs --changed-from
origin/main`: OK, 2 anchored files, 0 lost.
- `node scripts/check-skills-token-ratchet.mjs`: exit 0,
`skills/objectstack-formula/SKILL.md` 5988 / 5997.
- Not run locally (CI's): `test:repo`, repo-wide `pnpm lint`. No dogfood
battery is owed (no `!` in the title, no narrowing arm).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(no `packages/spec` change)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (repo-wide lint is CI's
run)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5nHvfaZE5NLUTcWkFZ
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5nHvfaZE5NLUTcWkFZ)_
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5pmEYLVFDcQ1Z1CS8H -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3e49033 commit 12b69e1
9 files changed
Lines changed: 485 additions & 21 deletions
File tree
- .changeset
- content/docs/data-modeling
- docs/qa/platform-checklist/areas
- packages/formula/src
- skills/objectstack-formula
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
| |||
595 | 596 | | |
596 | 597 | | |
597 | 598 | | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
598 | 630 | | |
599 | 631 | | |
600 | 632 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
| 508 | + | |
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
0 commit comments