fix(shipping-notice): 通知准备就地编辑放宽OT实体守卫
- 根因:update-notice-line 等四个编辑路由挂 _require_formal_notice, 通知准备阶段(Notice 未建)行内编辑必报 FORMAL_NOTICE_REQUIRED - 新增 _require_editable_task:Notice/OT 均可进入编辑写路径, 权限仍由服务层状态制闸门裁决(Excel 冻结+忙碌锁+Schema 反向锁) - 覆盖 update-notice-fields/update-notice-line/add/remove 四路由; confirm-uploaded 与 export 保持正式 Notice 严格守卫 - 新增 OT 无 Notice 就地编辑全链路测试(编辑→有效视图→重匹配口径)
This commit is contained in:
1 parent
f57bfc3bee
commit
95488db656
2 files changed
+53
-4
No files matched your search
@@ -154,6 +154,21 @@ def _require_formal_notice(task: Any) -> ShippingNotice:
|
|||||||
return task
|
return task
|
||||||
|
|
||||||
|
|
||||||
|
def _require_editable_task(task: Any) -> Any:
|
||||||
|
"""订单编辑写接口的实体守卫:正式 Notice 或建单前 OT 均可。
|
||||||
|
|
||||||
|
核心逻辑:订单字段/行的编辑权限由服务层状态制闸门裁决
|
||||||
|
(Excel ready 硬冻结 + 活动 Attempt 忙碌锁 + Schema 反向锁),
|
||||||
|
与实体类型无关——通知准备阶段(Notice 未建)编辑履约字段是受支持场景。
|
||||||
|
"""
|
||||||
|
if not isinstance(task, (ShippingNotice, ShippingOrderTask)):
|
||||||
|
raise ValidationError(
|
||||||
|
'Formal shipping notice is required for this operation',
|
||||||
|
code='SHIPPING.FORMAL_NOTICE_REQUIRED',
|
||||||
|
)
|
||||||
|
return task
|
||||||
|
|
||||||
|
|
||||||
@workspace_shipping_notice_bp.route('/shipping-tasks', methods=['GET'])
|
@workspace_shipping_notice_bp.route('/shipping-tasks', methods=['GET'])
|
||||||
def workspace_shipping_tasks():
|
def workspace_shipping_tasks():
|
||||||
"""分页列出当前用户可见的发货任务,可按处理状态过滤。"""
|
"""分页列出当前用户可见的发货任务,可按处理状态过滤。"""
|
||||||
@@ -660,7 +675,7 @@ def workspace_update_shipping_notice_fields(task_no: str):
|
|||||||
task = get_task_for_user(task_no, user.id)
|
task = get_task_for_user(task_no, user.id)
|
||||||
if not task:
|
if not task:
|
||||||
raise NotFoundError('Not found')
|
raise NotFoundError('Not found')
|
||||||
task = _require_formal_notice(task)
|
task = _require_editable_task(task)
|
||||||
data = request.get_json(silent=True) or {}
|
data = request.get_json(silent=True) or {}
|
||||||
fields = data.get('fields')
|
fields = data.get('fields')
|
||||||
if not isinstance(fields, dict) or not fields:
|
if not isinstance(fields, dict) or not fields:
|
||||||
@@ -707,7 +722,7 @@ def workspace_update_shipping_notice_line(task_no: str):
|
|||||||
task = get_task_for_user(task_no, user.id)
|
task = get_task_for_user(task_no, user.id)
|
||||||
if not task:
|
if not task:
|
||||||
raise NotFoundError('Not found')
|
raise NotFoundError('Not found')
|
||||||
task = _require_formal_notice(task)
|
task = _require_editable_task(task)
|
||||||
data = request.get_json(silent=True) or {}
|
data = request.get_json(silent=True) or {}
|
||||||
try:
|
try:
|
||||||
line_index = int(data.get('line_index'))
|
line_index = int(data.get('line_index'))
|
||||||
@@ -796,7 +811,7 @@ def workspace_add_shipping_notice_line(task_no: str):
|
|||||||
task = get_task_for_user(task_no, user.id)
|
task = get_task_for_user(task_no, user.id)
|
||||||
if not task:
|
if not task:
|
||||||
raise NotFoundError('Not found')
|
raise NotFoundError('Not found')
|
||||||
task = _require_formal_notice(task)
|
task = _require_editable_task(task)
|
||||||
data = request.get_json(silent=True) or {}
|
data = request.get_json(silent=True) or {}
|
||||||
line = data.get('line')
|
line = data.get('line')
|
||||||
if not isinstance(line, dict) or not line:
|
if not isinstance(line, dict) or not line:
|
||||||
@@ -822,7 +837,7 @@ def workspace_remove_shipping_notice_line(task_no: str):
|
|||||||
task = get_task_for_user(task_no, user.id)
|
task = get_task_for_user(task_no, user.id)
|
||||||
if not task:
|
if not task:
|
||||||
raise NotFoundError('Not found')
|
raise NotFoundError('Not found')
|
||||||
task = _require_formal_notice(task)
|
task = _require_editable_task(task)
|
||||||
data = request.get_json(silent=True) or {}
|
data = request.get_json(silent=True) or {}
|
||||||
try:
|
try:
|
||||||
line_index = int(data.get('line_index'))
|
line_index = int(data.get('line_index'))
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
"""
|
||||||
|
tests/test_ot_inline_edit.py
|
||||||
|
|
||||||
|
用途:验证通知准备阶段(Notice 未建、仅 OT)的就地编辑全链路。
|
||||||
|
依赖:pytest、task_workflow.update_notice_line、effective_order_view、有效视图夹具。
|
||||||
|
逻辑:复现"FORMAL_NOTICE_REQUIRED"报错场景——OT task_no 直接走 update-notice-line 通道,
|
||||||
|
编辑后有效值立即可见(库存匹配/Excel/通知行的统一读取口径)。
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from app.services.shipping_notice.effective_order_view import effective_order_field_values
|
||||||
|
from app.services.shipping_notice.task_workflow import update_notice_line
|
||||||
|
from tests.test_effective_order_view import _seed_frozen_order
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_notice_line_accepts_order_task_before_notice(app):
|
||||||
|
"""通知准备阶段(无 Notice)编辑 OT 行字段必须成功且进入有效视图。"""
|
||||||
|
with app.app_context():
|
||||||
|
fixture = _seed_frozen_order()
|
||||||
|
response = update_notice_line({
|
||||||
|
'task_id': fixture.order.task_no,
|
||||||
|
'line_index': 0,
|
||||||
|
'patch': {'part_number': 'D4-A08AR12000002'},
|
||||||
|
'event_source': 'workspace_api',
|
||||||
|
'reviewed_by_id': fixture.user.id,
|
||||||
|
'expected_order_data_version': int(fixture.order.order_data_version or 1),
|
||||||
|
})
|
||||||
|
# 断言:服务层对 OT 放行(修复前 API 层 _require_formal_notice 报 FORMAL_NOTICE_REQUIRED)。
|
||||||
|
assert response['status'] == 'ok'
|
||||||
|
_header, lines = effective_order_field_values(fixture.order)
|
||||||
|
# 断言:编辑后的料号进入有效视图(重新匹配库存的读取口径),旧值不再出现。
|
||||||
|
assert lines[0]['f-part'] == 'D4-A08AR12000002'
|
||||||
|
assert lines[1]['f-part'] == 'D4-B07BR07000001'
|
||||||
Reference in new issue
Block a user