fix(contract-payment): fix comments of contract payment plan
This commit is contained in:
1 parent
60d4f06018
commit
1c0654c6f8
25 files changed
+956
-76
No files matched your search
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
backend/tests/test_contract_payment_parse.py
|
||||
|
||||
用途:验证合同付款预警解析器、三轮预警升级、ERP 金额匹配及周汇总摘要。
|
||||
依赖:contract_payment.parse_service、alert_service、erp_payment_service、supervisor_oa_service(三轮测试 mock)。
|
||||
逻辑:覆盖确定性解析边界、pending 计数与下一次周五 18:00;三轮升级 mock OA 矩阵,不调用外部 OA、文档库或企业微信。
|
||||
用途:验证合同付款预警解析器、三轮预警升级、ERP 金额匹配、周汇总摘要及企微 Excel 收件人列。
|
||||
依赖:contract_payment.parse_service、alert_service、erp_payment_service、supervisor_oa_service(三轮测试 mock)、openpyxl。
|
||||
逻辑:覆盖确定性解析边界、pending 计数与下一次周五 18:00;三轮升级 mock OA 矩阵,不调用外部 OA、文档库或企业微信;Excel 用例只断言「收件人」列为真实姓名。
|
||||
"""
|
||||
|
||||
from datetime import date, datetime
|
||||
@@ -17,10 +17,17 @@ from app.models import (
|
||||
ContractPaymentNode,
|
||||
User,
|
||||
)
|
||||
from io import BytesIO
|
||||
|
||||
from openpyxl import load_workbook
|
||||
|
||||
from app.services.contract_payment.alert_service import (
|
||||
bind_contract_owner_from_applicant,
|
||||
build_weekly_alert_summary,
|
||||
generate_alerts,
|
||||
_alert_status_label,
|
||||
_build_excel,
|
||||
_recipient_display_name,
|
||||
)
|
||||
from app.services.contract_payment import parse_service
|
||||
from app.services.contract_payment.parse_service import parse_contract_bytes, parse_contract_text
|
||||
@@ -549,6 +556,81 @@ def test_weekly_alert_summary_counts_pending_and_next_friday(app):
|
||||
assert at_send_time["next_send_at"] == "2026-09-11T10:00:00Z"
|
||||
|
||||
|
||||
def test_weekly_excel_writes_recipient_real_name_not_role(app):
|
||||
"""关键断言:企微 Excel 列名为「收件人」,单元格写系统用户真实姓名,不再写岗位名称。"""
|
||||
with app.app_context():
|
||||
owner = User(
|
||||
username="excel-owner",
|
||||
email="excel-owner@example.com",
|
||||
status="active",
|
||||
real_name="张三",
|
||||
)
|
||||
db.session.add(owner)
|
||||
db.session.flush()
|
||||
contract = ContractPaymentContract(
|
||||
contract_no="HT-EXCEL-1",
|
||||
purchase_order_no="PO-1",
|
||||
supplier_name="苏州供应商",
|
||||
owner_user_id=owner.id,
|
||||
status="active",
|
||||
)
|
||||
db.session.add(contract)
|
||||
db.session.flush()
|
||||
node = ContractPaymentNode(
|
||||
contract_id=contract.id,
|
||||
node_code="shipment",
|
||||
node_type="shipment",
|
||||
status="active",
|
||||
due_date=date(2026, 9, 1),
|
||||
)
|
||||
db.session.add(node)
|
||||
db.session.flush()
|
||||
alert = ContractPaymentAlert(
|
||||
contract_id=contract.id,
|
||||
node_id=node.id,
|
||||
trigger_key="round:1:date:2026-09-01",
|
||||
recipient_user_id=owner.id,
|
||||
alert_round=1,
|
||||
status="pending",
|
||||
)
|
||||
db.session.add(alert)
|
||||
db.session.commit()
|
||||
|
||||
data, summary = _build_excel([(alert, contract, node, owner)])
|
||||
wb = load_workbook(BytesIO(data))
|
||||
headers = [cell.value for cell in wb.active[1]]
|
||||
row = [cell.value for cell in wb.active[2]]
|
||||
|
||||
assert "收件岗位" not in headers
|
||||
assert headers[10] == "收件人"
|
||||
assert row[10] == "张三"
|
||||
assert row[11] == "待发送"
|
||||
assert "pending" not in row
|
||||
assert "采购负责人" not in row
|
||||
assert summary["total"] == 1
|
||||
|
||||
|
||||
def test_recipient_display_name_falls_back_to_username(app):
|
||||
"""关键断言:真实姓名为空时 Excel 收件人回退用户名,而不是岗位标签。"""
|
||||
with app.app_context():
|
||||
named = User(username="buyer", email="named@example.com", status="active", real_name="李采购")
|
||||
unnamed = User(username="buyer02", email="unnamed@example.com", status="active", real_name=" ")
|
||||
|
||||
assert _recipient_display_name(named) == "李采购"
|
||||
assert _recipient_display_name(unnamed) == "buyer02"
|
||||
assert _recipient_display_name(None) == "—"
|
||||
|
||||
|
||||
def test_alert_status_label_uses_chinese():
|
||||
"""关键断言:Excel 状态列把 pending/sent/failed 写成中文,未知码保留原文。"""
|
||||
assert _alert_status_label("pending") == "待发送"
|
||||
assert _alert_status_label("sent") == "已发送"
|
||||
assert _alert_status_label("failed") == "发送失败"
|
||||
assert _alert_status_label("resolved") == "已关闭"
|
||||
assert _alert_status_label("unknown-code") == "unknown-code"
|
||||
assert _alert_status_label(None) == "—"
|
||||
|
||||
|
||||
def test_erp_payment_amount_matches_the_corresponding_stage():
|
||||
"""关键断言:不同金额的 ERP 付款必须分别匹配同金额付款阶段。"""
|
||||
paid_node_ids = resolve_paid_node_ids(
|
||||
|
||||
Reference in new issue
Block a user