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
+17 -11
View File
@@ -131,7 +131,7 @@ def test_issue_ks2_creates_current_xlsx_artifact(storage_root, db_session, proje
).scalar_one_or_none()
assert art is not None
assert art.template_type == "ks2"
assert art.template_version == 1
assert art.template_version == 2
assert art.is_current is True or art.is_current == 1
path = resolve_storage_path(art.storage_key)
@@ -140,7 +140,7 @@ def test_issue_ks2_creates_current_xlsx_artifact(storage_root, db_session, proje
assert art.content_hash == compute_content_hash(content)
dto = build_ks2_export_dto(db_session, ks2)
assert art.input_hash == compute_input_hash(dto, "ks2", 1)
assert art.input_hash == compute_input_hash(dto, "ks2", 2)
def test_issue_ks3_creates_current_docx_artifact(storage_root, db_session, project_id):
@@ -336,10 +336,15 @@ def test_issue_ks3_rollback_leaves_no_orphan(storage_root, db_session, project_i
assert arts == []
# Only KS3 artifacts are orphans of this failed attempt; the committed
# KS-2 artifact file must remain untouched.
ks3_files = list((storage_root / "projects").rglob("*/*.docx")) if storage_root.exists() else []
assert [f for f in ks3_files if f.is_file()] == []
ks3_arts = db_session.execute(
select(DocumentArtifact).where(DocumentArtifact.document_type == "KS3")
).all()
assert ks3_arts == []
ks2_files = list((storage_root / "projects").rglob("*/*.xlsx")) if storage_root.exists() else []
assert len([f for f in ks2_files if f.is_file()]) == 1
ks2_docx = list((storage_root / "projects").rglob("*/*.docx")) if storage_root.exists() else []
# the committed KS-2 Word artifact remains; the failed KS3 attempt added none
assert len([f for f in ks2_docx if f.is_file()]) == 1
# ---------------------------------------------------------------------------
@@ -357,6 +362,7 @@ def test_cancel_ks2_preserves_issued_artifact(storage_root, db_session, project_
select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2",
DocumentArtifact.document_id == ks2.id,
DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True),
)
).scalar_one()
@@ -423,7 +429,8 @@ def test_issued_document_cannot_be_issued_again(storage_root, db_session, projec
art_count = db_session.execute(
select(DocumentArtifact).where(DocumentArtifact.document_type == "KS2")
).all()
assert len(art_count) == 1
# xlsx + docx artifacts are persisted on issue
assert len(art_count) == 2
with pytest.raises(KS2ValidationError, match="черновик"):
issue_ks2(db_session, project_id, ks2.id)
@@ -432,7 +439,7 @@ def test_issued_document_cannot_be_issued_again(storage_root, db_session, projec
arts = db_session.execute(
select(DocumentArtifact).where(DocumentArtifact.document_type == "KS2")
).all()
assert len(arts) == 1
assert len(arts) == 2
def test_issued_document_cannot_be_edited(storage_root, db_session, project_id):
@@ -460,6 +467,7 @@ def test_ks3_issue_does_not_touch_ks2_artifacts(storage_root, db_session, projec
ks2_art = db_session.execute(
select(DocumentArtifact).where(
DocumentArtifact.document_type == "KS2",
DocumentArtifact.format == "xlsx",
DocumentArtifact.is_current.is_(True),
)
).scalar_one()
@@ -477,12 +485,10 @@ def test_ks3_issue_does_not_touch_ks2_artifacts(storage_root, db_session, projec
ks2_art = db_session.get(DocumentArtifact, ks2_art_id)
assert ks2_art.is_current in (True, 1)
assert ks2_art.content_hash == ks2_hash
# Only one KS-2 artifact
assert db_session.execute(
# xlsx + docx KS-2 artifacts (DOC-C3)
assert len(db_session.execute(
select(DocumentArtifact).where(DocumentArtifact.document_type == "KS2")
).all() and len(db_session.execute(
select(DocumentArtifact).where(DocumentArtifact.document_type == "KS2")
).all()) == 1
).all()) == 2
# ---------------------------------------------------------------------------