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
+21 -1
View File
@@ -167,6 +167,7 @@ def save_draft(db: Session, project_id: int, number: str, document_date: date, c
def issue_ks2(db: Session, project_id: int, ks2_id: int):
"""Revalidate current balances, attribute quantity to DR lines oldest-first, and issue atomically."""
artifact = None
word_artifact = None
try:
document = db.query(KS2).filter(KS2.id == ks2_id, KS2.project_id == project_id).with_for_update().first()
if document is None:
@@ -217,12 +218,17 @@ def issue_ks2(db: Session, project_id: int, ks2_id: int):
)
document.status = "issued"
# Generate and persist the official artifact inside this transaction.
# Generate and persist the official artifacts inside this transaction.
from app.exporters.excel.ks2_renderer import (
TEMPLATE_TYPE as KS2_TEMPLATE_TYPE,
TEMPLATE_VERSION as KS2_TEMPLATE_VERSION,
render_ks2_excel,
)
from app.exporters.word.ks2_renderer import (
TEMPLATE_TYPE as KS2_WORD_TEMPLATE_TYPE,
TEMPLATE_VERSION as KS2_WORD_TEMPLATE_VERSION,
render_ks2_word,
)
from app.exporters.ks2_dto import build_ks2_export_dto
from app.services.document_artifact_service import persist_artifact, remove_artifact_file
@@ -239,6 +245,18 @@ def issue_ks2(db: Session, project_id: int, ks2_id: int):
content=content,
dto=dto,
)
word_content = render_ks2_word(dto)
word_artifact = persist_artifact(
db,
project_id=project_id,
document_type="KS2",
document_id=document.id,
format="docx",
template_type=KS2_WORD_TEMPLATE_TYPE,
template_version=KS2_WORD_TEMPLATE_VERSION,
content=word_content,
dto=dto,
)
db.commit()
db.refresh(document)
@@ -247,6 +265,8 @@ def issue_ks2(db: Session, project_id: int, ks2_id: int):
db.rollback()
if artifact is not None:
remove_artifact_file(artifact)
if word_artifact is not None:
remove_artifact_file(word_artifact)
raise