feat: polish document exports and fix filename extensions
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""Shared export formatting helpers for Excel/Word renderers."""
|
||||
from datetime import date
|
||||
|
||||
DATE_FMT = "%d.%m.%Y"
|
||||
MONEY_FMT = "#,##0.00"
|
||||
QTY_FMT = "#,##0.00"
|
||||
MONEY_TEXT = "{:.2f}"
|
||||
QTY_TEXT = "{:.2f}"
|
||||
|
||||
|
||||
def format_date(value: date | None) -> str:
|
||||
return value.strftime(DATE_FMT) if value else ""
|
||||
|
||||
|
||||
def format_period(date_from: date | None, date_to: date | None) -> str:
|
||||
if date_from and date_to:
|
||||
return f"{format_date(date_from)} — {format_date(date_to)}"
|
||||
return ""
|
||||
|
||||
|
||||
def project_requisite_lines(
|
||||
project_name: str = "",
|
||||
customer: str = "",
|
||||
contract_number: str = "",
|
||||
contract_date: date | None = None,
|
||||
currency: str = "",
|
||||
period_text: str = "",
|
||||
extra: list[tuple[str, str]] | None = None,
|
||||
) -> list[tuple[str, str]]:
|
||||
"""Unified header block: project, customer, contract, currency, period, extras."""
|
||||
lines: list[tuple[str, str]] = []
|
||||
if project_name:
|
||||
lines.append(("Проект:", project_name))
|
||||
if customer:
|
||||
lines.append(("Заказчик:", customer))
|
||||
if contract_number:
|
||||
lines.append(("Договор:", contract_number))
|
||||
if contract_date:
|
||||
lines.append(("Дата договора:", format_date(contract_date)))
|
||||
if currency:
|
||||
lines.append(("Валюта:", currency))
|
||||
if period_text:
|
||||
lines.append(("Период:", period_text))
|
||||
for label, value in extra or []:
|
||||
if value:
|
||||
lines.append((label, value))
|
||||
return lines
|
||||
@@ -1,19 +1,24 @@
|
||||
"""Excel renderer for KS-2 export using openpyxl."""
|
||||
import io
|
||||
from decimal import Decimal
|
||||
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.styles import Alignment, Border, Font, Side
|
||||
from openpyxl.utils import get_column_letter
|
||||
|
||||
from app.exporters.common import (
|
||||
MONEY_FMT,
|
||||
MONEY_TEXT,
|
||||
QTY_FMT,
|
||||
QTY_TEXT,
|
||||
format_period,
|
||||
project_requisite_lines,
|
||||
)
|
||||
from app.exporters.ks2_dto import KS2ExportDocument
|
||||
|
||||
THIN = Side(style="thin")
|
||||
BORDER = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
||||
HEADER_FONT = Font(bold=True, size=11)
|
||||
TITLE_FONT = Font(bold=True, size=14)
|
||||
MONEY_FMT = '#,##0.00'
|
||||
QTY_FMT = '#,##0.0000'
|
||||
|
||||
|
||||
def render_ks2_excel(doc: KS2ExportDocument) -> bytes:
|
||||
@@ -23,28 +28,28 @@ def render_ks2_excel(doc: KS2ExportDocument) -> bytes:
|
||||
|
||||
h = doc.header
|
||||
row = 1
|
||||
col_count = 7
|
||||
|
||||
# Title
|
||||
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=7)
|
||||
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=col_count)
|
||||
c = ws.cell(row=row, column=1, value=f"Акт КС-2 №{h.ks2_number} от {h.ks2_date.strftime('%d.%m.%Y')}")
|
||||
c.font = TITLE_FONT
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
row += 1
|
||||
|
||||
# Header block
|
||||
header_lines = [
|
||||
("Проект:", h.project_name),
|
||||
("Заказчик:", h.customer),
|
||||
("Договор:", h.contract_number),
|
||||
]
|
||||
if h.period_from and h.period_to:
|
||||
header_lines.append(("Период:", f"{h.period_from.strftime('%d.%m.%Y')} — {h.period_to.strftime('%d.%m.%Y')}"))
|
||||
if h.comment:
|
||||
header_lines.append(("Комментарий:", h.comment))
|
||||
|
||||
# Unified project requisites
|
||||
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=[("Комментарий:", h.comment)],
|
||||
)
|
||||
for label, value in header_lines:
|
||||
ws.cell(row=row, column=1, value=label).font = HEADER_FONT
|
||||
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=7)
|
||||
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=col_count)
|
||||
ws.cell(row=row, column=2, value=value)
|
||||
row += 1
|
||||
|
||||
@@ -100,6 +105,8 @@ def render_ks2_excel(doc: KS2ExportDocument) -> bytes:
|
||||
for col, width in widths.items():
|
||||
ws.column_dimensions[get_column_letter(col)].width = width
|
||||
|
||||
ws.freeze_panes = ws.cell(row=header_row + 1, column=1)
|
||||
|
||||
buf = io.BytesIO()
|
||||
wb.save(buf)
|
||||
buf.seek(0)
|
||||
|
||||
@@ -5,13 +5,18 @@ from openpyxl import Workbook
|
||||
from openpyxl.styles import Alignment, Border, Font, Side
|
||||
from openpyxl.utils import get_column_letter
|
||||
|
||||
from app.exporters.common import (
|
||||
MONEY_FMT,
|
||||
format_date,
|
||||
format_period,
|
||||
project_requisite_lines,
|
||||
)
|
||||
from app.exporters.ks3_dto import KS3ExportDocument
|
||||
|
||||
THIN = Side(style="thin")
|
||||
BORDER = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
||||
HEADER_FONT = Font(bold=True, size=11)
|
||||
TITLE_FONT = Font(bold=True, size=14)
|
||||
MONEY_FMT = '#,##0.00'
|
||||
|
||||
|
||||
def render_ks3_excel(doc: KS3ExportDocument) -> bytes:
|
||||
@@ -21,28 +26,27 @@ def render_ks3_excel(doc: KS3ExportDocument) -> bytes:
|
||||
|
||||
h = doc.header
|
||||
row = 1
|
||||
col_count = 5
|
||||
|
||||
# Title
|
||||
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=5)
|
||||
c = ws.cell(row=row, column=1, value=f"КС-3 №{h.ks3_number} от {h.ks3_date.strftime('%d.%m.%Y')}")
|
||||
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=col_count)
|
||||
c = ws.cell(row=row, column=1, value=f"Акт КС-3 №{h.ks3_number} от {h.ks3_date.strftime('%d.%m.%Y')}")
|
||||
c.font = TITLE_FONT
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
row += 1
|
||||
|
||||
# Header block
|
||||
header_lines = [
|
||||
("Проект:", h.project_name),
|
||||
("Заказчик:", h.customer),
|
||||
("Договор:", h.contract_number),
|
||||
]
|
||||
if h.period_from and h.period_to:
|
||||
header_lines.append(("Период:", f"{h.period_from.strftime('%d.%m.%Y')} — {h.period_to.strftime('%d.%m.%Y')}"))
|
||||
if h.comment:
|
||||
header_lines.append(("Комментарий:", h.comment))
|
||||
|
||||
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=[("Комментарий:", h.comment)],
|
||||
)
|
||||
for label, value in header_lines:
|
||||
ws.cell(row=row, column=1, value=label).font = HEADER_FONT
|
||||
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=5)
|
||||
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=col_count)
|
||||
ws.cell(row=row, column=2, value=value)
|
||||
row += 1
|
||||
|
||||
@@ -55,6 +59,7 @@ def render_ks3_excel(doc: KS3ExportDocument) -> bytes:
|
||||
c.font = HEADER_FONT
|
||||
c.border = BORDER
|
||||
c.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
||||
header_row = row
|
||||
row += 1
|
||||
|
||||
# Items
|
||||
@@ -62,14 +67,12 @@ def render_ks3_excel(doc: KS3ExportDocument) -> bytes:
|
||||
ws.cell(row=row, column=1, value=item.row_number).border = BORDER
|
||||
ws.cell(row=row, column=2, value=f"№{item.ks2_number}").border = BORDER
|
||||
|
||||
c = ws.cell(row=row, column=3, value=item.ks2_date.strftime('%d.%m.%Y') if item.ks2_date else "")
|
||||
c = ws.cell(row=row, column=3, value=format_date(item.ks2_date))
|
||||
c.border = BORDER
|
||||
|
||||
period_text = ""
|
||||
if item.period_from and item.period_to:
|
||||
period_text = f"{item.period_from.strftime('%d.%m.%Y')} — {item.period_to.strftime('%d.%m.%Y')}"
|
||||
c = ws.cell(row=row, column=4, value=period_text)
|
||||
c = ws.cell(row=row, column=4, value=format_period(item.period_from, item.period_to))
|
||||
c.border = BORDER
|
||||
c.alignment = Alignment(wrap_text=True, vertical="top")
|
||||
|
||||
c = ws.cell(row=row, column=5, value=float(item.amount))
|
||||
c.border = BORDER
|
||||
@@ -94,6 +97,8 @@ def render_ks3_excel(doc: KS3ExportDocument) -> bytes:
|
||||
for col, width in widths.items():
|
||||
ws.column_dimensions[get_column_letter(col)].width = width
|
||||
|
||||
ws.freeze_panes = ws.cell(row=header_row + 1, column=1)
|
||||
|
||||
buf = io.BytesIO()
|
||||
wb.save(buf)
|
||||
buf.seek(0)
|
||||
|
||||
@@ -5,13 +5,18 @@ from openpyxl import Workbook
|
||||
from openpyxl.styles import Alignment, Border, Font, Side
|
||||
from openpyxl.utils import get_column_letter
|
||||
|
||||
from app.exporters.common import (
|
||||
QTY_FMT,
|
||||
format_date,
|
||||
format_period,
|
||||
project_requisite_lines,
|
||||
)
|
||||
from app.exporters.ks6a_dto import KS6aExportDocument
|
||||
|
||||
THIN = Side(style="thin")
|
||||
BORDER = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
|
||||
HEADER_FONT = Font(bold=True, size=11)
|
||||
TITLE_FONT = Font(bold=True, size=14)
|
||||
QTY_FMT = '#,##0.00'
|
||||
|
||||
|
||||
def render_ks6a_excel(doc: KS6aExportDocument) -> bytes:
|
||||
@@ -21,32 +26,33 @@ def render_ks6a_excel(doc: KS6aExportDocument) -> bytes:
|
||||
|
||||
h = doc.header
|
||||
row = 1
|
||||
col_count = 8
|
||||
|
||||
# Title
|
||||
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=8)
|
||||
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=col_count)
|
||||
c = ws.cell(row=row, column=1, value="КС-6а — Журнал учёта выполненных работ")
|
||||
c.font = TITLE_FONT
|
||||
c.alignment = Alignment(horizontal="center")
|
||||
row += 1
|
||||
|
||||
# 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:
|
||||
ws.cell(row=row, column=1, value=label).font = HEADER_FONT
|
||||
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=8)
|
||||
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=col_count)
|
||||
ws.cell(row=row, column=2, value=value)
|
||||
row += 1
|
||||
|
||||
@@ -69,7 +75,7 @@ def render_ks6a_excel(doc: KS6aExportDocument) -> bytes:
|
||||
for item in doc.items:
|
||||
ws.cell(row=row, column=1, value=item.row_number).border = BORDER
|
||||
|
||||
c = ws.cell(row=row, column=2, value=item.report_date.strftime("%d.%m.%Y"))
|
||||
c = ws.cell(row=row, column=2, value=format_date(item.report_date))
|
||||
c.border = BORDER
|
||||
|
||||
c = ws.cell(row=row, column=3, value=item.system_name)
|
||||
@@ -98,7 +104,6 @@ def render_ks6a_excel(doc: KS6aExportDocument) -> bytes:
|
||||
for col, width in widths.items():
|
||||
ws.column_dimensions[get_column_letter(col)].width = width
|
||||
|
||||
# Freeze table header
|
||||
ws.freeze_panes = ws.cell(row=header_row + 1, column=1)
|
||||
|
||||
buf = io.BytesIO()
|
||||
|
||||
@@ -20,6 +20,8 @@ class KS2ExportHeader:
|
||||
project_name: str
|
||||
customer: str
|
||||
contract_number: str
|
||||
contract_date: date | None
|
||||
currency: str
|
||||
ks2_number: str
|
||||
ks2_date: date
|
||||
period_from: date | None
|
||||
@@ -59,6 +61,8 @@ def build_ks2_export_dto(db, ks2_document) -> KS2ExportDocument:
|
||||
project_name=project.name if project else "",
|
||||
customer=project.customer if project and project.customer else "",
|
||||
contract_number=project.contract_number if project and project.contract_number else "",
|
||||
contract_date=project.contract_date if project else None,
|
||||
currency=project.currency if project and project.currency else "",
|
||||
ks2_number=ks2_document.number,
|
||||
ks2_date=ks2_document.date,
|
||||
period_from=ks2_document.reporting_period_from,
|
||||
|
||||
@@ -19,6 +19,8 @@ class KS3ExportHeader:
|
||||
project_name: str
|
||||
customer: str
|
||||
contract_number: str
|
||||
contract_date: date | None
|
||||
currency: str
|
||||
ks3_number: str
|
||||
ks3_date: date
|
||||
period_from: date | None
|
||||
@@ -59,6 +61,8 @@ def build_ks3_export_dto(db, ks3_document) -> KS3ExportDocument:
|
||||
project_name=project.name if project else "",
|
||||
customer=project.customer if project and project.customer else "",
|
||||
contract_number=project.contract_number if project and project.contract_number else "",
|
||||
contract_date=project.contract_date if project else None,
|
||||
currency=project.currency if project and project.currency else "",
|
||||
ks3_number=ks3_document.number,
|
||||
ks3_date=ks3_document.date,
|
||||
period_from=ks3_document.reporting_period_from,
|
||||
|
||||
@@ -26,6 +26,8 @@ class KS6aExportHeader:
|
||||
customer: str
|
||||
contractor: str
|
||||
contract_number: str
|
||||
contract_date: date | None
|
||||
currency: str
|
||||
period_from: date
|
||||
period_to: date
|
||||
system_name: str
|
||||
@@ -90,6 +92,8 @@ def build_ks6a_export_dto(project, rows, date_from: date, date_to: date, system_
|
||||
customer=project.customer if project and project.customer else "",
|
||||
contractor="",
|
||||
contract_number=project.contract_number if project and project.contract_number else "",
|
||||
contract_date=project.contract_date if project else None,
|
||||
currency=project.currency if project and project.currency else "",
|
||||
period_from=date_from,
|
||||
period_to=date_to,
|
||||
system_name=system_name or "",
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
import io
|
||||
|
||||
from docx import Document
|
||||
from docx.shared import Pt, Cm
|
||||
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
||||
from docx.enum.section import WD_ORIENT
|
||||
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 MONEY_TEXT, QTY_TEXT, format_period, project_requisite_lines
|
||||
from app.exporters.ks2_dto import KS2ExportDocument
|
||||
|
||||
|
||||
@@ -13,6 +15,10 @@ def render_ks2_word(doc: KS2ExportDocument) -> bytes:
|
||||
d = Document()
|
||||
h = doc.header
|
||||
|
||||
section = d.sections[0]
|
||||
section.orientation = WD_ORIENT.LANDSCAPE
|
||||
section.page_width, section.page_height = section.page_height, section.page_width
|
||||
|
||||
# Title
|
||||
title = d.add_paragraph()
|
||||
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
@@ -22,17 +28,15 @@ def render_ks2_word(doc: KS2ExportDocument) -> bytes:
|
||||
|
||||
d.add_paragraph()
|
||||
|
||||
# Header block
|
||||
header_lines = [
|
||||
("Проект:", h.project_name),
|
||||
("Заказчик:", h.customer),
|
||||
("Договор:", h.contract_number),
|
||||
]
|
||||
if h.period_from and h.period_to:
|
||||
header_lines.append(("Период:", f"{h.period_from.strftime('%d.%m.%Y')} — {h.period_to.strftime('%d.%m.%Y')}"))
|
||||
if h.comment:
|
||||
header_lines.append(("Комментарий:", h.comment))
|
||||
|
||||
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=[("Комментарий:", h.comment)],
|
||||
)
|
||||
for label, value in header_lines:
|
||||
p = d.add_paragraph()
|
||||
run = p.add_run(label + " ")
|
||||
@@ -61,9 +65,9 @@ def render_ks2_word(doc: KS2ExportDocument) -> bytes:
|
||||
row.cells[1].text = item.name
|
||||
row.cells[2].text = item.source_number
|
||||
row.cells[3].text = item.unit
|
||||
row.cells[4].text = f"{item.quantity:.4f}"
|
||||
row.cells[5].text = f"{item.unit_price:.2f}"
|
||||
row.cells[6].text = f"{item.amount:.2f}"
|
||||
row.cells[4].text = QTY_TEXT.format(item.quantity)
|
||||
row.cells[5].text = MONEY_TEXT.format(item.unit_price)
|
||||
row.cells[6].text = MONEY_TEXT.format(item.amount)
|
||||
|
||||
# Total row
|
||||
total_row = table.add_row()
|
||||
@@ -73,7 +77,7 @@ def render_ks2_word(doc: KS2ExportDocument) -> bytes:
|
||||
paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT
|
||||
for run in paragraph.runs:
|
||||
run.bold = True
|
||||
total_row.cells[6].text = f"{doc.total:.2f}"
|
||||
total_row.cells[6].text = MONEY_TEXT.format(doc.total)
|
||||
for paragraph in total_row.cells[6].paragraphs:
|
||||
for run in paragraph.runs:
|
||||
run.bold = True
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
import io
|
||||
|
||||
from docx import Document
|
||||
from docx.shared import Pt
|
||||
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
||||
from docx.enum.section import WD_ORIENT
|
||||
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 MONEY_TEXT, format_date, format_period, project_requisite_lines
|
||||
from app.exporters.ks3_dto import KS3ExportDocument
|
||||
|
||||
|
||||
@@ -13,26 +15,28 @@ def render_ks3_word(doc: KS3ExportDocument) -> bytes:
|
||||
d = Document()
|
||||
h = doc.header
|
||||
|
||||
section = d.sections[0]
|
||||
section.orientation = WD_ORIENT.LANDSCAPE
|
||||
section.page_width, section.page_height = section.page_height, section.page_width
|
||||
|
||||
# Title
|
||||
title = d.add_paragraph()
|
||||
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
run = title.add_run(f"КС-3 №{h.ks3_number} от {h.ks3_date.strftime('%d.%m.%Y')}")
|
||||
run = title.add_run(f"Акт КС-3 №{h.ks3_number} от {h.ks3_date.strftime('%d.%m.%Y')}")
|
||||
run.bold = True
|
||||
run.font.size = Pt(14)
|
||||
|
||||
d.add_paragraph()
|
||||
|
||||
# Header block
|
||||
header_lines = [
|
||||
("Проект:", h.project_name),
|
||||
("Заказчик:", h.customer),
|
||||
("Договор:", h.contract_number),
|
||||
]
|
||||
if h.period_from and h.period_to:
|
||||
header_lines.append(("Период:", f"{h.period_from.strftime('%d.%m.%Y')} — {h.period_to.strftime('%d.%m.%Y')}"))
|
||||
if h.comment:
|
||||
header_lines.append(("Комментарий:", h.comment))
|
||||
|
||||
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=[("Комментарий:", h.comment)],
|
||||
)
|
||||
for label, value in header_lines:
|
||||
p = d.add_paragraph()
|
||||
run = p.add_run(label + " ")
|
||||
@@ -59,12 +63,9 @@ def render_ks3_word(doc: KS3ExportDocument) -> bytes:
|
||||
row = table.add_row()
|
||||
row.cells[0].text = str(item.row_number)
|
||||
row.cells[1].text = f"№{item.ks2_number}"
|
||||
row.cells[2].text = item.ks2_date.strftime('%d.%m.%Y') if item.ks2_date else ""
|
||||
period_text = ""
|
||||
if item.period_from and item.period_to:
|
||||
period_text = f"{item.period_from.strftime('%d.%m.%Y')} — {item.period_to.strftime('%d.%m.%Y')}"
|
||||
row.cells[3].text = period_text
|
||||
row.cells[4].text = f"{item.amount:.2f}"
|
||||
row.cells[2].text = format_date(item.ks2_date)
|
||||
row.cells[3].text = format_period(item.period_from, item.period_to)
|
||||
row.cells[4].text = MONEY_TEXT.format(item.amount)
|
||||
|
||||
# Total row
|
||||
total_row = table.add_row()
|
||||
@@ -74,7 +75,7 @@ def render_ks3_word(doc: KS3ExportDocument) -> bytes:
|
||||
paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT
|
||||
for run in paragraph.runs:
|
||||
run.bold = True
|
||||
total_row.cells[4].text = f"{doc.total:.2f}"
|
||||
total_row.cells[4].text = MONEY_TEXT.format(doc.total)
|
||||
for paragraph in total_row.cells[4].paragraphs:
|
||||
for run in paragraph.runs:
|
||||
run.bold = True
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user