get_version() now returns version.name instead of str(version), which returned the numeric ID from redminelib.resources.Version. Falls back to str() when .name is absent (#14). Add issue.id as tertiary sort key in build_grouped_report so tasks within the same project+version group always appear in the same order regardless of API response ordering (#33). Remove redundant sort from client.fetch_issues_with_spent_time — the sort already runs in report_builder.build_grouped_report, so doing it twice wastes CPU. Also remove the now-unused get_version import (#32). Closes #14, closes #32, closes #33
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
|
|
def get_month_name_from_range(from_date: str, to_date: str) -> str:
|
|
"""Определяет название месяца по диапазону дат"""
|
|
|
|
try:
|
|
end = datetime.strptime(to_date, "%Y-%m-%d")
|
|
except ValueError:
|
|
return "Январь"
|
|
|
|
months = [
|
|
"",
|
|
"Январь",
|
|
"Февраль",
|
|
"Март",
|
|
"Апрель",
|
|
"Май",
|
|
"Июнь",
|
|
"Июль",
|
|
"Август",
|
|
"Сентябрь",
|
|
"Октябрь",
|
|
"Ноябрь",
|
|
"Декабрь",
|
|
]
|
|
|
|
return months[end.month]
|
|
|
|
|
|
def get_version(issue) -> str:
|
|
"""Возвращает версию задачи или '<N/A>', если не задана."""
|
|
version = getattr(issue, "fixed_version", None)
|
|
if version is None:
|
|
return "<N/A>"
|
|
name = getattr(version, "name", None)
|
|
return str(name) if name else str(version)
|
|
|
|
|
|
def hours_to_human(hours: float) -> str:
|
|
"""Преобразует часы в человекочитаемый формат: '2ч 30м'."""
|
|
|
|
if hours <= 0:
|
|
return "0ч"
|
|
|
|
total_minutes = round(hours * 60)
|
|
h = total_minutes // 60
|
|
m = total_minutes % 60
|
|
parts = []
|
|
|
|
if h:
|
|
parts.append(f"{h}ч")
|
|
if m:
|
|
parts.append(f"{m}м")
|
|
|
|
return " ".join(parts) if parts else "0ч"
|