From 0eba80d93caf8f84fdae1a73e436ac0b9143988f Mon Sep 17 00:00:00 2001 From: wuzilong <704541015@qq.com> Date: Thu, 29 Oct 2026 16:36:52 +0800 Subject: [PATCH] feat: allow dispatch calendar kind other on backend. Co-authored-by: Cursor --- backend/app/models/pl_dispatch_calendar.py | 2 +- backend/app/schemas/pl/dispatch_calendar.py | 4 ++-- .../services/pl_dispatch_calendar_service.py | 4 ++-- backend/tests/test_pl_dispatch_calendar.py | 23 +++++++++++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/app/models/pl_dispatch_calendar.py b/backend/app/models/pl_dispatch_calendar.py index 20ba2d578..8eeac9a51 100644 --- a/backend/app/models/pl_dispatch_calendar.py +++ b/backend/app/models/pl_dispatch_calendar.py @@ -24,7 +24,7 @@ class PlDispatchCalendar(Base): quantity = Column(String(16), nullable=True, comment="数量文本(吨),最多两位小数,不参与汇总") calendar_kind = Column( String(16), nullable=False, default="acid", server_default="acid", - comment="日历类型:acid酸派车 alkali碱派车", + comment="日历类型:acid酸派车 alkali碱派车 other其他", ) tenant_no = Column(String(64), nullable=False, comment="租户编号") order_num = Column(Integer, nullable=True, comment="排序号") diff --git a/backend/app/schemas/pl/dispatch_calendar.py b/backend/app/schemas/pl/dispatch_calendar.py index cfe6a0e19..08b212ef7 100644 --- a/backend/app/schemas/pl/dispatch_calendar.py +++ b/backend/app/schemas/pl/dispatch_calendar.py @@ -51,8 +51,8 @@ class CreateBody(BaseModel): @field_validator("calendar_kind") @classmethod def validate_calendar_kind(cls, value: str) -> str: - if value not in ("acid", "alkali"): - raise ValueError("日历类型须为 acid 或 alkali") + if value not in ("acid", "alkali", "other"): + raise ValueError("日历类型须为 acid、alkali 或 other") return value diff --git a/backend/app/services/pl_dispatch_calendar_service.py b/backend/app/services/pl_dispatch_calendar_service.py index 03b8f0b5b..ccb0a08ad 100644 --- a/backend/app/services/pl_dispatch_calendar_service.py +++ b/backend/app/services/pl_dispatch_calendar_service.py @@ -14,13 +14,13 @@ from app.models.pl_models import PlVehicle from app.schemas.pl.dispatch_calendar import CreateBody, UpdateBody from app.services.pl_data_scope import apply_pl_scope -CALENDAR_KINDS = ("acid", "alkali") +CALENDAR_KINDS = ("acid", "alkali", "other") def _calendar_kind(kind: Optional[str]) -> str: value = kind or "acid" if value not in CALENDAR_KINDS: - raise HTTPException(status_code=422, detail="日历类型须为 acid 或 alkali") + raise HTTPException(status_code=422, detail="日历类型须为 acid、alkali 或 other") return value diff --git a/backend/tests/test_pl_dispatch_calendar.py b/backend/tests/test_pl_dispatch_calendar.py index 2b3c5710c..e6efffee3 100644 --- a/backend/tests/test_pl_dispatch_calendar.py +++ b/backend/tests/test_pl_dispatch_calendar.py @@ -219,6 +219,10 @@ def test_http_read_only_manage_permissions_both_clients_and_routes(db, monkeypat assert client.get(path, params={'month': '2026-10', 'calendarKind': 'alkali'}).json()['total'] == 1 assert client.get(path, params={'month': '2026-10', 'calendarKind': 'salt'}).status_code == 422 assert client.put(f"{path}/{alkali.json()['id']}", json=payload(calendarKind='acid')).status_code == 422 + other = client.post(path, json=payload(calendarKind='other')) + assert other.status_code == 200 and other.json()['calendarKind'] == 'other' + assert client.get(path, params={'month': '2026-10', 'calendarKind': 'other'}).json()['total'] == 1 + assert client.put(f"{path}/{other.json()['id']}", json=payload(calendarKind='alkali')).status_code == 422 engine.dispose() @@ -278,6 +282,25 @@ def test_acid_and_alkali_calendars_stay_separate(db): assert kept.destination == '南京' and kept.calendar_kind == 'alkali' +def test_other_calendar_stays_separate_from_acid_and_alkali(db): + _, update, _, svc = modules() + create(db) # acid default + create(db, calendarKind='alkali', origin='碱库') + other = create(db, calendarKind='other', origin='其他库') + other_page = svc.list_records(db, 't1', user(), month='2026-10', calendar_kind='other') + assert other_page['total'] == 1 and other_page['list'][0]['id'] == other.id + assert other_page['list'][0]['calendarKind'] == 'other' + assert svc.list_records(db, 't1', user(), month='2026-10')['total'] == 1 + assert svc.list_records(db, 't1', user(), month='2026-10', calendar_kind='alkali')['total'] == 1 + with pytest.raises(HTTPException) as moved: + svc.update_record(db, 't1', user(), other.id, update(**payload(calendarKind='acid'))) + assert moved.value.status_code == 422 + kept = svc.update_record( + db, 't1', user(), other.id, update(**payload(calendarKind='other', destination='合肥')) + ) + assert kept.destination == '合肥' and kept.calendar_kind == 'other' + + def test_month_pagination_can_fetch_more_than_500_trips(db): model, _, _, svc = modules() db.add_all([model(id=f'bulk-{number:04}', dispatch_date=date(2026, 10, 26),