feat: auto-suggest KS-2/KS-3 document numbers

This commit is contained in:
Арсентьев Александр
2026-09-27 17:39:22 +03:00
parent b3741ca106
commit 80b7d4732e
11 changed files with 727 additions and 20 deletions
+21
View File
@@ -0,0 +1,21 @@
"""Next document number suggestions for KS-2 / KS-3.
Separate sequences per document type. Cancelled documents keep their numbers.
Numbers stay strings in the model; suggestion is numeric max + 1.
"""
from sqlalchemy.orm import Session
def next_document_number(db: Session, model, project_id: int) -> str:
"""Return the next free number for the given document model in a project."""
rows = db.query(model.number).filter(model.project_id == project_id).all()
max_number = 0
for (raw,) in rows:
text = str(raw or "").strip()
try:
value = int(text)
except ValueError:
continue
if value > max_number:
max_number = value
return str(max_number + 1)