|
|
@@ -148,6 +148,18 @@ def normalize_qc_work_order_completed(raw) -> Optional[bool]:
|
|
|
return None
|
|
|
|
|
|
|
|
|
+def normalize_ready_for_review_only(raw) -> Optional[bool]:
|
|
|
+ """Return True when ready-only filter should apply; None means no filter."""
|
|
|
+ if raw is None:
|
|
|
+ return None
|
|
|
+ if isinstance(raw, bool):
|
|
|
+ return True if raw else None
|
|
|
+ s = str(raw).strip().lower()
|
|
|
+ if s in ("true", "1", "yes"):
|
|
|
+ return True
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
def _qc_work_order_exists_for_review_sample(
|
|
|
tenant_no: str, *, unfinished_only: bool = False
|
|
|
):
|
|
|
@@ -171,6 +183,27 @@ def _qc_work_order_exists_for_review_sample(
|
|
|
)
|
|
|
|
|
|
|
|
|
+def _production_work_order_unfinished_exists_for_review_sample(tenant_no: str):
|
|
|
+ """True if sample has any unfinished inbound-side production WO (dpz/jxz)."""
|
|
|
+ conds = [
|
|
|
+ BizProductionWorkOrder.tenant_no == tenant_no,
|
|
|
+ BizProductionWorkOrder.del_flag == 0,
|
|
|
+ BizProductionWorkOrder.sample_code.isnot(None),
|
|
|
+ BizProductionWorkOrder.sample_code != "",
|
|
|
+ eq_unicode(
|
|
|
+ BizProductionWorkOrder.sample_code, BizStorageReleaseReview.sample_code
|
|
|
+ ),
|
|
|
+ BizStorageReleaseReview.sample_code.isnot(None),
|
|
|
+ BizStorageReleaseReview.sample_code != "",
|
|
|
+ BizProductionWorkOrder.work_order_status.in_(("dpz", "jxz")),
|
|
|
+ ]
|
|
|
+ return (
|
|
|
+ exists()
|
|
|
+ .where(and_(*conds))
|
|
|
+ .correlate(BizStorageReleaseReview)
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def list_reviews(
|
|
|
db: Session,
|
|
|
*,
|
|
|
@@ -183,6 +216,7 @@ def list_reviews(
|
|
|
keyword: Optional[str] = None,
|
|
|
review_phase: Optional[str] = None,
|
|
|
qc_work_order_completed=None,
|
|
|
+ ready_for_review_only=None,
|
|
|
user_info=None,
|
|
|
) -> Dict[str, Any]:
|
|
|
q0 = db.query(BizStorageReleaseReview).filter(
|
|
|
@@ -246,6 +280,14 @@ def list_reviews(
|
|
|
),
|
|
|
)
|
|
|
)
|
|
|
+ if normalize_ready_for_review_only(ready_for_review_only) is True:
|
|
|
+ # 无未完成质检/生产工单 ⇒ 该侧完成(含零工单)
|
|
|
+ q0 = q0.filter(
|
|
|
+ ~_qc_work_order_exists_for_review_sample(
|
|
|
+ tenant_no, unfinished_only=True
|
|
|
+ ),
|
|
|
+ ~_production_work_order_unfinished_exists_for_review_sample(tenant_no),
|
|
|
+ )
|
|
|
if user_info:
|
|
|
from app.core.data_scope import apply_data_scope
|
|
|
q0 = apply_data_scope(q0, BizStorageReleaseReview, user_info, db, tenant_no)
|