feat: add KS-2 UI, reporting period, and table layout fixes

- 004: KS-2 UI (list, create, edit, view, issue) with integration tests
- 005: navigation buttons, financial column alignment, button layout
- 006: reporting_period_from/to fields with migration, validation, display
- 007: fixed table layout with colgroup, quantity2 filter, stable column widths
This commit is contained in:
Арсентьев Александр
2026-09-26 21:36:43 +03:00
parent 1f5eed2064
commit 6c608a8779
20 changed files with 1407 additions and 96 deletions
+28 -3
View File
@@ -1,4 +1,4 @@
from dataclasses import dataclass
from dataclasses import dataclass
from datetime import date
from decimal import Decimal, InvalidOperation
@@ -37,6 +37,17 @@ def _decimal(value):
return result
def _parse_date(value, label):
if value is None:
return None
if isinstance(value, date):
return value
try:
return date.fromisoformat(str(value).strip())
except (ValueError, TypeError) as exc:
raise KS2ValidationError(f"{label}: неверный формат даты") from exc
def build_work_item_balances(db: Session, project_id: int):
"""Return effective plan, accumulated Daily Report fact and issued KS-2 closure."""
plan = build_effective_plan(db, project_id)
@@ -91,7 +102,8 @@ def _validated_entries(db, project_id, entries, excluded_ks2_id=None):
def save_draft(db: Session, project_id: int, number: str, document_date: date, comment: str | None,
entries, ks2_id: int | None = None):
entries, ks2_id: int | None = None,
reporting_period_from=None, reporting_period_to=None):
"""Create/update a draft and its selected lines in one transaction."""
try:
number = (number or "").strip()
@@ -103,6 +115,17 @@ def save_draft(db: Session, project_id: int, number: str, document_date: date, c
if conflict.first():
raise KS2ValidationError("КС-2 с таким номером уже существует в проекте")
normalized, _ = _validated_entries(db, project_id, entries)
period_from = _parse_date(reporting_period_from, "Период с")
period_to = _parse_date(reporting_period_to, "Период по")
if ks2_id is None:
if period_from is None:
raise KS2ValidationError("Укажите дату начала периода")
if period_to is None:
raise KS2ValidationError("Укажите дату окончания периода")
if period_from is not None and period_to is not None and period_to < period_from:
raise KS2ValidationError("Дата окончания периода не может быть раньше даты начала")
document = None
if ks2_id is not None:
document = db.query(KS2).filter(KS2.id == ks2_id, KS2.project_id == project_id).with_for_update().first()
@@ -115,6 +138,8 @@ def save_draft(db: Session, project_id: int, number: str, document_date: date, c
db.add(document)
document.number = number
document.date = document_date
document.reporting_period_from = period_from
document.reporting_period_to = period_to
document.comment = comment.strip() or None if comment else None
document.items.clear()
for item_id, quantity in normalized.items():
@@ -195,4 +220,4 @@ def project_ks2_totals(db: Session, project_id: int):
for document in documents:
rows.append({"document": document, "item_count": len(document.items),
"amount": sum((_decimal(line.amount) for line in document.items), ZERO)})
return rows
return rows