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:
Арсентьев Александр
2026-10-03 19:48:29 +03:00
parent 79c7d4f335
commit bd64bb6307
49 changed files with 6917 additions and 353 deletions
+18 -9
View File
@@ -117,6 +117,7 @@ def test_ks2_issued_download_xlsx(storage_root, db_session, ctx):
art = db_session.execute(select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2",
DocumentArtifact.document_id == ks2.id,
DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True),
)).scalar_one()
stored = resolve_storage_path(art.storage_key).read_bytes()
@@ -137,6 +138,7 @@ def test_ks2_download_does_not_mutate_artifact(storage_root, db_session, ctx):
ks2 = _make_issued_ks2(db_session, ctx)
art = db_session.execute(select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2",
DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True),
)).scalar_one()
art_id, is_current, ch, ih = art.id, art.is_current, art.content_hash, art.input_hash
@@ -153,13 +155,15 @@ def test_ks2_download_does_not_mutate_artifact(storage_root, db_session, ctx):
assert art.input_hash == ih
count = db_session.execute(select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2")).all()
assert len(count) == 1
# xlsx + docx artifacts are persisted on issue
assert len(count) == 2
def test_ks2_cancelled_download_same_artifact(storage_root, db_session, ctx):
ks2 = _make_issued_ks2(db_session, ctx)
art = db_session.execute(select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2",
DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True),
)).scalar_one()
stored = resolve_storage_path(art.storage_key).read_bytes()
@@ -191,7 +195,8 @@ def test_ks2_missing_artifact_404(storage_root, db_session, ctx):
ks2 = _make_issued_ks2(db_session, ctx)
# Delete the physical file
art = db_session.execute(select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2", DocumentArtifact.is_current.is_(True))).scalar_one()
DocumentArtifact.document_type == "KS2", DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True))).scalar_one()
resolve_storage_path(art.storage_key).unlink()
client = _client(sessionmaker(bind=db_session.get_bind(), expire_on_commit=False))
@@ -206,7 +211,8 @@ def test_ks2_missing_artifact_404(storage_root, db_session, ctx):
def test_ks2_hash_mismatch_not_served(storage_root, db_session, ctx):
ks2 = _make_issued_ks2(db_session, ctx)
art = db_session.execute(select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2", DocumentArtifact.is_current.is_(True))).scalar_one()
DocumentArtifact.document_type == "KS2", DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True))).scalar_one()
path = resolve_storage_path(art.storage_key)
path.write_bytes(b"tampered")
@@ -324,22 +330,24 @@ def test_ks3_cross_project_rejected(storage_root, db_session, ctx):
# ---------------------------------------------------------------------------
# UI visibility
# ---------------------------------------------------------------------------
def test_ks2_ui_shows_official_button_only_non_draft(storage_root, db_session, ctx):
def test_ks2_ui_shows_single_export_button(storage_root, db_session, ctx):
client = _client(sessionmaker(bind=db_session.get_bind(), expire_on_commit=False))
try:
# Draft: no official button
# Draft: single working KS-2 button, no legacy "Официальная форма"
draft = save_ks2_draft(db_session, ctx["project_id"], "K2-UI", date(2026, 3, 1), None,
[(ctx["work_item_id"], Decimal("5"))],
reporting_period_from=date(2026, 2, 1),
reporting_period_to=date(2026, 2, 28))
resp = client.get(f"/projects/{ctx['project_id']}/ks2/{draft.id}")
assert "КС-2 (Excel)" in resp.text
assert "Официальная форма" not in resp.text
# Issued: button present
# Issued: same single button
ks2 = issue_ks2(db_session, ctx["project_id"], draft.id)
resp = client.get(f"/projects/{ctx['project_id']}/ks2/{ks2.id}")
assert "Официальная форма" in resp.text
assert "/artifact" in resp.text
assert "КС-2 (Excel)" in resp.text
assert "/export/excel" in resp.text
assert "Официальная форма" not in resp.text
finally:
_clear()
@@ -350,7 +358,8 @@ def test_ks2_ui_cancelled_shows_storno_badge(storage_root, db_session, ctx):
client = _client(sessionmaker(bind=db_session.get_bind(), expire_on_commit=False))
try:
resp = client.get(f"/projects/{ctx['project_id']}/ks2/{ks2.id}")
assert "Официальная форма" in resp.text
assert "КС-2 (Excel)" in resp.text
assert "Официальная форма" not in resp.text
assert "СТОРНИРОВАН" in resp.text
finally:
_clear()