fix(payment): 缴费信息列表返回样本状态与作废原因
Web 列表走 list_sample_payments_page,补齐 sampleStatus/voidDesc(#136)。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b57898fabb
commit
b59c921b50
2 files changed
+83
-2
No files matched your search
@@ -45,6 +45,14 @@ from app.services.sample_payment_progress import (
|
||||
)
|
||||
|
||||
|
||||
_SAMPLE_STATUS_LABELS = {
|
||||
"ycj": "已采集",
|
||||
"jcz": "检测中",
|
||||
"yrk": "已入库",
|
||||
"yzf": "已作废",
|
||||
}
|
||||
|
||||
|
||||
def _fmt_ymd8(v: Any) -> str:
|
||||
s = str(v or "").strip()
|
||||
if len(s) == 8 and s.isdigit():
|
||||
@@ -1882,6 +1890,7 @@ def _build_list_summary_row(
|
||||
]
|
||||
receivable = float(sum(active_dues, Decimal("0"))) if active_dues else 0.0
|
||||
discount = meta.get("discountAmount")
|
||||
sample_status = str(meta.get("sampleStatus") or "").strip()
|
||||
row: Dict[str, Any] = {
|
||||
"id": sp.id,
|
||||
"collectionProtocolId": sp.collection_protocol_id,
|
||||
@@ -1891,6 +1900,10 @@ def _build_list_summary_row(
|
||||
"motherName": (party.mother_name if party else "") or "",
|
||||
"motherPhone": (party.mother_phone if party else "") or "",
|
||||
"sampleCode": sp.sample_code or "",
|
||||
"sampleStatus": sample_status,
|
||||
"sampleStatusLabel": str(meta.get("sampleStatusLabel") or "").strip()
|
||||
or _SAMPLE_STATUS_LABELS.get(sample_status, ""),
|
||||
"voidDesc": str(meta.get("voidDesc") or "").strip(),
|
||||
"payMode": sp.pay_mode or "",
|
||||
"contractAmount": float(sp.contract_amount)
|
||||
if sp.contract_amount is not None
|
||||
@@ -2020,10 +2033,14 @@ def list_sample_payments_page(
|
||||
discount = None
|
||||
if orig is not None and price is not None and orig > price:
|
||||
discount = round(orig - price, 2)
|
||||
status = str(s.sample_status or "").strip()
|
||||
sample_meta_by_key[key] = {
|
||||
"storageYears": s.storage_years,
|
||||
"sampleTypeName": type_name_map.get(s.sample_type_id or "", ""),
|
||||
"discountAmount": discount,
|
||||
"sampleStatus": status,
|
||||
"sampleStatusLabel": _SAMPLE_STATUS_LABELS.get(status, ""),
|
||||
"voidDesc": str(getattr(s, "void_desc", None) or "").strip(),
|
||||
}
|
||||
rows: List[Dict[str, Any]] = []
|
||||
for sp, proto, party in candidates:
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
"""样本缴费列表:进度过滤与分页顺序"""
|
||||
"""样本缴费列表:进度过滤与分页顺序、样本状态汇总字段"""
|
||||
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
|
||||
from app.crud.protocol_sample_payment import _filter_and_page_progress
|
||||
from app.crud.protocol_sample_payment import (
|
||||
_build_list_summary_row,
|
||||
_filter_and_page_progress,
|
||||
)
|
||||
|
||||
|
||||
class TestFilterAndPageProgress(unittest.TestCase):
|
||||
@@ -33,5 +37,65 @@ class TestFilterAndPageProgress(unittest.TestCase):
|
||||
self.assertEqual([r["id"] for r in page], ["0", "1", "2"])
|
||||
|
||||
|
||||
class TestPaymentListSampleStatus(unittest.TestCase):
|
||||
def test_summary_row_exposes_sample_status_and_void_desc(self):
|
||||
sp = SimpleNamespace(
|
||||
id="sp1",
|
||||
collection_protocol_id="p1",
|
||||
sample_code="ZKZX34001028",
|
||||
pay_mode="dj",
|
||||
contract_amount=None,
|
||||
remark="",
|
||||
)
|
||||
proto = SimpleNamespace(
|
||||
protocol_no="CP-1",
|
||||
protocol_status="sxz",
|
||||
void_type="",
|
||||
register_date="20261101",
|
||||
)
|
||||
party = SimpleNamespace(mother_name="张三", mother_phone="13800000000")
|
||||
progress = {
|
||||
"progressStatus": "dfj",
|
||||
"paidAmount": 0,
|
||||
"arrearsAmount": 0,
|
||||
"dueAmount": 0,
|
||||
}
|
||||
row = _build_list_summary_row(
|
||||
sp,
|
||||
proto,
|
||||
party,
|
||||
progress,
|
||||
schedules=[],
|
||||
transfers=[],
|
||||
sample_meta={
|
||||
"storageYears": 20,
|
||||
"sampleTypeName": "脐带血",
|
||||
"discountAmount": None,
|
||||
"sampleStatus": "ycj",
|
||||
"sampleStatusLabel": "已采集",
|
||||
"voidDesc": "",
|
||||
},
|
||||
)
|
||||
self.assertEqual(row["sampleStatus"], "ycj")
|
||||
self.assertEqual(row["sampleStatusLabel"], "已采集")
|
||||
self.assertEqual(row["voidDesc"], "")
|
||||
|
||||
voided = _build_list_summary_row(
|
||||
sp,
|
||||
proto,
|
||||
party,
|
||||
progress,
|
||||
schedules=[],
|
||||
transfers=[],
|
||||
sample_meta={
|
||||
"sampleStatus": "yzf",
|
||||
"voidDesc": "客户放弃存储",
|
||||
},
|
||||
)
|
||||
self.assertEqual(voided["sampleStatus"], "yzf")
|
||||
self.assertEqual(voided["sampleStatusLabel"], "已作废")
|
||||
self.assertEqual(voided["voidDesc"], "客户放弃存储")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user