Skip to content

Commit 220c9ed

Browse files
committed
Allow negative stock
1 parent a5bb791 commit 220c9ed

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ BASE_URL=http://localhost:8000 # Also adjust this to your production url
3030
# (restricts user creation endpoint to these devices)
3131
CHECKOUT_BOX_SLUGS=nfckasse
3232

33+
# Optional: allow purchases when stock is 0 (stock goes negative, default: false)
34+
# ALLOW_NEGATIVE_STOCK=false
35+
3336
# Currency symbol appended to all monetary amounts in API messages and PDF statements (default: €)
3437
CURRENCY=
3538

app/api/v1/products.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require_checkout_device,
1212
require_product_manager_user,
1313
)
14+
from app.config import settings
1415
from app.auth.oidc import is_product_manager
1516
from app.database import get_db
1617
from app.models.machine import Machine
@@ -345,7 +346,7 @@ def purchase_product(
345346
product = _resolve_product(ean, db)
346347
if not product.active:
347348
raise HTTPException(status_code=400, detail="Product is not active")
348-
if product.stock <= 0:
349+
if product.stock <= 0 and not settings.ALLOW_NEGATIVE_STOCK:
349350
raise HTTPException(status_code=400, detail="Product out of stock")
350351

351352
user = db.execute(

app/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class Settings(BaseSettings):
2727
# Devices
2828
CHECKOUT_BOX_SLUGS: str = ""
2929

30+
# Allow purchases when stock is 0 (stock goes negative)
31+
ALLOW_NEGATIVE_STOCK: bool = False
32+
3033
# PDF statement generation (typst)
3134
# Directory containing extra fonts (e.g. albertsans.ttf). Leave empty to use system fonts only.
3235
TYPST_FONT_DIR: str = ""

0 commit comments

Comments
 (0)