spec.md 2.7 KB

REMOVED Requirements

Requirement: Step save auto stock deduction

Reason: Superseded by production-step-requisition-usage — 步骤保存改为领用关联登记,不再按 actual_usage 直接扣减 stock_qty。

Migration: 见 openspec/changes/production-material-requisition/specs/production-step-requisition-usage/spec.md。

Requirement: Step save diff settlement via full revert and re-deduct

Reason: 「re-deduct」语义移除;重算阶段仅写 parent_usage_id 关联流水,不扣总库。

Migration: 保留 revert 框架;回退规则区分历史/新记录。

Requirement: Step save stock deduction uses row-level locking

Reason: 新流程 step_save 不改 stock_qty,无需对物资主表加锁;manual_out 仍保留行锁。

Migration: 行锁保留在 manual_out 与历史 step_save 回退路径。

Requirement: Step save stock deduction in same transaction

Reason: 合并入 production-step-requisition-usage 的事务原子性要求;错误类型从「库存不足」变为「请选择领用记录」。

Migration: 无数据迁移。

Requirement: Skip deduction for materials not in catalog

Reason: 合并入自定义物料 record-only 规则;目录内物料必须选领用。

Migration: 自定义编码行为不变。

MODIFIED Requirements

Requirement: Stock deduction traceability

每条 step_save 类型的变动记录 SHALL 包含以下溯源字段:

  • step_id — 生产任务步骤 ID
  • step_name — 步骤名称快照
  • task_id — 生产任务 ID
  • task_no — 生产任务编号快照
  • parent_usage_id — 关联领用记录 ID(新流程必填;历史直接扣库为空)

Scenario: Stock log shows task and requisition info

  • WHEN 步骤保存触发 step_save 变动记录(新流程)
  • THEN 变动记录包含 step_id、task_id、task_no、parent_usage_id,且 stock_before 等于 stock_after

Scenario: Legacy stock log without parent

  • WHEN 查询历史 step_save(无 parent_usage_id)
  • THEN 仍展示 task_no/step 溯源;stock_before/stock_after 反映当时直接扣库结果

Requirement: Deduction hooks in replace_step_reagents and replace_step_consumables

步骤试剂/耗材替换函数 SHALL 调用 revert_step_stock_changes() + register_step_usage_from_requisition()(取代原 deduct_for_step() 直接扣库),调用时机不变:软删旧子记录前回退 stock_log,插入新子记录后登记新消耗。

Scenario: replace_step_consumables triggers requisition registration

  • WHEN API PUT /production-tasks/{task_id}/steps/{step_id}/consumables 被调用且含有效 requisitionUsageId
  • THEN 系统登记 step_save 关联流水,不扣减 consumable.stock_qty