feat(manager): customers, throwaways, stock and notes on v2 (platform-v2 step 6.13b)

- CRM -> Customers: search ignoring case and Greek accents (and part of the phone), visits / spent / last visit,
  the card (contact, notes, open tab, every visit with what was on a tab), new/edit/remove
- Inventory -> Throwaways: log (product, quantity with a comma, reason, note) with its cost, today's list (delete today only),
  a period's totals by reason and product, every entry; Inventory -> Stock: an honest 'not available yet'
- Notes: notes (pinned first, edit in place) and to-dos (urgent first, done folded away, who did it kept)
- backend: crm.manage / inventory.manage / notes.use (the customer search also with the dashboard key, for orders);
  spending counted by services/sales.py (refunds off, tab lines in); null clears a field; names/notes not blank, priorities checked;
  waste ?date_from=&date_to= venue dates; the Greek reason labels left the API; live customers.changed / waste.changed / notes.changed
- the overview's notes card needs notes.use and refreshes live
- tests: test_customers_waste_notes.py (4), crm.test.mjs (3), e2e manager.mjs (customers, throwaways, notes, stock, Greek)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 18:36:27 +02:00
co-authored by Claude Opus 5.5
parent 07c9a0aecf
commit bde125bf09
28 changed files with 1356 additions and 1244 deletions
+37 -14
View File
@@ -8,11 +8,25 @@ from database import get_db
from models.notes import SiteNote, SiteTodo
from models.user import User
from schemas.notes import NoteCreate, NoteUpdate, NoteOut, TodoCreate, TodoUpdate, TodoOut
from routers.deps import require_manager
from core.access.deps import require
from core.errors import XeniaError
from services.ws_bus import broadcast_sync
router = APIRouter()
USE = Depends(require("notes.use"))
PRIORITIES = ("normal", "high")
def _changed():
broadcast_sync("notes.changed", {})
def _text(body: str | None) -> str:
if not (body or "").strip():
raise XeniaError("validation.missing", field="body")
return body.strip()
@@ -55,7 +69,7 @@ def _todo_out(t: SiteTodo) -> dict:
# ── Notes ─────────────────────────────────────────────────────────────────────
@router.get("/", response_model=List[NoteOut])
def list_notes(db: Session = Depends(get_db), user: User = Depends(require_manager)):
def list_notes(db: Session = Depends(get_db), user: User = USE):
notes = db.query(SiteNote).order_by(
SiteNote.is_pinned.desc(), SiteNote.updated_at.desc()
).all()
@@ -63,42 +77,44 @@ def list_notes(db: Session = Depends(get_db), user: User = Depends(require_manag
@router.post("/", response_model=NoteOut, status_code=status.HTTP_201_CREATED)
def create_note(body: NoteCreate, db: Session = Depends(get_db), user: User = Depends(require_manager)):
note = SiteNote(body=body.body, is_pinned=body.is_pinned, created_by_id=user.id)
def create_note(body: NoteCreate, db: Session = Depends(get_db), user: User = USE):
note = SiteNote(body=_text(body.body), is_pinned=body.is_pinned, created_by_id=user.id)
db.add(note)
db.commit()
db.refresh(note)
_changed()
return _note_out(note)
@router.put("/{note_id}", response_model=NoteOut)
def update_note(note_id: int, body: NoteUpdate, db: Session = Depends(get_db), user: User = Depends(require_manager)):
def update_note(note_id: int, body: NoteUpdate, db: Session = Depends(get_db), user: User = USE):
note = db.query(SiteNote).filter(SiteNote.id == note_id).first()
if not note:
raise XeniaError("note.not_found")
if body.body is not None:
note.body = body.body
note.body = _text(body.body)
if body.is_pinned is not None:
note.is_pinned = body.is_pinned
note.updated_at = utcnow()
db.commit()
db.refresh(note)
_changed()
return _note_out(note)
@router.delete("/{note_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_note(note_id: int, db: Session = Depends(get_db), user: User = Depends(require_manager)):
def delete_note(note_id: int, db: Session = Depends(get_db), user: User = USE):
note = db.query(SiteNote).filter(SiteNote.id == note_id).first()
if not note:
raise XeniaError("note.not_found")
db.delete(note)
db.commit()
_changed()
# ── Todos ─────────────────────────────────────────────────────────────────────
@router.get("/todos", response_model=List[TodoOut])
def list_todos(done: bool = None, db: Session = Depends(get_db), user: User = Depends(require_manager)):
def list_todos(done: bool = None, db: Session = Depends(get_db), user: User = USE):
q = db.query(SiteTodo)
if done is not None:
q = q.filter(SiteTodo.is_done == done)
@@ -112,22 +128,27 @@ def list_todos(done: bool = None, db: Session = Depends(get_db), user: User = De
@router.post("/todos", response_model=TodoOut, status_code=status.HTTP_201_CREATED)
def create_todo(body: TodoCreate, db: Session = Depends(get_db), user: User = Depends(require_manager)):
todo = SiteTodo(body=body.body, priority=body.priority, created_by_id=user.id)
def create_todo(body: TodoCreate, db: Session = Depends(get_db), user: User = USE):
if body.priority not in PRIORITIES:
raise XeniaError("validation.choice", field="priority", value=body.priority)
todo = SiteTodo(body=_text(body.body), priority=body.priority, created_by_id=user.id)
db.add(todo)
db.commit()
db.refresh(todo)
_changed()
return _todo_out(todo)
@router.put("/todos/{todo_id}", response_model=TodoOut)
def update_todo(todo_id: int, body: TodoUpdate, db: Session = Depends(get_db), user: User = Depends(require_manager)):
def update_todo(todo_id: int, body: TodoUpdate, db: Session = Depends(get_db), user: User = USE):
todo = db.query(SiteTodo).filter(SiteTodo.id == todo_id).first()
if not todo:
raise XeniaError("todo.not_found")
if body.body is not None:
todo.body = body.body
todo.body = _text(body.body)
if body.priority is not None:
if body.priority not in PRIORITIES:
raise XeniaError("validation.choice", field="priority", value=body.priority)
todo.priority = body.priority
if body.is_done is not None:
todo.is_done = body.is_done
@@ -139,13 +160,15 @@ def update_todo(todo_id: int, body: TodoUpdate, db: Session = Depends(get_db), u
todo.done_by_id = None
db.commit()
db.refresh(todo)
_changed()
return _todo_out(todo)
@router.delete("/todos/{todo_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_todo(todo_id: int, db: Session = Depends(get_db), user: User = Depends(require_manager)):
def delete_todo(todo_id: int, db: Session = Depends(get_db), user: User = USE):
todo = db.query(SiteTodo).filter(SiteTodo.id == todo_id).first()
if not todo:
raise XeniaError("todo.not_found")
db.delete(todo)
db.commit()
_changed()