mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 10:25:29 +03:00
update
This commit is contained in:
@@ -20,6 +20,10 @@ from dutylog.infrastructure.database.repositories.floors_repository import (
|
||||
from dutylog.infrastructure.database.repositories.users_repository import (
|
||||
UsersRepository,
|
||||
)
|
||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import (
|
||||
HoursTransactionsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.utils.datetime import msk_now
|
||||
|
||||
|
||||
@inject
|
||||
@@ -546,6 +550,58 @@ async def on_search_resident_selected(
|
||||
await dialog_manager.switch_to(AdminMenuSG.resident_info)
|
||||
|
||||
|
||||
@inject
|
||||
async def get_resident_history_data(
|
||||
dialog_manager: DialogManager,
|
||||
residents_repository: FromDishka[ResidentsRepository],
|
||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||
**kwargs,
|
||||
):
|
||||
resident_id = dialog_manager.dialog_data.get("selected_resident_id")
|
||||
|
||||
if not resident_id:
|
||||
return {"history_content": "Ошибка: резидент не выбран"}
|
||||
|
||||
resident = await residents_repository.get_resident_by_id(resident_id)
|
||||
|
||||
if not resident:
|
||||
return {"history_content": "Ошибка: резидент не найден"}
|
||||
|
||||
transactions = await transactions_repository.get_resident_history(resident_id)
|
||||
transactions_sorted = sorted(transactions, key=lambda x: x.created_at)
|
||||
last_10 = transactions_sorted[-10:]
|
||||
|
||||
resident_name = resident.real_name if resident.real_name else "Без имени"
|
||||
|
||||
if not last_10:
|
||||
history_text = f"""
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
|
||||
<b>Резидент:</b> {resident_name}
|
||||
|
||||
<i>История операций пуста</i>
|
||||
"""
|
||||
else:
|
||||
history_text = f"""
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
|
||||
<b>Резидент:</b> {resident_name}
|
||||
|
||||
"""
|
||||
for tx in last_10:
|
||||
operation = "Начислено" if tx.transaction_type == "increase" else "Списано"
|
||||
emoji = "+" if tx.transaction_type == "increase" else "−"
|
||||
|
||||
msk_time = tx.created_at.astimezone(msk_now().tzinfo).replace(tzinfo=None)
|
||||
date_str = msk_time.strftime("%d.%m.%Y %H:%M")
|
||||
|
||||
remark_text = f"\n💬 <i>{tx.remark}</i>" if tx.remark else ""
|
||||
|
||||
history_text += f"<blockquote><b>{operation}</b> {emoji}<code>{tx.amount}</code> ч\n📅 {date_str}{remark_text}</blockquote>\n"
|
||||
|
||||
return {"history_content": history_text}
|
||||
|
||||
|
||||
residents_list_window = Window(
|
||||
Format("{content}"),
|
||||
Row(
|
||||
@@ -602,6 +658,12 @@ resident_info_window = Window(
|
||||
when=~F["is_admin"],
|
||||
),
|
||||
),
|
||||
Button(
|
||||
Const("📜 История"),
|
||||
id="resident_history_btn",
|
||||
on_click=lambda c, b, m: m.switch_to(AdminMenuSG.resident_history),
|
||||
when=~F["is_admin"],
|
||||
),
|
||||
Button(
|
||||
Const("🔄 Перепривязать к комнате"),
|
||||
id="rebind_resident_btn",
|
||||
@@ -850,3 +912,14 @@ resident_rebind_confirm_window = Window(
|
||||
state=AdminMenuSG.resident_rebind_confirm,
|
||||
getter=get_rebind_confirm_data,
|
||||
)
|
||||
|
||||
resident_history_window = Window(
|
||||
Format("{history_content}"),
|
||||
SwitchTo(
|
||||
Const("◀️ Назад"),
|
||||
id="back_to_resident_info",
|
||||
state=AdminMenuSG.resident_info,
|
||||
),
|
||||
state=AdminMenuSG.resident_history,
|
||||
getter=get_resident_history_data,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user