feat(pl): 运输计划模块接入数据权限过滤

新增 pl_data_scope 辅助,PL 列表/统计 apply_pl_scope,详情与改删 assert_pl_row_in_scope;运费结算待办审批 skip_scope。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-06-28 21:00:15 +08:00
1 parent bf73b6b2d8
commit eff99edeea
8 files changed
+526 -53

No files matched your search

+11
View File
@@ -9,6 +9,7 @@ from sqlalchemy.orm import Session
from app.core.database import get_db
from app.core.db_auth import DbUserContext, get_db_current_user
from app.services.pl_data_scope import apply_pl_scope, assert_pl_row_in_scope
from app.core.tenant_context import get_tenant_no
from app.core.utils import generate_uuid
from app.models.pl_models import (
@@ -61,6 +62,8 @@ def get_inventory_ledger(
if product_name:
query = query.filter(PlInventory.product_name.contains(product_name))
query = apply_pl_scope(query, PlInventory, user, db, tenant_no)
total = query.count()
offset = (page - 1) * page_size
items = query.order_by(PlInventory.product_name).offset(offset).limit(page_size).all()
@@ -92,6 +95,7 @@ def set_warning_threshold(
)
if inventory:
assert_pl_row_in_scope(db, inventory, PlInventory, user, tenant_no)
inventory.low_stock_warning = payload.low_stock_warning
inventory.high_stock_warning = payload.high_stock_warning
else:
@@ -136,6 +140,7 @@ def list_warnings(
if status:
query = query.filter(PlInventoryWarning.status == status)
query = apply_pl_scope(query, PlInventoryWarning, user, db, tenant_no)
return query.order_by(PlInventoryWarning.create_time.desc()).all()
@@ -160,6 +165,7 @@ def update_warning(
if not warning:
raise HTTPException(status_code=404, detail="预警不存在")
assert_pl_row_in_scope(db, warning, PlInventoryWarning, user, tenant_no)
if payload.status == "resolved":
warning.status = "resolved"
@@ -207,6 +213,8 @@ def list_transactions(
if date_to:
query = query.filter(PlInventoryTransaction.create_time <= date_to)
query = apply_pl_scope(query, PlInventoryTransaction, user, db, tenant_no)
total = query.count()
offset = (page - 1) * page_size
items = query.order_by(PlInventoryTransaction.create_time.desc()).offset(offset).limit(page_size).all()
@@ -236,6 +244,7 @@ def get_summary(
PlInventoryTransaction.create_time >= date_from,
PlInventoryTransaction.create_time <= date_to,
)
query = apply_pl_scope(query, PlInventoryTransaction, user, db, tenant_no)
if product_id:
query = query.filter(PlInventoryTransaction.product_id == product_id)
@@ -295,6 +304,7 @@ def list_document_reminders(
if status:
query = query.filter(PlDocumentReminder.status == status)
query = apply_pl_scope(query, PlDocumentReminder, user, db, tenant_no)
return query.order_by(PlDocumentReminder.expire_date.asc()).all()
@@ -319,6 +329,7 @@ def update_document_reminder(
if not reminder:
raise HTTPException(status_code=404, detail="提醒不存在")
assert_pl_row_in_scope(db, reminder, PlDocumentReminder, user, tenant_no)
reminder.status = payload.status
if payload.remark: