feat: add KS-3/payments, tech debt fixes, UI polish, and KS-2 Excel/Word export

Tasks 008-016: KS-6a journal, KS-3 documents, payments with allocations,
tech debt cleanup, financial privacy, document tree, storno mechanism,
row-click UI, BOQ collapse/sticky header, and KS-2 export to Excel/Word
via shared DTO architecture.
This commit is contained in:
Арсентьев Александр
2026-09-27 13:38:45 +03:00
parent 6c608a8779
commit 9cfb341774
57 changed files with 7163 additions and 50 deletions
+56 -2
View File
@@ -1,9 +1,10 @@
from datetime import date
from decimal import Decimal
from pathlib import Path
import re
from fastapi import APIRouter, Depends, Form, HTTPException, Request
from fastapi.responses import RedirectResponse
from fastapi.responses import RedirectResponse, Response
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session, joinedload
@@ -147,4 +148,57 @@ async def ks2_issue(project_id: int, ks2_id: int, db: Session = Depends(get_db))
issue_ks2(db, project_id, ks2_id)
except KS2ValidationError as exc:
raise HTTPException(status_code=409, detail=str(exc)) from exc
return RedirectResponse(f"/projects/{project_id}/ks2/{ks2_id}", status_code=303)
return RedirectResponse(f"/projects/{project_id}/ks2/{ks2_id}", status_code=303)
@router.post("/{project_id}/ks2/{ks2_id}/cancel")
async def ks2_cancel(project_id: int, ks2_id: int, db: Session = Depends(get_db)):
from app.models.ks2 import KS2
doc = db.query(KS2).filter(KS2.id == ks2_id, KS2.project_id == project_id).first()
if doc is None:
raise HTTPException(status_code=404, detail="KS-2 not found")
if doc.status == "cancelled":
raise HTTPException(status_code=400, detail="KS-2 already cancelled")
doc.status = "cancelled"
db.commit()
return RedirectResponse(f"/projects/{project_id}/ks2/{ks2_id}", status_code=303)
def _safe_filename(number: str, dt) -> str:
raw = f"КС-2 №{number} от {dt.strftime('%d.%m.%Y')}"
return re.sub(r'[<>:"/\\|?*]', "_", raw)
def _content_disposition(filename: str) -> str:
from urllib.parse import quote
return f"attachment; filename*=UTF-8''{quote(filename)}"
@router.get("/{project_id}/ks2/{ks2_id}/export/excel")
async def ks2_export_excel(project_id: int, ks2_id: int, db: Session = Depends(get_db)):
document = _document(db, project_id, ks2_id)
from app.exporters.ks2_dto import build_ks2_export_dto
from app.exporters.excel.ks2_renderer import render_ks2_excel
dto = build_ks2_export_dto(db, document)
data = render_ks2_excel(dto)
filename = _safe_filename(document.number, document.date) + ".xlsx"
return Response(
content=data,
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
headers={"Content-Disposition": _content_disposition(filename)},
)
@router.get("/{project_id}/ks2/{ks2_id}/export/word")
async def ks2_export_word(project_id: int, ks2_id: int, db: Session = Depends(get_db)):
document = _document(db, project_id, ks2_id)
from app.exporters.ks2_dto import build_ks2_export_dto
from app.exporters.word.ks2_renderer import render_ks2_word
dto = build_ks2_export_dto(db, document)
data = render_ks2_word(dto)
filename = _safe_filename(document.number, document.date) + ".docx"
return Response(
content=data,
media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
headers={"Content-Disposition": _content_disposition(filename)},
)