# 延后发货通知单号与库存结果重读 Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** 仅在首次发货 Excel 成功生成时为既有 `ShippingNotice` 分配业务单号,并提供不触发 RPA 的库存结果重读 Gate 动作。 **Architecture:** `ShippingNotice` 继续作为建单、库存和匹配阶段的内部流程载体;新 Notice 在 Excel 前保持 `business_no=None`。首次 Excel Artifact 生成时,同一事务内锁定明细归属、生成 Artifact 并为该 Notice 分配编号。库存重读复用既有快照查询、身份校验、挂接和库存加载函数,不写 RPA trigger。 **Tech Stack:** Flask、SQLAlchemy 2.0、Alembic、pytest、Vue 3、TypeScript、Vitest。 ## Global Constraints - 不新增发货通知单实体、平行表或第二套编号体系。 - 一个 Notice 可通过既有 Reservation/Artifact 明细关联覆盖多条订单明细;有效 Reservation 不得重复归属其他 Notice。 - 新 Notice 仅在首个 Excel 成功生成的事务中分配 `business_no`;历史数据兼容读取不变。 - `reload_inventory_result` 不得调用 `retry_rpa`、写 trigger 或新建 RPA Attempt。 - 新增前端文案同步 zh-CN、zh-TW、en、th 四语言;后端业务错误遵循 `AppError` envelope。 - 保留并避开工作区与本需求无关的未提交改动。 --- ### Task 1: 延后 Notice 编号至首个 Excel 生成 **Files:** - Modify: `backend/app/services/shipping_notice/customer_identity_gate.py` - Modify: `backend/app/services/shipping_notice/export.py` - Modify: `backend/app/services/shipping_notice/business_numbering_service.py` - Modify: `backend/tests/test_shipping_customer_identity_gate.py` - Modify: `backend/tests/test_shipping_excel_template.py` **Interfaces:** - Consumes: `confirm_task_customer(task, customer_id, actor_id)`、`generate_shipment_excel(task)`。 - Produces: 客户确认后 `task.business_no is None`;首个成功 Artifact 创建后 `task.business_no` 非空且可由既有货代接口使用。 - [ ] **Step 1: 写入失败测试** ```python def test_confirm_customer_does_not_assign_business_number(app): with app.app_context(): task, customer, user = _seed_task() confirmed = confirm_task_customer(task, customer_id=customer.id, actor_id=user.id) assert confirmed.customer_id == customer.id assert confirmed.business_no is None def test_first_export_assigns_notice_business_number(app, tmp_path): with app.app_context(): task = _seed_exportable_task_without_business_number(tmp_path) artifact = generate_shipment_excel(task) assert task.business_no is not None assert artifact.task_id == task.id ``` - [ ] **Step 2: 验证失败原因正确** Run: `cd backend; pytest tests/test_shipping_customer_identity_gate.py::test_confirm_customer_does_not_assign_business_number tests/test_shipping_excel_template.py::test_first_export_assigns_notice_business_number -q` Expected: FAIL,因为客户确认路径仍分配编号,或导出路径未分配编号。 - [ ] **Step 3: 最小实现** ```python # customer_identity_gate.py # 仅写入客户确认事实;不得调用 assign_notice_business_number。 # export.py,在首个 Artifact 持久化的同一事务中: if not task.business_no: assign_notice_business_number(task) ``` 保留已有 `assert_notice_has_no_export_artifact` 约束,确保同一 Notice 的首个 Artifact 是唯一编号触发点;分批导出必须由既有波次服务创建新 Notice,禁止在同一 Notice 重生成第二个有效 Artifact。 - [ ] **Step 4: 验证通过** Run: `cd backend; pytest tests/test_shipping_customer_identity_gate.py tests/test_shipping_business_numbering.py tests/test_shipping_excel_template.py -q` Expected: PASS。 ### Task 2: 增加无 RPA 的库存结果重读 Gate 动作 **Files:** - Modify: `backend/app/services/shipping_notice/process_gate_contract.py` - Modify: `backend/app/services/shipping_notice/process_gate_executor.py` - Modify: `backend/app/services/shipping_notice/process_gate_projection.py` - Modify: `backend/app/services/shipping_notice/error_explainability_contract.py` - Test: `backend/tests/test_shipping_process_gate_contract.py` - Test: `backend/tests/test_shipping_process_gate_retry_cap.py` **Interfaces:** - Consumes: `reload_inventory_result`(`inventory_preparation` Gate 的用户动作)。 - Produces: 命中有效快照时挂接并加载库存;无快照时返回 `blocked_retryable`,不写 RPA trigger/Attempt。 - [ ] **Step 1: 写入失败测试** ```python def test_inventory_preparation_allows_reload_without_rpa_trigger(): assert action_belongs_to_gate( gate_code='inventory_preparation', action_code='reload_inventory_result', ) is True def test_reload_inventory_result_reuses_snapshot_without_new_rpa_attempt(app, monkeypatch): task, execution, snapshot = _seed_timeout_task_with_matching_snapshot() result = _dispatch_gate_action(execution, 'reload_inventory_result') assert result['outcome'] == 'passed' assert task.inventory_snapshot_id == snapshot.id assert _rpa_attempt_count(task) == 0 ``` - [ ] **Step 2: 验证失败原因正确** Run: `cd backend; pytest tests/test_shipping_process_gate_contract.py -q` Expected: FAIL,因为 `reload_inventory_result` 未注册为 Gate 动作。 - [ ] **Step 3: 最小实现** ```python def _handle_reload_inventory_result(*, execution, gate, payload): # 使用 _try_reuse_inventory_snapshot 的查询、身份校验与库存加载行为; # 不设置 mode='retry_rpa',不调用 ensure_inventory_via_rpa。 response = ensure_inventory({**_task_payload(execution, payload), 'mode': 'auto'}) return _tool_outcome(action_code='reload_inventory_result', response=response, ...) ``` 当 `inventory_preparation` 的原因是 RPA 超时/耗尽时,投影将 `reload_inventory_result` 作为主动作;`retry_inventory_preparation` 作为明确的“重新获取库存(重新运行 RPA)”替代动作。 - [ ] **Step 4: 验证通过** Run: `cd backend; pytest tests/test_shipping_process_gate_contract.py tests/test_shipping_process_gate_retry_cap.py tests/test_shipping_notice_inventory_rpa_workflow.py -q` Expected: PASS。 ### Task 3: 工作台文案、投影与回归验证 **Files:** - Modify: `frontend/src/locales/zh-CN/workspace.json` - Modify: `frontend/src/locales/zh-TW/workspace.json` - Modify: `frontend/src/locales/en/workspace.json` - Modify: `frontend/src/locales/th/workspace.json` - Modify: `frontend/src/features/shipping-progress/actionPresentation.ts` - Modify: `frontend/src/features/chat/components/shipping-review/ReviewCurrentProcessingCard.spec.ts` - Modify: `docs/features/shipping-notice/technical.md` - Modify: `docs/funclist.md` **Interfaces:** - Consumes: 后端下发的 `reload_inventory_result` 和 Artifact 成功后才出现的 Notice `business_no`。 - Produces: 主按钮显示“重新读取库存结果”;备用按钮明确为“重新获取库存(重新运行 RPA)”;Excel 前不展示单号。 - [ ] **Step 1: 写入失败测试** ```ts it('renders reload result as the timeout primary action', async () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { primaryAction: { code: 'reload_inventory_result' } }, global: { plugins: [i18n] }, }); expect(wrapper.text()).toContain('重新读取库存结果'); }); ``` - [ ] **Step 2: 验证失败原因正确** Run: `cd frontend; npm run test -- ReviewCurrentProcessingCard.spec.ts` Expected: FAIL,因为该动作尚无前端展示映射或翻译。 - [ ] **Step 3: 最小实现** 新增四语言 label,复用动作展示注册表;仅更改此动作及现有 RPA 重试动作的用户可见标签。更新技术文档与功能清单的单号时机、明细归属和库存重读说明。 - [ ] **Step 4: 验证通过** Run: `cd frontend; npm run test -- ReviewCurrentProcessingCard.spec.ts; npm run build` Expected: PASS。 ## Plan Self-Review - 覆盖规格:Task 1 覆盖延后编号;Task 2 覆盖无 RPA 快照读取与超时主动作;Task 3 覆盖 UI、四语言与文档。 - 未新增实体、编号表或新的 RPA 流程;复用现有 Notice、Artifact、Reservation、快照和 Gate 机制。 - 计划未采用未定义的跨域服务;实际代码以现有 `ensure_inventory(mode='auto')` 作为库存快照复用入口。