ODT: Group by project & versions
This commit is contained in:
@@ -9,25 +9,34 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
||||||
# Загружаем шаблон с альбомной ориентацией
|
|
||||||
template_path = "template.odt"
|
template_path = "template.odt"
|
||||||
# template_path = os.path.join(os.path.dirname(__file__), "..", "template.odt")
|
|
||||||
if not os.path.exists(template_path):
|
if not os.path.exists(template_path):
|
||||||
raise FileNotFoundError("Шаблон template.odt не найден. Создайте его вручную в LibreOffice (альбомная ориентация) и сохраните в корень проекта.")
|
raise FileNotFoundError("Шаблон template.odt не найден...")
|
||||||
|
|
||||||
doc = load(template_path)
|
doc = load(template_path)
|
||||||
|
para_style_name = "Standard"
|
||||||
|
|
||||||
# Стили уже есть в шаблоне — просто используем их по имени
|
# Заголовок
|
||||||
para_style_name = "Standard" # или другое имя, если вы задали стиль в шаблоне
|
|
||||||
table_style_name = "Table1" # LibreOffice обычно даёт такое имя
|
|
||||||
|
|
||||||
# Заголовок отчёта
|
|
||||||
header_text = "Кокос Артём Николаевич. Отчет за месяц Июль."
|
header_text = "Кокос Артём Николаевич. Отчет за месяц Июль."
|
||||||
header_paragraph = P(stylename=para_style_name, text=header_text)
|
header_paragraph = P(stylename=para_style_name, text=header_text)
|
||||||
doc.text.addElement(header_paragraph)
|
doc.text.addElement(header_paragraph)
|
||||||
|
|
||||||
# Таблица
|
# Группировка: project → version → [(issue, hours, status_ru)]
|
||||||
table = Table(name="Report", stylename=table_style_name)
|
projects = {}
|
||||||
|
for issue, hours in issue_hours:
|
||||||
|
project = str(issue.project)
|
||||||
|
version = get_version(issue)
|
||||||
|
status_en = str(issue.status)
|
||||||
|
status_ru = STATUS_TRANSLATION.get(status_en, status_en)
|
||||||
|
|
||||||
|
if project not in projects:
|
||||||
|
projects[project] = {}
|
||||||
|
if version not in projects[project]:
|
||||||
|
projects[project][version] = []
|
||||||
|
projects[project][version].append((issue, hours, status_ru))
|
||||||
|
|
||||||
|
# Создание таблицы
|
||||||
|
table = Table(name="Report")
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
table.addElement(TableColumn())
|
table.addElement(TableColumn())
|
||||||
|
|
||||||
@@ -41,34 +50,57 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
header_row.addElement(cell)
|
header_row.addElement(cell)
|
||||||
table.addElement(header_row)
|
table.addElement(header_row)
|
||||||
|
|
||||||
# Данные
|
# Данные: двухуровневая группировка
|
||||||
prev_project = None
|
for project, versions in projects.items():
|
||||||
prev_version = None
|
total_project_rows = sum(len(rows) for rows in versions.values())
|
||||||
for issue, hours in issue_hours:
|
first_version_in_project = True
|
||||||
project = str(issue.project)
|
|
||||||
version = get_version(issue)
|
|
||||||
status_en = str(issue.status)
|
|
||||||
status_ru = STATUS_TRANSLATION.get(status_en, status_en)
|
|
||||||
|
|
||||||
display_project = project if project != prev_project else ""
|
for version, rows in versions.items():
|
||||||
display_version = version if (project != prev_project or version != prev_version) else ""
|
row_span_version = len(rows)
|
||||||
|
first_row_in_version = True
|
||||||
|
|
||||||
row = TableRow()
|
for issue, hours, status_ru in rows:
|
||||||
cells_content = [
|
row = TableRow()
|
||||||
display_project,
|
|
||||||
display_version,
|
# Ячейка "Проект" — только в первой строке всего проекта
|
||||||
f"{issue.id}. {issue.subject}",
|
if first_version_in_project and first_row_in_version:
|
||||||
status_ru,
|
cell_project = TableCell()
|
||||||
"" # как в скриншоте
|
cell_project.setAttribute("numberrowsspanned", str(total_project_rows))
|
||||||
]
|
p = P(stylename=para_style_name, text=project)
|
||||||
for col_text in cells_content:
|
cell_project.addElement(p)
|
||||||
cell = TableCell()
|
row.addElement(cell_project)
|
||||||
p = P(stylename=para_style_name, text=col_text)
|
|
||||||
cell.addElement(p)
|
# Ячейка "Версия" — только в первой строке каждой версии
|
||||||
row.addElement(cell)
|
if first_row_in_version:
|
||||||
table.addElement(row)
|
cell_version = TableCell()
|
||||||
prev_project = project
|
cell_version.setAttribute("numberrowsspanned", str(row_span_version))
|
||||||
prev_version = version
|
p = P(stylename=para_style_name, text=version)
|
||||||
|
cell_version.addElement(p)
|
||||||
|
row.addElement(cell_version)
|
||||||
|
first_row_in_version = False
|
||||||
|
else:
|
||||||
|
# Пропускаем — уже объединена
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Остальные колонки
|
||||||
|
task_cell = TableCell()
|
||||||
|
p = P(stylename=para_style_name, text=f"{issue.id}. {issue.subject}")
|
||||||
|
task_cell.addElement(p)
|
||||||
|
row.addElement(task_cell)
|
||||||
|
|
||||||
|
status_cell = TableCell()
|
||||||
|
p = P(stylename=para_style_name, text=status_ru)
|
||||||
|
status_cell.addElement(p)
|
||||||
|
row.addElement(status_cell)
|
||||||
|
|
||||||
|
time_cell = TableCell()
|
||||||
|
p = P(stylename=para_style_name, text=hours_to_human(hours))
|
||||||
|
time_cell.addElement(p)
|
||||||
|
row.addElement(time_cell)
|
||||||
|
|
||||||
|
table.addElement(row)
|
||||||
|
|
||||||
|
first_version_in_project = False
|
||||||
|
|
||||||
doc.text.addElement(table)
|
doc.text.addElement(table)
|
||||||
return doc
|
return doc
|
||||||
|
|||||||
Reference in New Issue
Block a user