53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""运输计划:内置山峡/云栋客户判定(合同可免)"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.pl_models import PlPlan, PlPlanDelivery, PlPlanLoad
|
|
|
|
INTERNAL_CUSTOMER_NAMES = frozenset(
|
|
{
|
|
"安庆市山峡化工有限公司",
|
|
"安徽云栋化工有限公司",
|
|
}
|
|
)
|
|
|
|
|
|
def is_internal_customer_name(name: Optional[str]) -> bool:
|
|
return (name or "").strip() in INTERNAL_CUSTOMER_NAMES
|
|
|
|
|
|
def plan_requires_site_link(db: Session, *, tenant_no: str, plan: PlPlan) -> bool:
|
|
"""装货或送货段任一段客户为山峡/云栋时,需要生成现场链接。"""
|
|
load = (
|
|
db.query(PlPlanLoad)
|
|
.filter(
|
|
PlPlanLoad.plan_id == plan.id,
|
|
PlPlanLoad.tenant_no == tenant_no,
|
|
PlPlanLoad.del_flag == 0,
|
|
)
|
|
.first()
|
|
)
|
|
if load:
|
|
if is_internal_customer_name(load.customer_name):
|
|
return True
|
|
elif is_internal_customer_name(plan.supplier_name):
|
|
return True
|
|
|
|
deliveries = (
|
|
db.query(PlPlanDelivery)
|
|
.filter(
|
|
PlPlanDelivery.plan_id == plan.id,
|
|
PlPlanDelivery.tenant_no == tenant_no,
|
|
PlPlanDelivery.del_flag == 0,
|
|
)
|
|
.all()
|
|
)
|
|
if deliveries:
|
|
return any(is_internal_customer_name(row.customer_name) for row in deliveries)
|
|
return is_internal_customer_name(plan.customer_name) or is_internal_customer_name(
|
|
plan.destination_name
|
|
)
|