Repository navigation
fix(psa): refuse an expense report's submission on a locked, closed or cancelled project (#2764) - #2773
Draft
sunhaolin wants to merge 3 commits into
Draft
fix(psa): refuse an expense report's submission on a locked, closed or cancelled project (#2764)#2773sunhaolin wants to merge 3 commits into
sunhaolin wants to merge 3 commits into
Conversation
…r cancelled project (#2764) Submit on a draft expense report of a project with Lock Time and Expenses ticked, or of a Closed or Cancelled project, answered "submitted for approval" and the flow expense_report_project_approval then set the report back to Draft with a notice. A timesheet on the same project was refused at the click. Project Delivery now contributes three validation rules to crm_expense_report through objectExtensions (ADR-0130 R4: no hook on another package's object). They refuse the write that makes the report Submitted, with the reason and what to do, in en, zh-CN, es-ES and ja-JP. A Draft is never refused. The flow keeps its turn-back branches as the backstop for a project that locks or closes between the rule's read and the flow's. Submit for Reimbursement and Submit Against a Travel Request submit the reports of open projects and of no project, keep the refused report in Draft, and end the click with an error naming it, where they reported success for all. The locale-pack ownership guard (#2352) now also lets a module word the rules it contributes to another package's object, as it already let it label the fields it contributes. Fixes #2764
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
5 tasks done
Collaborator
Author
|
Seat record · 独立评审 · HOLD · head 独立评审(只读子代理,xhigh,未参与改动)结论:通过(有 nit),建议合并前补第 1 条守卫。Metadata-impact 同意
Findings
已核实:规则条件与流程 OVER / LOCKED 分支一致;在途报销单不受影响;驳回后重交被拦;表单直改状态与管理员写入均被覆盖;四语齐全;en / zh-Hans / zh-Hant 文档与中英手册已更新;测试覆盖 issue 列出的每种提交方式与兜底路径。 |
…d-project-report-submit-54f6ce
…2764) Review follow-ups on #2773: - has() on record.crm_project.status / .time_entry_locked in the three rules (AGENTS.md #630), pinned by test/expense-report-project-rules-total.test.ts through evaluateValidationRules, including a report created as Submitted. - EXP-004 in docs/feature-inventory.md: a bulk submit can now partly succeed. - expense.actions.ts: the 'before anything is written' comment names its one exception. - Changeset: the trip action is Submit for a Trip; a report created or imported directly as Submitted is refused too.
This was referenced Nov 25, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2764
What was wrong
On a project with Lock Time and Expenses ticked (
crm_project.time_entry_locked), or on a Closed or Cancelled project, Submit on a draft expense report (submit_expense_report) was accepted: the click answered "Expense report … submitted for approval.", and a moment later the flowexpense_report_project_approval(turn_back_locked/turn_back_over) set the report back to Draft and left a notice in the inbox. A timesheet on the same project is refused at the click with the reason (src/psa/objects/timesheet.hook.ts).Which option, and why
Option A of the issue: the submission is refused at the click. The report stays in Draft, the person reads why and what to do, and no approval request or notice is created.
How
The expense package knows nothing of projects, and no hook may attach to another package's object (ADR-0130 R4), so the refusal is three validation rules contributed by Project Delivery to
crm_expense_reportthrough theobjectExtensionsit already uses for the report's Project field (src/psa/extensions/expense-project.extension.ts):expense_report_project_closedexpense_report_project_cancelledexpense_report_project_lockedEach is a
conditionalrule (when: status becomessubmittedand the report has a project;then: one hop throughrecord.crm_project), the shapecontract_same_accountoncrm_sales_orderalready uses. The engine evaluates them on every write, so the Submit button, the stage path and a plainPATCHare all covered, for every caller (an administrator is not exempt, as with the timesheet). A Draft is never refused: a report on such a project can still be written, changed and deleted. With Project Delivery disabled the rules leave with the field. No platform change was needed.One behaviour this adds beyond the issue, please confirm it: the rules'
whentreats a create as a write that makes the report Submitted (previous == null), so a report created or imported directly as Submitted through the API on a locked, Closed or Cancelled project is now refused too. Before, it was accepted without that check: the turn-back flow isrecord-after-updateand never saw a create. I kept it because the question "may this report be Submitted on this project?" has the same answer whichever write asks it, and the state machine (expense_report_status_progression) has noinitialStates, so a create as Submitted is otherwise open. No seed data creates expense reports, so no seed is affected.Every read through the project carries
has()(has(record.crm_project.status),has(record.crm_project.time_entry_locked)), per AGENTS.md "Validation predicates must be TOTAL" (#630) and as the flow's ownOVER/LOCKEDtests do: a project row read without either key leaves the rule answerable instead of unevaluable (which would refuse the write).test/expense-report-project-rules-total.test.tsruns the three rules through the engine'sevaluateValidationRuleswith such rows and pins no "failed to evaluate" warning, admission on an open project, and each refusal still given when only its own key is present.The messages are translated in all four locales (
src/psa/translations/{en,zh-CN,es-ES,ja-JP}.ts,objects.crm_expense_report._validations.*). They sit in Project Delivery's packs, beside the label of the Project field it contributes to the same object, so they leave with the rules.One guard changed, please look at it:
test/i18n-package-ownership.test.ts(#2352) let a module's pack carry a row for another package's object only when the row labelled fields the module contributes throughobjectExtensions(#2416). This is the first time a module contributes validation rules that way, so the allowance now also covers the messages of the rules it contributes (the rule's name and the name of the rule inside aconditional), and nothing else: the object's own label, a field or a rule the module does not contribute is still a stray. A positive control pins that Project Delivery words exactly its six rule names in every locale.The turn-back flow stays as the backstop
src/psa/flows/expense-report-project-approval.flow.tskeepsturn_back_locked/turn_back_overunchanged (only its header comment changed). They are now reachable only when a project is closed or locked between the rule's read and the flow's read. A test opens that window (it holds the flow, submits on an open project, changes the project, then runs the flow) and pins that the report still ends in Draft with the notice.What Submit for Reimbursement and Submit for a Trip now do
submit_for_reimbursementandsubmit_trip_for_reimbursementshare one script (src/expense/actions/expense.actions.ts). It groups the selected expenses into one draft report per project and submits each. It now catches the rule's refusal per report and carries on:VALIDATION_FAILEDand a message that names each refused report with the rule's reason, then says how many other reports were submitted. Before, it reported success for all of them and the flow turned the refused ones back.The expense package still does not import or name anything of PSA: it only reacts to a
VALIDATION_FAILEDfrom the update.Known limits
@objectstack/*18.6.0 a rule's message is fixed text (no record values are interpolated), so it says "This report's project …" where the timesheet's hook names the project. The report page shows the project beside it.Measured
Booted stack (
@objectstack/verify),test/psa-approvals.test.ts:POST /api/v1/actions/crm_expense_report/submit_expense_reporton a locked, Closed or Cancelled project → 400{"success":false,"error":{"code":"VALIDATION_FAILED","message":…}}; withaccept-language: zh-CNthe message is the Chinese sentence. Afterwards the report and its lines aredraft, there are 0 turned-back notices, 0 approval requests and no flow run.submit_for_reimbursementover a locked and over a Closed project,submit_trip_for_reimbursementover a locked and over a Cancelled one), each with one expense on the refusing project, one on an open project and one on no project: 400VALIDATION_FAILED, messageExpense report <number> was not submitted: <reason in zh-CN> It stays in Draft in My Reports, with its expenses on it. 2 other reports were submitted.; the refused report and its expense aredraftand no flow ran on it; the other two reports aresubmitted, each with one open approval request.Browser, my own dev server on port 4002, dev login button (Dev Admin), UI in zh-CN:
submit_for_reimbursement→ 400submit_expense_report→ 400PATCH /api/v1/data/crm_expense_report/:id→ 400submit_expense_report→ 200After the locked-project refusals:
sys_notification0 rows,sys_approval_request0 rows, the report and its expensedraft, the expense still on the report.Docs
src/expense/docs/crm_expense_recording.md/.zh.md,src/psa/docs/crm_psa_approvals_budget.md/.zh.md.content/docs/(operate)/administration/automation,content/docs/(product)/expenses/index,content/docs/(product)/projects/time-and-expenses, each in en, zh-Hans and zh-Hant.docs/feature-inventory.md,docs/architecture/psa-module-plan.md,docs/architecture/expense-module-plan.md..changeset/2764-report-submit-refused-on-locked-project.md(patch).Possible conflicts
Two open sibling changes touch files this PR touches; whichever lands second needs a rebase:
src/expense/docs/crm_expense_recording*.md,content/docs/(product)/expenses/index*.mdx.src/expense/actions/expense.actions.ts.Checks
pnpm verifylocally atbad5b98c(this branch withorigin/mainaf7025cdmerged in): validate, typecheck, lint, hygiene and build green. The test step was run on a machine at load average ~150: 322 of 334 files passed, and the 29 failures in 12 files (case assignment, quotes, forecasts, seeds and others, most far from this change) were 5 s timeouts and transaction-already-complete faults from the load. Re-run alone, 8 of those files passed outright and the last 4 (flow-billing-handoff,global-actions,psa-approvals,psa-budget-versions) failed only on the 5 s timeout and passed whole with--testTimeout=60000(109 tests). CI is the clean run.Metadata-impact: maintainer — a validation rule tightened (three rules contributed by Project Delivery to
crm_expense_reportrefuse a submission that was accepted and then turned back; no change to who can see or change what)