chore(order-delivery-reply): 前端页面调整、细节修改、优化逻辑等
This commit is contained in:
1 parent
7fb36b301c
commit
36868f875c
36 files changed
+1577
-376
No files matched your search
@@ -73,3 +73,31 @@ def test_keyword_and_date_status_filters_stack(app):
|
||||
assert result["total"] == 0
|
||||
# 断言:status=not_fully_replied(未锁定)两行都算;有批次的行仍是未锁定(部分回复)
|
||||
assert list_lines({"keyword": "齿轮", "status": "not_fully_replied"})["total"] == 2
|
||||
|
||||
|
||||
def test_keyword_matches_salesperson_and_reply_person(app):
|
||||
"""keyword 命中业务员(姓名/工号)与交期回复人员(姓名/工号)即返回(2026-09-23 增补)。"""
|
||||
from app.models.order_delivery_reply import OrderDeliveryLineState
|
||||
|
||||
salesperson_line = _line("8301-P1", 1, cust_no="C-A")
|
||||
salesperson_line.salesperson_name = "王瑞雪"
|
||||
salesperson_line.salesperson_code = "26070045"
|
||||
replied_line = _line("8301-P2", 2, cust_no="C-B")
|
||||
replied_line.salesperson_name = "张小奇"
|
||||
db.session.flush()
|
||||
# 交期回复人员快照存于行状态表(notified_user_name / notified_employee_id)
|
||||
db.session.add(OrderDeliveryLineState(
|
||||
line_id=replied_line.id, notified_user_name="李生", notified_employee_id="10002",
|
||||
))
|
||||
db.session.commit()
|
||||
|
||||
# 断言:业务员姓名命中 → 只返回 8301-P1
|
||||
assert [i["order_no"] for i in list_lines({"keyword": "王瑞雪"})["items"]] == ["8301-P1"]
|
||||
# 断言:业务员工号命中 → 只返回 8301-P1
|
||||
assert [i["order_no"] for i in list_lines({"keyword": "26070045"})["items"]] == ["8301-P1"]
|
||||
# 断言:交期回复人员姓名命中(状态表 EXISTS 子查询)→ 只返回 8301-P2
|
||||
assert [i["order_no"] for i in list_lines({"keyword": "李生"})["items"]] == ["8301-P2"]
|
||||
# 断言:交期回复人员工号命中 → 只返回 8301-P2
|
||||
assert [i["order_no"] for i in list_lines({"keyword": "10002"})["items"]] == ["8301-P2"]
|
||||
# 断言:未命中任何人员 → 空
|
||||
assert list_lines({"keyword": "不存在的名字"})["items"] == []
|
||||
@@ -30,21 +30,18 @@ from app.services.order_delivery_reply.reminder_service import (
|
||||
)
|
||||
|
||||
|
||||
def _make_line(order_no="8301-1605280014", line_no=1, salesperson="10001", created_days_ago=0):
|
||||
"""构造一行已同步快照(created_days_ago 控制未回复超期判定)。"""
|
||||
def _make_line(order_no="8301-1605280014", line_no=1, salesperson="10001", order_days_ago=0):
|
||||
"""构造一行已同步快照(order_days_ago 控制订单日期距今天数,即未回复超期判定的锚点)。"""
|
||||
line = OrderDeliveryErpLine(
|
||||
order_no=order_no,
|
||||
line_no=line_no,
|
||||
order_date=datetime.utcnow().date(),
|
||||
order_date=datetime.utcnow().date() - timedelta(days=order_days_ago),
|
||||
customer_no="C001",
|
||||
salesperson_code=salesperson,
|
||||
qty=Decimal("100"),
|
||||
delivered_qty=Decimal("0"),
|
||||
erp_missing=False,
|
||||
)
|
||||
if created_days_ago:
|
||||
line.created_at = datetime.utcnow() - timedelta(days=created_days_ago)
|
||||
line.updated_at = line.created_at
|
||||
db.session.add(line)
|
||||
db.session.flush()
|
||||
return line
|
||||
@@ -159,8 +156,8 @@ def test_ship_reminder_records_unmapped_salesperson(app, send_recorder):
|
||||
def test_unreplied_reminder_notifies_recipients_with_cadence(app, send_recorder):
|
||||
"""超期未回复行提醒配置的生管;N 天内第二次扫描不重复提醒。"""
|
||||
_make_user("10001", "wx_admin1") # 生管收件人
|
||||
_make_line(order_no="8301-E", line_no=1, created_days_ago=5) # 超 3 天未回复
|
||||
_make_line(order_no="8301-F", line_no=2, created_days_ago=1) # 未超期,不应入选
|
||||
_make_line(order_no="8301-E", line_no=1, order_days_ago=5) # 订单日期超 3 天未回复
|
||||
_make_line(order_no="8301-F", line_no=2, order_days_ago=1) # 未超期,不应入选
|
||||
db.session.commit()
|
||||
|
||||
result = run_unreplied_reminders(unreplied_days=3, notify_user_ids=[1])
|
||||
@@ -178,7 +175,7 @@ def test_unreplied_reminder_notifies_recipients_with_cadence(app, send_recorder)
|
||||
|
||||
def test_unreplied_reminder_skips_without_recipients(app, send_recorder):
|
||||
"""未配置生管收件人(开关关闭或名单为空):跳过发送并如实标记。"""
|
||||
_make_line(order_no="8301-G", line_no=1, created_days_ago=10)
|
||||
_make_line(order_no="8301-G", line_no=1, order_days_ago=10)
|
||||
db.session.commit()
|
||||
|
||||
result = run_unreplied_reminders(unreplied_days=3, notify_user_ids=[])
|
||||
@@ -191,7 +188,7 @@ def test_unreplied_reminder_skips_without_recipients(app, send_recorder):
|
||||
def test_unreplied_reminder_failed_send_does_not_advance_cadence(app, send_recorder):
|
||||
"""发送失败不推进提醒节奏:紧接着的再次扫描仍会尝试提醒(不做 N 天静默)。"""
|
||||
_make_user("10001", "wx_admin2")
|
||||
_make_line(order_no="8301-H", line_no=1, created_days_ago=5)
|
||||
_make_line(order_no="8301-H", line_no=1, order_days_ago=5)
|
||||
db.session.commit()
|
||||
|
||||
send_recorder["ok"] = False
|
||||
@@ -242,12 +239,13 @@ def test_remind_params_defaults_backfill_both_enabled(app):
|
||||
from app.services.schedule.job_params import validate_task_params
|
||||
|
||||
normalized = validate_task_params("order-delivery-remind", {}, check_options=False)
|
||||
# 断言:四个参数齐全,开关默认 True、天数默认 3
|
||||
# 断言:五个参数齐全,开关默认 True、天数默认 3;未回复提醒收件人默认空(回退任务通知人)
|
||||
assert normalized == {
|
||||
"ship_remind_enabled": True,
|
||||
"ship_remind_advance_days": 3,
|
||||
"unreplied_remind_enabled": True,
|
||||
"unreplied_remind_days": 3,
|
||||
"unreplied_remind_user_ids": [],
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +257,7 @@ def test_disabled_ship_reminder_skips_only_ship(app, send_recorder):
|
||||
today = date.today()
|
||||
locked_line = _make_line(order_no="8301-S1", line_no=1)
|
||||
_lock_line(locked_line, today + timedelta(days=2)) # 出货提醒候选
|
||||
_make_line(order_no="8301-S2", line_no=2, created_days_ago=5) # 未回复候选
|
||||
_make_line(order_no="8301-S2", line_no=2, order_days_ago=5) # 未回复候选
|
||||
db.session.commit()
|
||||
|
||||
task = _make_remind_task(
|
||||
@@ -288,7 +286,7 @@ def test_disabled_unreplied_reminder_skips_only_unreplied(app, send_recorder):
|
||||
today = date.today()
|
||||
locked_line = _make_line(order_no="8301-U1", line_no=1)
|
||||
_lock_line(locked_line, today + timedelta(days=2)) # 出货提醒候选
|
||||
_make_line(order_no="8301-U2", line_no=2, created_days_ago=5) # 未回复候选(应被跳过不提醒)
|
||||
_make_line(order_no="8301-U2", line_no=2, order_days_ago=5) # 未回复候选(应被跳过不提醒)
|
||||
db.session.commit()
|
||||
|
||||
task = _make_remind_task(
|
||||
@@ -316,7 +314,7 @@ def test_both_disabled_no_scan_no_send(app, send_recorder):
|
||||
_make_user("10001", "wx_any")
|
||||
locked_line = _make_line(order_no="8301-X1", line_no=1)
|
||||
_lock_line(locked_line, date.today() + timedelta(days=2))
|
||||
_make_line(order_no="8301-X2", line_no=2, created_days_ago=5)
|
||||
_make_line(order_no="8301-X2", line_no=2, order_days_ago=5)
|
||||
db.session.commit()
|
||||
|
||||
task = _make_remind_task(
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"""
|
||||
tests/test_order_delivery_reply_validation.py
|
||||
|
||||
用途:订单交期回复保存「数量守恒」校验的单测——每行各批次合计必须等于订单数量
|
||||
(2026-09-23 由「超额仅提醒」修订)。
|
||||
依赖:conftest 的 app 夹具(testing + sqlite create_all)、reply_service.save_batches/batch_reply。
|
||||
逻辑:合计 ≠ 订单数量 → ValidationError(BATCH_QTY_TOTAL_MISMATCH)且不落任何批次/审计;
|
||||
合计 = 订单数量 → 正常保存(多批次拆分亦同);联合回复中单行不等 → 该行按行失败,
|
||||
不影响其它行(部分成功语义)。
|
||||
"""
|
||||
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.extensions import db
|
||||
from app.models.order_delivery_reply import OrderDeliveryBatch, OrderDeliveryErpLine
|
||||
from app.services.order_delivery_reply.reply_service import batch_reply, save_batches
|
||||
|
||||
|
||||
def _line(order_no, line_no=1, qty="100"):
|
||||
"""构造一行最小快照(qty 即订单数量,未回复提醒/保存校验的对照基准)。"""
|
||||
row = OrderDeliveryErpLine(
|
||||
order_no=order_no,
|
||||
line_no=line_no,
|
||||
order_date=date(2024, 6, 1),
|
||||
customer_no="C001",
|
||||
qty=Decimal(qty),
|
||||
delivered_qty=Decimal("0"),
|
||||
erp_missing=False,
|
||||
)
|
||||
db.session.add(row)
|
||||
return row
|
||||
|
||||
|
||||
def test_save_batches_rejects_total_not_equal_order_qty(app):
|
||||
"""各批次合计 90 ≠ 订单数量 100 → 422 数量守恒错误,且不落任何批次。"""
|
||||
_line("8301-V1", qty="100")
|
||||
db.session.commit()
|
||||
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
save_batches("8301-V1", 1, [{"planned_date": "2026-10-01", "qty": "90"}], operator_user_id=None)
|
||||
# 断言:错误码为数量守恒专用码,便于前端与 errors.json 四语言文案对应
|
||||
assert exc.value.code == "ORDER_DELIVERY_REPLY.BATCH_QTY_TOTAL_MISMATCH"
|
||||
# 断言:校验在任何写操作之前,失败不落批次
|
||||
assert OrderDeliveryBatch.query.count() == 0
|
||||
|
||||
|
||||
def test_save_batches_accepts_exact_total_with_multi_batches(app):
|
||||
"""60 + 40 = 订单数量 100 → 保存成功,多批次拆分合法。"""
|
||||
_line("8301-V2", qty="100")
|
||||
db.session.commit()
|
||||
|
||||
data = save_batches("8301-V2", 1, [
|
||||
{"planned_date": "2026-10-01", "qty": "60"},
|
||||
{"planned_date": "2026-11-01", "qty": "40"},
|
||||
], operator_user_id=None)
|
||||
# 断言:保存成功且 total_qty 与订单数量一致
|
||||
assert data["total_qty"] == "100"
|
||||
assert len(data["batches"]) == 2
|
||||
assert OrderDeliveryBatch.query.count() == 2
|
||||
|
||||
|
||||
def test_batch_reply_mismatch_line_fails_others_succeed(app):
|
||||
"""联合回复:单行合计不等按行失败,另一行正常保存(部分成功语义不回归)。"""
|
||||
_line("8301-V3", line_no=1, qty="100")
|
||||
_line("8301-V3", line_no=2, qty="200")
|
||||
db.session.commit()
|
||||
|
||||
summary = batch_reply([
|
||||
{"order_no": "8301-V3", "line_no": 1, "batches": [{"planned_date": "2026-10-01", "qty": "100"}]},
|
||||
{"order_no": "8301-V3", "line_no": 2, "batches": [{"planned_date": "2026-10-01", "qty": "150"}]},
|
||||
], operator_user_id=None)
|
||||
# 断言:行 2 合计 150 ≠ 200 失败;行 1 保存成功
|
||||
assert summary["succeeded"] == 1
|
||||
assert summary["failed"] == 1
|
||||
assert summary["items"][1]["ok"] is False
|
||||
# 断言:仅成功行落批次
|
||||
assert OrderDeliveryBatch.query.count() == 1
|
||||
Reference in new issue
Block a user