feat: official KS-2 Excel/Word forms with template markers and single-table flow
Replace the simplified KS-2 exports with the official unified form: - Excel: official blank as working template, merge-safe row insertion, compact layout, header/signer polish, 0.00 money format - Word: official blank via named template markers (DOC-C4), one dynamic works table with repeating header rows, separate closing totals block (Итого / Всего по акту), system group rows merged across 8 columns - Word money formatter (space thousands, comma decimals) and split contract date day/month/year boxes - Issue persists both xlsx and docx artifacts; UI keeps Excel and adds Word download - Daily reports: multi-system item selection in the form Regression tests for renderers, artifacts and layout; docs/tasks + docs/implementation for the DOC-C* series.
This commit is contained in:
@@ -49,7 +49,8 @@ def _report_or_404(db: Session, project_id: int, report_id: int):
|
||||
return report
|
||||
|
||||
|
||||
def _report_rows(db: Session, project_id: int, system_id: int | None, exclude_report_id=None):
|
||||
def _report_rows(db: Session, project_id: int, system_id: int | None, exclude_report_id=None,
|
||||
all_systems: bool = False):
|
||||
totals = db.query(
|
||||
DailyReportItem.work_item_id.label("work_item_id"),
|
||||
func.sum(DailyReportItem.completed_quantity).label("completed"),
|
||||
@@ -64,7 +65,7 @@ def _report_rows(db: Session, project_id: int, system_id: int | None, exclude_re
|
||||
rows = []
|
||||
for planned in plan["items"]:
|
||||
item = planned.item
|
||||
if item.system_id == system_id:
|
||||
if all_systems or item.system_id == system_id:
|
||||
rows.append({"item": item, "planned_quantity": planned.quantity,
|
||||
"accumulated": totals.get(item.id, Decimal("0"))})
|
||||
rows.sort(key=lambda row: (row["item"].section_id or 0, row["item"].id))
|
||||
@@ -98,11 +99,13 @@ def _render_form(request, db, project_obj, system_id=None, report=None, errors=N
|
||||
selected_system = next((row for row in systems if row.id == selected_id), None)
|
||||
if selected_system is None:
|
||||
raise HTTPException(status_code=400, detail="System does not belong to this project effective plan")
|
||||
rows = _report_rows(db, project_obj.id, selected_id, report.id if report else None)
|
||||
rows = _report_rows(db, project_obj.id, selected_id, report.id if report else None,
|
||||
all_systems=True)
|
||||
current = {line.work_item_id: line.completed_quantity for line in report.items} if report else {}
|
||||
for row in rows:
|
||||
row["current_quantity"] = current.get(row["item"].id)
|
||||
row["over_plan"] = row["accumulated"] + Decimal(str(row["current_quantity"] or 0)) > row["planned_quantity"]
|
||||
row["in_selection"] = row["item"].system_id == selected_id
|
||||
return request.app.templates.TemplateResponse("projects/daily_report_form.html", {
|
||||
"request": request, "project": project_obj, "systems": systems,
|
||||
"has_unclassified_items": bool(unclassified), "unclassified_selected": unclassified_selected,
|
||||
@@ -171,7 +174,7 @@ async def view_daily_report(request: Request, project_id: int, report_id: int,
|
||||
db: Session = Depends(get_db)):
|
||||
project_obj = _project_or_404(db, project_id)
|
||||
report = _report_or_404(db, project_id, report_id)
|
||||
rows = _report_rows(db, project_id, report.system_id, report.id)
|
||||
rows = _report_rows(db, project_id, report.system_id, report.id, all_systems=True)
|
||||
lines = {line.work_item_id: line for line in report.items}
|
||||
displayed = []
|
||||
warnings = []
|
||||
@@ -193,20 +196,22 @@ async def view_daily_report(request: Request, project_id: int, report_id: int,
|
||||
row["closed_quantity"] = info.closed_quantity if info else Decimal("0")
|
||||
row["available_quantity"] = info.available_quantity if info else row["current_quantity"]
|
||||
can_del, del_reason = can_delete_report(db, report)
|
||||
system_names = sorted({row["item"].system.name for row in displayed if row["item"].system})
|
||||
return request.app.templates.TemplateResponse("projects/daily_report_view.html", {
|
||||
"request": request, "project": project_obj, "report": report,
|
||||
"rows": displayed, "warnings": warnings,
|
||||
"rows": displayed, "warnings": warnings, "system_names": system_names,
|
||||
"can_delete_report": can_del, "delete_blocked_reason": del_reason,
|
||||
})
|
||||
|
||||
|
||||
@router.get("/{project_id}/daily-reports/{report_id}/edit")
|
||||
async def edit_daily_report(request: Request, project_id: int, report_id: int,
|
||||
db: Session = Depends(get_db)):
|
||||
system_id: str = None, db: Session = Depends(get_db)):
|
||||
project_obj = _project_or_404(db, project_id)
|
||||
report = _report_or_404(db, project_id, report_id)
|
||||
return _render_form(request, db, project_obj,
|
||||
report.system_id if report.system_id is not None else "unclassified", report)
|
||||
selection = system_id if system_id not in (None, "") else (
|
||||
report.system_id if report.system_id is not None else "unclassified")
|
||||
return _render_form(request, db, project_obj, selection, report)
|
||||
|
||||
|
||||
@router.post("/{project_id}/daily-reports/{report_id}/edit")
|
||||
@@ -259,10 +264,14 @@ def _quantities_from_form(form):
|
||||
|
||||
|
||||
def _validate_work_items(db, project_id, system_id, quantities):
|
||||
effective_ids = {row.item.id for row in build_effective_plan(db, project_id)["items"]
|
||||
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")
|
||||
"""Quantities must reference effective-plan items of the project.
|
||||
|
||||
Items may come from several systems at once: one Daily Report can hold
|
||||
positions of multiple systems, so only project membership is enforced.
|
||||
"""
|
||||
effective_ids = {row.item.id for row in build_effective_plan(db, project_id)["items"]}
|
||||
if not set(quantities).issubset(effective_ids):
|
||||
raise HTTPException(status_code=400, detail="One or more work items are not part of the project effective plan")
|
||||
|
||||
|
||||
def _ks2_closed_item_ids(db, report_id):
|
||||
|
||||
Reference in New Issue
Block a user