Add allow_negative_stock toggle for sales, remissions, quotes, layaways and service orders
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user