feat: auto-suggest KS-2/KS-3 document numbers
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user