feat(contract): 合同付款预警bug修复

This commit is contained in:
sophie committed 2026-10-28 09:09:53 +08:00
1 parent b02b776a97
commit f0334e5d22
16 files changed
+383 -104

No files matched your search

@@ -4,6 +4,7 @@ backend/tests/test_contract_payment_ledger_focus.py
用途:验收合同台账汇总卡按合同计数,以及点卡片过滤列表。
依赖:Flask test client、ContractPaymentContract、ContractPaymentNode、ledger_focus。
逻辑:固定业务日 2026-09-10,分别构造即将到期、逾期、进行中、本月应付合同后核对计数与 focus 筛选。
金额和比例都为 0 的验收款不把合同算进逾期。
"""
from __future__ import annotations
@@ -12,7 +13,7 @@ from datetime import date
from app import db
from app.models import Agent, ContractPaymentContract, ContractPaymentNode, User
from app.services.contract_payment.ledger_focus import ledger_focus_counts
from app.services.contract_payment.ledger_focus import classify_ledger_status, ledger_focus_counts
def _create_user(*, username: str) -> User:
@@ -136,3 +137,37 @@ def test_list_contracts_focus_filters_ledger(client, app, monkeypatch):
assert summary.get_json()['data']['active'] == 2
assert 'needs_completion' not in summary.get_json()['data']
assert empty.get_json()['data']['total'] == 0
def test_zero_amount_stage_does_not_mark_contract_overdue():
"""金额和比例都为 0 的阶段不参与逾期。"""
status = classify_ledger_status(
contract_status='active',
parse_status='parsed',
nodes=[
{
'status': 'paid',
'percentage': '50',
'amount': '4250.00',
'due_date': date(2026, 9, 2),
'anchor_date': date(2026, 9, 2),
},
{
'status': 'active',
'percentage': '0',
'amount': '0.00',
'due_date': date(2026, 9, 24),
'anchor_date': date(2026, 9, 24),
},
{
'status': 'active',
'percentage': '0',
'amount': '0.00',
'due_date': date(2027, 3, 23),
'anchor_date': date(2026, 9, 24),
},
],
today=date(2026, 10, 27),
)
# 关键断言:预付款已付,验收款和质保款为 0,合同应为已完成而不是已逾期。
assert status == 'completed'
+8 -1
View File
@@ -915,7 +915,14 @@ def test_erp_combined_payment_marks_prepayment_and_shipment_paid():
assert resolve_paid_node_ids(nodes, [Decimal("43200")]) == {1, 2}
def test_oa_company_dropdown_uses_selected_option(app):
def test_erp_payment_matches_acceptance_amount_without_consuming_earlier_stages():
"""关键断言:验收款金额单独命中时只标验收款,不把预付款或出货款记成已付。"""
nodes = [
(1, "prepayment", Decimal("16740")),
(2, "shipment", Decimal("27900")),
(3, "acceptance", Decimal("11160")),
]
assert resolve_paid_node_ids(nodes, [Decimal("11160")]) == {3}
"""关键断言:公司下拉框只取 selected 项,不把全部候选项拼进公司名。"""
page = """
<table><tr>