Add allow_negative_stock toggle for sales, remissions, quotes, layaways and service orders
Some checks failed
CI / lint-and-test (3.11) (push) Has been cancelled
CI / lint-and-test (3.13) (push) Has been cancelled

This commit is contained in:
2026-07-15 18:02:43 +00:00
parent 116d4452da
commit c90012ca37
7 changed files with 76 additions and 44 deletions

View File

@@ -8,6 +8,16 @@ from datetime import datetime
from services import inventory_engine
def _tenant_allows_negative_stock(conn):
"""Return True if the tenant explicitly allows selling below zero stock."""
cur = conn.cursor()
cur.execute("SELECT value FROM tenant_config WHERE key = 'allow_negative_stock'")
row = cur.fetchone()
cur.close()
return row is not None and str(row[0]).lower() in ('true', '1', 'yes')
# Rached workshop statuses (applies to all tenants).
ORDER_STATUSES = [
'por_revisar',
@@ -612,10 +622,11 @@ def reserve_item(conn, so_item_id, branch_id, employee_id=None):
raise ValueError("Item has no inventory linked")
qty = int(quantity)
available = inventory_engine.get_stock(conn, inventory_id, branch_id)
if available < qty:
cur.close()
raise ValueError(f"Insufficient stock. Available: {available}, requested: {qty}")
if not _tenant_allows_negative_stock(conn):
available = inventory_engine.get_stock(conn, inventory_id, branch_id)
if available < qty:
cur.close()
raise ValueError(f"Sin stock suficiente. Disponible: {available}, solicitado: {qty}")
inventory_engine.record_operation(
conn,