fix: exclude off-shelf products from dispatch calendar options.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
677f1b4c5a
commit
13570a2aee
5 files changed
+18045
-21641
No files matched your search
@@ -84,9 +84,13 @@ def _resolve_snapshots(db: Session, tenant_no: str, user: DbUserContext, body: C
|
||||
vehicle = _query(db, tenant_no, user, PlVehicle).filter(PlVehicle.id == body.vehicle_id).first()
|
||||
if vehicle is None:
|
||||
raise HTTPException(status_code=422, detail="车辆不存在、已删除或无权访问,请重新选择")
|
||||
product = _query(db, tenant_no, user, CrmProduct).filter(CrmProduct.id == body.product_id).first()
|
||||
product = (
|
||||
_query(db, tenant_no, user, CrmProduct)
|
||||
.filter(CrmProduct.id == body.product_id, CrmProduct.status == "on")
|
||||
.first()
|
||||
)
|
||||
if product is None:
|
||||
raise HTTPException(status_code=422, detail="产品不存在、已删除或无权访问,请重新选择")
|
||||
raise HTTPException(status_code=422, detail="产品不存在、已下架、已删除或无权访问,请重新选择")
|
||||
return {"license_plate": vehicle.license_plate, "product_name": product.product_name}
|
||||
|
||||
|
||||
@@ -146,5 +150,12 @@ def list_vehicles(db: Session, tenant_no: str, user: DbUserContext, *, q: Option
|
||||
|
||||
def list_products(db: Session, tenant_no: str, user: DbUserContext, *, q: Optional[str] = None,
|
||||
page: int = 1, page_size: int = 500) -> dict:
|
||||
return _list_options(db, tenant_no, user, CrmProduct, CrmProduct.product_name,
|
||||
"productName", q, page, page_size)
|
||||
query = _query(db, tenant_no, user, CrmProduct).filter(CrmProduct.status == "on")
|
||||
keyword = (q or "").strip()
|
||||
if keyword:
|
||||
query = query.filter(CrmProduct.product_name.contains(keyword, autoescape=True))
|
||||
total = query.count()
|
||||
rows = query.order_by(CrmProduct.create_time.desc(), CrmProduct.id.desc()).offset(
|
||||
(page - 1) * page_size
|
||||
).limit(page_size).all()
|
||||
return {"list": [{"id": row.id, "productName": row.product_name} for row in rows], "total": total}
|
||||
File diff suppressed because it is too large.
Load diff
+15289
-15215
File diff suppressed because it is too large.
Load diff
@@ -139,6 +139,22 @@ def test_options_full_library_types_search_pagination(db):
|
||||
assert svc.list_products(db, 't1', user(), q='%')['total'] == 0
|
||||
|
||||
|
||||
def test_off_shelf_products_excluded_from_options_and_create(db):
|
||||
_, _, _, svc = modules()
|
||||
db.add(CrmProduct(id='p-off', product_no='POFF', product_name='下架液碱',
|
||||
tenant_no='t1', create_by='u1', status='off'))
|
||||
db.commit()
|
||||
ids = {row['id'] for row in svc.list_products(db, 't1', user())['list']}
|
||||
assert 'p-off' not in ids
|
||||
assert 'p1' in ids and 'p2' in ids
|
||||
assert svc.list_products(db, 't1', user(), q='下架')['total'] == 0
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
create(db, productId='p-off')
|
||||
assert exc.value.status_code == 422
|
||||
assert '下架' in exc.value.detail
|
||||
assert svc.list_records(db, 't1', user(), month='2026-10')['total'] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('field,value', [('vehicleId', 'v3'), ('vehicleId', 'v4'), ('vehicleId', 'missing'), ('productId', 'p3'), ('productId', 'p4'), ('productId', 'missing')])
|
||||
def test_invalid_cross_tenant_and_deleted_relations_rejected(db, field, value):
|
||||
_, _, _, svc = modules()
|
||||
|
||||
+1861
-5449
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user