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
+30
View File
@@ -9,6 +9,7 @@ from sqlalchemy.orm import Session
from app.database.database import SessionLocal
from app.models import boq, project
from app.models.daily_report import DailyReport, DailyReportItem
from app.models.ks2 import KS2ItemSource
from app.services.effective_plan import build_effective_plan
router = APIRouter()
@@ -207,6 +208,15 @@ async def update_daily_report(request: Request, project_id: int, report_id: int,
selection = "unclassified" if system_id is None else system_id
return _render_form(request, db, project_obj, selection, report, errors)
_validate_work_items(db, project_id, system_id, quantities)
closed_ids = _ks2_closed_item_ids(db, report.id)
if closed_ids:
existing = {line.id: line for line in report.items}
for line_id in closed_ids:
line = existing.get(line_id)
if line and line.work_item_id not in quantities:
raise HTTPException(status_code=400, detail="Cannot remove quantity closed in KS-2")
if line and quantities.get(line.work_item_id) != line.completed_quantity:
raise HTTPException(status_code=400, detail="Cannot change quantity closed in KS-2")
report.system_id = system_id
report.notes = notes.strip() or None
db.query(DailyReportItem).filter(DailyReportItem.daily_report_id == report.id).delete()
@@ -242,3 +252,23 @@ def _validate_work_items(db, project_id, system_id, quantities):
if row.item.system_id == system_id}
if effective_ids.intersection(quantities) != set(quantities):
raise HTTPException(status_code=400, detail="One or more work items are not part of the selected system effective plan")
def _ks2_closed_item_ids(db, report_id):
"""Return DailyReportItem ids already closed via KS-2 for this report."""
rows = db.query(KS2ItemSource.daily_report_item_id).join(
DailyReportItem, DailyReportItem.id == KS2ItemSource.daily_report_item_id
).filter(DailyReportItem.daily_report_id == report_id).distinct().all()
return {r[0] for r in rows}
@router.post("/{project_id}/daily-reports/{report_id}/delete")
async def delete_daily_report(project_id: int, report_id: int, db: Session = Depends(get_db)):
_project_or_404(db, project_id)
report = _report_or_404(db, project_id, report_id)
closed_ids = _ks2_closed_item_ids(db, report.id)
if closed_ids:
raise HTTPException(status_code=400, detail="Cannot delete daily report with quantities closed in KS-2")
db.delete(report)
db.commit()
return RedirectResponse(f"/projects/{project_id}/daily-reports", status_code=303)