80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
"""现场链接生成条件:装货/送货段含山峡或云栋客户"""
|
|
from types import SimpleNamespace
|
|
|
|
from app.services.pl_internal_customer import (
|
|
INTERNAL_CUSTOMER_NAMES,
|
|
plan_requires_site_link,
|
|
)
|
|
|
|
|
|
class _FakeQuery:
|
|
def __init__(self, rows):
|
|
self._rows = rows
|
|
|
|
def filter(self, *args, **kwargs):
|
|
return self
|
|
|
|
def first(self):
|
|
if isinstance(self._rows, list):
|
|
return self._rows[0] if self._rows else None
|
|
return self._rows
|
|
|
|
def all(self):
|
|
if isinstance(self._rows, list):
|
|
return self._rows
|
|
return [self._rows] if self._rows else []
|
|
|
|
|
|
class _FakeSession:
|
|
def __init__(self, load=None, deliveries=None):
|
|
self.load = load
|
|
self.deliveries = deliveries or []
|
|
|
|
def query(self, model):
|
|
name = getattr(model, "__name__", str(model))
|
|
if name == "PlPlanLoad":
|
|
return _FakeQuery(self.load)
|
|
if name == "PlPlanDelivery":
|
|
return _FakeQuery(self.deliveries)
|
|
return _FakeQuery(None)
|
|
|
|
|
|
def _plan(**kwargs):
|
|
defaults = {
|
|
"id": "plan-1",
|
|
"supplier_name": None,
|
|
"customer_name": None,
|
|
"destination_name": None,
|
|
}
|
|
defaults.update(kwargs)
|
|
return SimpleNamespace(**defaults)
|
|
|
|
|
|
def test_internal_delivery_requires_site_link():
|
|
plan = _plan()
|
|
db = _FakeSession(
|
|
load=SimpleNamespace(customer_name="巢湖市大自然化工有限公司"),
|
|
deliveries=[SimpleNamespace(customer_name="安庆市山峡化工有限公司")],
|
|
)
|
|
assert plan_requires_site_link(db, tenant_no="shanxia2.0", plan=plan) is True
|
|
|
|
|
|
def test_external_stops_do_not_require_site_link():
|
|
plan = _plan()
|
|
db = _FakeSession(
|
|
load=SimpleNamespace(customer_name="巢湖市大自然化工有限公司"),
|
|
deliveries=[SimpleNamespace(customer_name="外部客户有限公司")],
|
|
)
|
|
assert plan_requires_site_link(db, tenant_no="shanxia2.0", plan=plan) is False
|
|
|
|
|
|
def test_legacy_plan_customer_fallback():
|
|
plan = _plan(customer_name="安徽云栋化工有限公司")
|
|
db = _FakeSession(load=None, deliveries=[])
|
|
assert plan_requires_site_link(db, tenant_no="shanxia2.0", plan=plan) is True
|
|
|
|
|
|
def test_internal_customer_names_constant():
|
|
assert "安庆市山峡化工有限公司" in INTERNAL_CUSTOMER_NAMES
|
|
assert "安徽云栋化工有限公司" in INTERNAL_CUSTOMER_NAMES
|