From b59c921b50072136eecf55a282b9cf8966f86f43 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Thu, 19 Nov 2026 14:51:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(payment):=20=E7=BC=B4=E8=B4=B9=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E6=A0=B7=E6=9C=AC?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=B8=8E=E4=BD=9C=E5=BA=9F=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Web 列表走 list_sample_payments_page,补齐 sampleStatus/voidDesc(#136)。 Co-authored-by: Cursor --- backend/app/crud/protocol_sample_payment.py | 17 +++++ .../tests/test_sample_payment_list_helpers.py | 68 ++++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/backend/app/crud/protocol_sample_payment.py b/backend/app/crud/protocol_sample_payment.py index 2bae8a61..48540ab8 100644 --- a/backend/app/crud/protocol_sample_payment.py +++ b/backend/app/crud/protocol_sample_payment.py @@ -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: diff --git a/backend/tests/test_sample_payment_list_helpers.py b/backend/tests/test_sample_payment_list_helpers.py index 3ec2f18f..78d3177d 100644 --- a/backend/tests/test_sample_payment_list_helpers.py +++ b/backend/tests/test_sample_payment_list_helpers.py @@ -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() -- 2.54.0