feat: polish document exports and fix filename extensions

This commit is contained in:
Арсентьев Александр
2026-09-27 17:18:15 +03:00
parent d8e92386d9
commit b3741ca106
14 changed files with 920 additions and 112 deletions
+15 -14
View File
@@ -7,6 +7,7 @@ from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Pt
from app.exporters.common import QTY_TEXT, format_date, format_period, project_requisite_lines
from app.exporters.ks6a_dto import KS6aExportDocument
@@ -28,21 +29,21 @@ def render_ks6a_word(doc: KS6aExportDocument) -> bytes:
d.add_paragraph()
# Header block
header_lines = [
("Проект:", h.project_name),
("Заказчик:", h.customer),
]
extra = []
if h.contractor:
header_lines.append(("Подрядчик:", h.contractor))
header_lines.append(("Договор:", h.contract_number))
header_lines.append((
"Период:",
f"{h.period_from.strftime('%d.%m.%Y')} — {h.period_to.strftime('%d.%m.%Y')}",
))
extra.append(("Подрядчик:", h.contractor))
if h.system_name:
header_lines.append(("Система:", h.system_name))
extra.append(("Система:", h.system_name))
header_lines = project_requisite_lines(
project_name=h.project_name,
customer=h.customer,
contract_number=h.contract_number,
contract_date=h.contract_date,
currency=h.currency,
period_text=format_period(h.period_from, h.period_to),
extra=extra,
)
for label, value in header_lines:
p = d.add_paragraph()
run = p.add_run(label + " ")
@@ -71,13 +72,13 @@ def render_ks6a_word(doc: KS6aExportDocument) -> bytes:
for item in doc.items:
row = table.add_row()
row.cells[0].text = str(item.row_number)
row.cells[1].text = item.report_date.strftime("%d.%m.%Y")
row.cells[1].text = format_date(item.report_date)
row.cells[2].text = item.system_name
row.cells[3].text = item.section_name
row.cells[4].text = item.source_number
row.cells[5].text = item.name
row.cells[6].text = item.unit
row.cells[7].text = f"{item.quantity:.2f}"
row.cells[7].text = QTY_TEXT.format(item.quantity)
buf = io.BytesIO()
d.save(buf)