feat(qc): 工单级附件与取消第三方检测材料必填
质检工单卡片右上角可上传/查看附件;第三方任务材料改为选填,校验与前端必填一并取消。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7792c28893
commit
dfcef6f81f
12 files changed
+359
-19
No files matched your search
@@ -980,6 +980,7 @@ async def update_qc_work_order(
|
||||
external_target_code=body.external_target_code,
|
||||
work_order_status=body.work_order_status,
|
||||
qc_conclusion=body.qc_conclusion,
|
||||
attachments=body.attachments,
|
||||
remark=body.remark,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
@@ -785,13 +785,8 @@ def _set_task_remark(t: BizQcTask, remark: Optional[str]) -> None:
|
||||
|
||||
|
||||
def _require_dsfjc_attachments(t: BizQcTask, *, for_status: str = "ywc") -> None:
|
||||
"""第三方检测且任务状态为已完成时,须至少有一个检测材料附件。"""
|
||||
if (t.task_type or "").strip() != "dsfjc":
|
||||
return
|
||||
if (for_status or "").strip() != "ywc":
|
||||
return
|
||||
if not (t.third_party_attachments or "").strip():
|
||||
raise ValueError("第三方检测须上传检测材料附件")
|
||||
"""历史校验入口:第三方检测材料改为选填,工单级附件在工单卡片维护。"""
|
||||
return
|
||||
|
||||
|
||||
def complete_task(
|
||||
|
||||
@@ -1264,6 +1264,7 @@ def _wo_to_dict(
|
||||
"configuredBy": wo.configured_by or "",
|
||||
"configuredByName": configured_by_name or wo.configured_by or "",
|
||||
"thirdPartyFeeTotal": _dec(wo.third_party_fee_total),
|
||||
"attachments": (getattr(wo, "attachments", None) or "").strip(),
|
||||
"remark": wo.remark or "",
|
||||
"createTime": _fmt_dt(wo.create_time),
|
||||
"updateTime": _fmt_dt(wo.update_time),
|
||||
@@ -3347,6 +3348,7 @@ def update_qc_work_order(
|
||||
external_target_code: Optional[str] = None,
|
||||
work_order_status: Optional[str] = None,
|
||||
qc_conclusion: Optional[str] = None,
|
||||
attachments: Optional[str] = None,
|
||||
remark: Optional[str] = None,
|
||||
) -> BizQcWorkOrder:
|
||||
"""编辑质检工单:入库/出库可改备注、状态与质检结论;临时可改备注与质检对象"""
|
||||
@@ -3377,6 +3379,15 @@ def update_qc_work_order(
|
||||
if conc and conc not in _VALID_QC_WORK_ORDER_CONCLUSIONS:
|
||||
raise ValueError("质检结论无效")
|
||||
wo.conclusion = conc or None
|
||||
if attachments is not None:
|
||||
urls = ",".join(
|
||||
p.strip()
|
||||
for p in (attachments or "").replace(",", ",").split(",")
|
||||
if p.strip()
|
||||
)
|
||||
if len(urls) > 4000:
|
||||
raise ValueError("工单附件过多,请减少后重试")
|
||||
wo.attachments = urls or None
|
||||
if remark is not None:
|
||||
wo.remark = (remark or "").strip() or None
|
||||
wo.update_by = user_id
|
||||
|
||||
@@ -2304,6 +2304,7 @@ class BizQcWorkOrder(Base):
|
||||
configured_time = Column(DateTime, nullable=True, comment="配置时间")
|
||||
configured_by = Column(String(64), nullable=True, comment="配置人")
|
||||
third_party_fee_total = Column(Numeric(18, 2), nullable=True, comment="第三方费用合计")
|
||||
attachments = Column(String(4000), nullable=True, comment="工单附件(逗号分隔URL)")
|
||||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||||
remark = Column(String(512), nullable=True, comment="备注")
|
||||
|
||||
@@ -111,4 +111,7 @@ class QcWorkOrderUpdateBody(BaseModel):
|
||||
qc_conclusion: Optional[str] = Field(
|
||||
None, alias="qcConclusion", description="质检结论 tg合格 btg不合格,空串清空"
|
||||
)
|
||||
attachments: Optional[str] = Field(
|
||||
None, description="工单附件(逗号分隔URL),空串清空"
|
||||
)
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
@@ -0,0 +1,142 @@
|
||||
"""质检工单附件:序列化与第三方材料必填取消。"""
|
||||
|
||||
import os
|
||||
|
||||
# 避免导入 app 时 Settings 因缺 SECRET_KEY 失败
|
||||
os.environ.setdefault(
|
||||
"SECRET_KEY", "test-secret-key-for-qc-wo-attach-unit-tests-32c"
|
||||
)
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
class TestQcWorkOrderAttachmentsDict(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# 先导入 qc_task 打破与 qc_work_order 的循环依赖
|
||||
import app.crud.qc_task # noqa: F401
|
||||
from app.crud import qc_work_order as wo_mod
|
||||
|
||||
cls.wo_mod = wo_mod
|
||||
|
||||
def _base_wo(self, **overrides):
|
||||
wo = SimpleNamespace(
|
||||
id="wo-1",
|
||||
work_order_no="QC001",
|
||||
work_order_type="inbound",
|
||||
reception_id=None,
|
||||
protocol_sample_id=None,
|
||||
collection_protocol_id=None,
|
||||
protocol_no="",
|
||||
sample_code="S1",
|
||||
reception_source="cell_storage",
|
||||
qc_biz_type="inbound",
|
||||
biz_type="",
|
||||
cell_product_id=None,
|
||||
external_target_code=None,
|
||||
trigger_source="reception",
|
||||
production_work_order_id=None,
|
||||
production_task_id=None,
|
||||
production_step_output_id=None,
|
||||
infusion_schedule_id=None,
|
||||
work_order_status="jxz",
|
||||
conclusion=None,
|
||||
has_lab="1",
|
||||
has_third_party="0",
|
||||
configured_time=None,
|
||||
configured_by=None,
|
||||
third_party_fee_total=None,
|
||||
attachments=None,
|
||||
remark=None,
|
||||
create_time=None,
|
||||
update_time=None,
|
||||
)
|
||||
for k, v in overrides.items():
|
||||
setattr(wo, k, v)
|
||||
return wo
|
||||
|
||||
def test_wo_to_dict_includes_attachments(self):
|
||||
data = self.wo_mod._wo_to_dict(
|
||||
self._base_wo(attachments="https://a/x.pdf, https://b/y.png")
|
||||
)
|
||||
self.assertEqual(data["attachments"], "https://a/x.pdf, https://b/y.png")
|
||||
|
||||
def test_wo_to_dict_attachments_default_empty(self):
|
||||
data = self.wo_mod._wo_to_dict(self._base_wo(attachments=None, sample_code=""))
|
||||
self.assertEqual(data["attachments"], "")
|
||||
|
||||
|
||||
class TestRequireDsfjcAttachmentsOptional(unittest.TestCase):
|
||||
def test_complete_without_third_party_attachments_ok(self):
|
||||
from app.crud.qc_task import _require_dsfjc_attachments
|
||||
|
||||
task = SimpleNamespace(task_type="dsfjc", third_party_attachments="")
|
||||
# 不再抛错
|
||||
_require_dsfjc_attachments(task, for_status="ywc")
|
||||
|
||||
|
||||
class TestUpdateQcWorkOrderAttachments(unittest.TestCase):
|
||||
@patch("app.crud.qc_work_order.get_work_order")
|
||||
def test_update_normalizes_and_sets_attachments(self, mock_get):
|
||||
from app.crud.qc_work_order import update_qc_work_order
|
||||
|
||||
wo = SimpleNamespace(
|
||||
id="wo-3",
|
||||
work_order_type="inbound",
|
||||
attachments=None,
|
||||
remark=None,
|
||||
work_order_status="jxz",
|
||||
conclusion=None,
|
||||
cell_product_id=None,
|
||||
external_target_code=None,
|
||||
update_by=None,
|
||||
update_time=None,
|
||||
)
|
||||
mock_get.return_value = wo
|
||||
db = MagicMock()
|
||||
|
||||
update_qc_work_order(
|
||||
db,
|
||||
"wo-3",
|
||||
tenant_no="zkxw",
|
||||
user_id="u1",
|
||||
attachments=" https://a/1.pdf , https://b/2.pdf , ",
|
||||
)
|
||||
self.assertEqual(wo.attachments, "https://a/1.pdf,https://b/2.pdf")
|
||||
self.assertEqual(wo.update_by, "u1")
|
||||
db.add.assert_called()
|
||||
db.flush.assert_called()
|
||||
|
||||
@patch("app.crud.qc_work_order.get_work_order")
|
||||
def test_update_clear_attachments(self, mock_get):
|
||||
from app.crud.qc_work_order import update_qc_work_order
|
||||
|
||||
wo = SimpleNamespace(
|
||||
id="wo-4",
|
||||
work_order_type="inbound",
|
||||
attachments="https://a/1.pdf",
|
||||
remark=None,
|
||||
work_order_status="jxz",
|
||||
conclusion=None,
|
||||
cell_product_id=None,
|
||||
external_target_code=None,
|
||||
update_by=None,
|
||||
update_time=None,
|
||||
)
|
||||
mock_get.return_value = wo
|
||||
db = MagicMock()
|
||||
|
||||
update_qc_work_order(
|
||||
db,
|
||||
"wo-4",
|
||||
tenant_no="zkxw",
|
||||
user_id="u1",
|
||||
attachments="",
|
||||
)
|
||||
self.assertIsNone(wo.attachments)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user