test(backend): align market chase assertions with yjf-only paid

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-10-12 18:06:22 +08:00
1 parent b8b20dcebe
commit d2bb1e0fa1
1 file changed
+107 -5
+107 -5
View File
@@ -13,12 +13,14 @@ from starlette.responses import JSONResponse
from app.models.base import Base
from app.models.models import (
BizAttachment,
BizCellSampleType,
BizCollectionProtocol,
BizCollectionRegionStaff,
BizProtocolCollectionInfo,
BizProtocolPartyCustomer,
BizProtocolPaymentSchedule,
BizProtocolPaymentTransfer,
BizProtocolSample,
BizProtocolSamplePayment,
SysPost,
SysPostRole,
@@ -41,6 +43,8 @@ def _session():
BizProtocolSamplePayment.__table__,
BizProtocolPaymentSchedule.__table__,
BizProtocolPaymentTransfer.__table__,
BizProtocolSample.__table__,
BizCellSampleType.__table__,
BizAttachment.__table__,
BizCollectionRegionStaff.__table__,
SysUser.__table__,
@@ -86,12 +90,17 @@ def _payment_tree(
deleted=0,
transfer_statuses=(),
transfer_dept='',
register_date='20261001',
storage_years=20,
sample_price=80,
sample_original_price=100,
):
protocol = BizCollectionProtocol(
id=f'p-{key}',
protocol_no=f'P-{key}',
protocol_status=protocol_status,
payment_model_version=payment_model_version,
register_date=register_date,
tenant_no=tenant,
create_dept_id='dept-a',
create_time=datetime.now(),
@@ -139,7 +148,27 @@ def _payment_tree(
create_dept_id='dept-a',
del_flag=deleted,
)
db.add_all([protocol, collection, party, payment, schedule])
sample_type = BizCellSampleType(
id=f'type-{key}',
type_code=f'TYPE-{key}',
type_name=f'样本类型-{key}',
tenant_no=tenant,
create_dept_id='dept-a',
del_flag=deleted,
)
sample = BizProtocolSample(
id=f'sample-{key}',
collection_protocol_id=protocol.id,
sample_type_id=sample_type.id,
sample_code=payment.sample_code,
storage_years=storage_years,
price=sample_price,
original_price=sample_original_price,
tenant_no=tenant,
create_dept_id='dept-a',
del_flag=deleted,
)
db.add_all([protocol, collection, party, payment, schedule, sample_type, sample])
for index, status in enumerate(transfer_statuses):
db.add(
BizProtocolPaymentTransfer(
@@ -186,7 +215,35 @@ def test_chase_is_overdue_union_next_30_days_with_parent_scope():
}
def test_chase_counts_dfj_jfqrz_and_yjf_and_excludes_fully_paid():
def test_payment_chase_uses_historical_nickname_without_user_no_fallback():
from app.services.market_payment import list_payment_chase
db = _session()
db.add_all(
[
SysUser(id='u1', user_no='deleted-sales-no', nick_name='历史删除专员', status='0', tenant_no='tenant-a', create_dept_id='', del_flag=1),
SysUser(id='blank-sales', user_no='raw-sales-no', nick_name='', status='0', tenant_no='tenant-a', create_dept_id='', del_flag=1),
]
)
_payment_tree(db, 'historical-sales', sales='u1')
_payment_tree(db, 'blank-sales', sales='blank-sales')
historical_items, historical_total = list_payment_chase(
db, ctx=_ctx(user_id='u1'), user_info=_user('u1')
)
blank_items, blank_total = list_payment_chase(
db,
ctx=_ctx(user_id='blank-sales'),
user_info=_user('blank-sales'),
)
assert historical_total == 1
assert historical_items[0]['salesUserName'] == '历史删除专员'
assert blank_total == 1
assert blank_items[0]['salesUserName'] == ''
def test_chase_counts_only_yjf_and_excludes_fully_confirmed():
from app.services.market_payment import list_payment_chase
db = _session()
@@ -200,15 +257,15 @@ def test_chase_counts_dfj_jfqrz_and_yjf_and_excludes_fully_paid():
db,
'fully-paid',
due_amount=60,
transfer_statuses=('dfj', 'jfqrz', 'yjf'),
transfer_statuses=('yjf', 'yjf', 'yjf'),
)
items, total = list_payment_chase(db, ctx=_ctx(), user_info=_user())
assert total == 1
assert items[0]['scheduleId'] == 'sch-part-paid'
assert items[0]['paidAmount'] == '60.00'
assert items[0]['arrearsAmount'] == '40.00'
assert items[0]['paidAmount'] == '20.00'
assert items[0]['arrearsAmount'] == '80.00'
def test_chase_filters_counts_orders_and_pages_in_sql_before_materialization():
@@ -757,3 +814,48 @@ def test_list_queries_batch_children_without_n_plus_one():
assert total == 8
assert len(items) == 5
assert len(statements) <= 5
def test_payment_list_contains_card_summary_totals():
from app.services.market_payment import list_payments
db = _session()
_payment_tree(db, 'summary', due_amount=Decimal('100.00'), transfer_statuses=('yjf',))
items, total = list_payments(db, ctx=_ctx(), user_info=_user())
assert total == 1
assert items[0]['paidAmount'] == '20.00'
assert items[0]['remainAmount'] == '80.00'
assert items[0]['activeScheduleCount'] == 1
assert items[0]['clearedScheduleCount'] == 0
assert items[0]['paymentProgress'] == '部分缴费'
assert items[0]['signDate'] == '2026-10-01'
assert items[0]['storageYears'] == 20
assert items[0]['sampleTypeName'] == '样本类型-summary'
assert items[0]['discountAmount'] == '20.00'
assert items[0]['receivableAmount'] == '100.00'
assert items[0]['dueRemainAmount'] == '80.00'
assert len(items[0]['periods']) == 6
assert items[0]['periods'][0]['scheduleNo'] == 1
def test_payment_sample_meta_uses_tenant_and_sample_code_after_protocol_change():
from app.services.market_payment import list_payments
db = _session()
_, payment, _ = _payment_tree(db, 'protocol-changed')
sample = (
db.query(BizProtocolSample)
.filter(BizProtocolSample.sample_code == payment.sample_code)
.one()
)
sample.collection_protocol_id = 'p-previous-protocol'
db.commit()
items, total = list_payments(db, ctx=_ctx(), user_info=_user())
assert total == 1
assert items[0]['storageYears'] == 20
assert items[0]['sampleTypeName'] == '样本类型-protocol-changed'
assert items[0]['discountAmount'] == '20.00'