Skip to content

fix(expense): Mark as Paid refuses in the caller's language (#2763) - #2765

Merged
sunhaolin merged 1 commit into
mainfrom
claude/quirky-sutherland-2db3d5
Nov 25, 2026
Merged

sunhaolin merged 1 commit into
mainfrom
claude/quirky-sutherland-2db3d5

Conversation

@sunhaolin

Copy link
Copy Markdown
Collaborator

Description

Mark as Paid on an expense report (crm_expense_report.mark_expense_report_paid) refused with four English literals thrown from the script body, so a zh-CN, ja-JP or es-ES user read the reason in English. The action now declares a refusals catalogue and the body throws by code; the three locale packs carry the sentences.

Fixes #2763

Metadata-impact: reviewer

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

  • src/expense/actions/expense.actions.ts — MarkExpenseReportPaidAction declares refusals, one code per sentence, English wording and status unchanged:

    Code Status Sentence
    FORBIDDEN 403 Only finance marks an expense report as paid, once it is approved.
    VALIDATION_FAILED 400 Open the expense report to mark it as paid.
    RECORD_NOT_FOUND 404 This expense report no longer exists.
    CONFLICT 409 Only an approved expense report is marked as paid. Expense report {{name}} is not approved. (params: ['name'])

    The body throws Object.assign(new Error('<log text>'), { code, params? }); the fail helper is gone. SUBMIT_FOR_REIMBURSEMENT_SOURCE and the two submit actions are not touched (zh-CN:「提交报销」「按出差申请报销」的拒绝原因是英文 #2759 stays blocked on refusals: one throw answers one declared sentence — an action that refuses a selection for several reasons at once cannot list them in the person's language (after #34273) objectstack#36877).

  • src/expense/translations/{zh-CN,ja-JP,es-ES}.ts — four rows each under objects.crm_expense_report._actions.mark_expense_report_paid.refusals.<CODE>.message. zh-CN follows the vocabulary of src/expense/docs/crm_expense_recording.zh.md (报销单、已批准、财务). en.ts carries no such keys and is unchanged.

  • test/expense-report-paid-refusals.test.ts — booted stack, 11 cases.

  • .changeset/2763-mark-as-paid-refusals-localised.md (patch).

  • No user doc quotes any of the four sentences, so no doc changed.

Every throw the body can reach

Once a catalogue exists, an undeclared throw answers 500, so each path was checked on @objectstack/* 18.6.0:

  • The four throw statements in the body each carry a declared code (the test counts them: four throw, four declared codes).
  • A recordId naming no report, or one the caller cannot see, is answered by the platform before the body runs (its own 404 RECORD_NOT_FOUND, already localised). A missing or malformed payment_date is answered by the param contract before the body (400 VALIDATION_ERROR).
  • A hook or validation rule refusing the body's update is relayed unchanged.
  • So the body's own RECORD_NOT_FOUND ("This expense report no longer exists.") is read only when the report is deleted between the platform's load and the body's read. The test stages exactly that on the real engine: a spy holds the body's read (the one asking for id, name, status) until a real system delete of the row has finished; both locales answer 404 with the action's sentence.

Measurements

POST /api/v1/actions/crm_expense_report/mark_expense_report_paid on the booted stack.

Before (unchanged action) — the same English for accept-language: en and zh-CN:

Case Answer
caller is not finance 403 FORBIDDEN "Only finance marks an expense report as paid, once it is approved."
no recordId 400 VALIDATION_FAILED "Open the expense report to mark it as paid."
report not approved 409 CONFLICT "Only an approved expense report is marked as paid. Expense report 2026-11-02 is not approved."

After — same status and code in each case; error.message and error.userMessage carry the pack's sentence for zh-CN, ja-JP and es-ES and the unchanged English for en. For zh-CN:

Case Answer
caller is not finance 403 报销单获批准后,只有财务可以把它标记为已付款。
no recordId 400 请打开报销单,再标记为已付款。
report gone mid-run 404 这张报销单已不存在。
report not approved 409 只有已批准的报销单可以标记为已付款。报销单不是已批准状态。

The success path still answers 200 and a second mark on a paid report answers the same 409 without touching the row.

Testing

Run locally on this branch:

  • pnpm validate — exit 0 ("Validation passed")
  • pnpm typecheck — exit 0
  • pnpm lint — exit 0 (49 suggestions, informational; none about this action)
  • pnpm hygiene — exit 0
  • pnpm vitest run on 13 files (expense-report-paid-refusals, expense-module, expense-report-request, expense-skills, script-bodies, psa-approvals, hook-refusal-catalogue, refusal-envelope, refusal-labels, i18n-package-ownership, i18n-references, i18n-shared-widget-parity, locale-label-collisions) — 13 files passed, 277 tests passed.
  • Red check: with the src/ changes reverted, the new suite fails 9 of 11. The two that stay green are the platform's own 404 and the English race case, both true before the change.

Not run / not verified:

  • The full pnpm verify (build plus the whole suite) was not run locally; CI runs it.
  • How the console shows the refusal (toast) in a browser was not checked; only the HTTP answer was measured.
  • The 13-file run printed two "Audit write FAILED … Transaction query already complete" log lines for sys_email from another suite. The new file run alone prints none. Observed, not investigated.

Checklist

  • I have added a changeset
  • Metadata changes under src/ declare their class (Metadata-impact: reviewer above — text and translations of one action; who may mark a report as paid, and when, is unchanged)
  • English docs changed with their Chinese twins (no doc changed)
  • I have added tests that prove my fix is effective

Additional Notes

Noticed, not touched:

  • The platform's param-contract refusal ("Invalid action params: Action param "payment_date" is required") is English in every locale. The console's dialog requires the date, so a person meets it only over REST.
  • A report made by Submit for Reimbursement is named by its date alone, so the 409 reads "Expense report 2026-11-02 is not approved." Existing behaviour.
  • test/hook-refusal-catalogue.test.ts PACKAGES does not list expense.

mark_expense_report_paid threw four English literals, so a zh-CN, ja-JP
or es-ES user read the refusal in English. The action now declares a
refusals catalogue (FORBIDDEN 403, VALIDATION_FAILED 400,
RECORD_NOT_FOUND 404, CONFLICT 409 with the report name as a declared
param) and the script body throws by code. The English wording and each
status are unchanged; the three locale packs carry the sentences.

Every throw the body can reach carries a declared code. A missing or
invisible record and a bad payment_date are answered by the platform
before the body runs, so the body's RECORD_NOT_FOUND is only read when
the report is deleted between the platform's load and the body's read;
the booted test stages that on the real engine.

Fixes #2763
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hotcrm Ignored Ignored Nov 24, 2026 6:28am UTC

Request Review

@github-actions github-actions Bot added ci/cd CI plumbing and the verification pipeline metadata Declarative metadata — schema, security posture, UI surfaces backend Server-side behaviour — hooks, flows, actions labels Nov 24, 2026
@sunhaolin

Copy link
Copy Markdown
Collaborator Author

Seat record · 独立评审 · head bc02a9ef · 2026-11-25

独立评审(只读子代理,未参与改动)结论:通过(有 nit)。Metadata-impact 同意 reviewer:判断条件、状态码与 code 原样保留,只改了句子的来源。

Findings

  1. test/expense-report-paid-refusals.test.ts:176(nit,本 PR):race 用例按 fields.join() === 'id,name,status' 识别动作自身的读,绑定字段顺序;顺序改了只会让断言失败,不会假通过。
  2. src/expense/actions/expense.actions.ts:322(低,本 PR 之前就有):R.update 被别的规则以 VALIDATION_FAILED 拒绝时用哪句话,无测试覆盖;实际难触发。
  3. 本地化、测试、changeset 无问题;文档无需改。

@sunhaolin
sunhaolin added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 7809784 Nov 25, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Server-side behaviour — hooks, flows, actions ci/cd CI plumbing and the verification pipeline metadata Declarative metadata — schema, security posture, UI surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expense: Mark as Paid refuses in English for zh-CN / ja-JP / es-ES users

1 participant