Backend: Product.updated_at (Zuletzt geaendert)

Neue Spalte updated_at, die bei jeder Stammdaten-Aenderung automatisch nachzieht
(onupdate). Migration legt sie nullable an und setzt Altbestaende auf created_at.
In ProductOut ausgegeben - Basis fuer eine "Zuletzt geaendert"-Spalte im Web.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-28 11:12:03 +02:00
parent 9ca7291c68
commit 45031df1f4
4 changed files with 28 additions and 0 deletions

View File

@@ -331,3 +331,20 @@ def test_verbrauchsgegenstand_unter_mindestbestand(db):
db.commit()
# Unter dem Mindestbestand -> gehört auf die Einkaufsliste (wie ein Lebensmittel).
assert current_stock(db, product.id) < product.min_stock
# ---- Zuletzt geändert ----
def test_updated_at_wird_bei_aenderung_nachgezogen(db):
import time
product = Product(name="Alt")
db.add(product)
db.commit()
db.refresh(product)
erst = product.updated_at
assert erst is not None
time.sleep(0.01)
product.name = "Neu"
db.commit()
db.refresh(product)
assert product.updated_at > erst