05/08 Phase 4

This commit is contained in:
2026-05-08 10:15:40 -04:00
parent 959f54ed84
commit bf9b54f6b5
26 changed files with 1509 additions and 42 deletions
+31
View File
@@ -212,6 +212,37 @@ def submit():
)
db.session.add(comm_log)
# ── Inventory auto-deduction for product line items ─────
for item in db.session.query(TransactionItem).filter_by(
transaction_id=txn.id
).filter(TransactionItem.product_id.isnot(None)).all():
from app.models.salon import Inventory, InventoryLog, Product as _Prod
prod = _Prod.query.get(item.product_id)
if prod and prod.sku:
inv = Inventory.query.filter_by(
tenant_id=g.tenant.id,
location_id=g.location.id,
sku=prod.sku,
).first()
elif prod:
inv = Inventory.query.filter_by(
tenant_id=g.tenant.id,
location_id=g.location.id,
name=prod.name,
).first()
else:
inv = None
if inv and inv.qty_on_hand > 0:
inv.qty_on_hand -= item.qty
db.session.add(InventoryLog(
tenant_id=g.tenant.id,
location_id=g.location.id,
inventory_id=inv.id,
delta=-item.qty,
reason=f"POS sale txn#{txn.id}",
))
log_tenant_action("transaction.create", "transaction", txn.id,
{"total": float(total), "payment": payment_method})
db.session.commit()