From f775a34885012791a300136ba27843817feab810 Mon Sep 17 00:00:00 2001 From: kolo Date: Wed, 15 Jul 2026 01:43:17 +0300 Subject: [PATCH] fix: delete button now shows for all transactions; reverse resident hours on transaction deletion --- .../bot/creator_dialogs/transactions_history.py | 2 +- .../hours_transactions_repository.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/dutylog/application/bot/creator_dialogs/transactions_history.py b/src/dutylog/application/bot/creator_dialogs/transactions_history.py index 0403ed7..e615803 100644 --- a/src/dutylog/application/bot/creator_dialogs/transactions_history.py +++ b/src/dutylog/application/bot/creator_dialogs/transactions_history.py @@ -230,7 +230,7 @@ transactions_history_window = Window( ) transactions_history_detail_window = Window( - DynamicMedia("photo_media"), + DynamicMedia("photo_media", when=F["photo_media"]), Format("{detail_content}", when=F["detail_content"]), Row( Button( diff --git a/src/dutylog/infrastructure/database/repositories/hours_transactions_repository.py b/src/dutylog/infrastructure/database/repositories/hours_transactions_repository.py index 711aea7..a00ddc0 100644 --- a/src/dutylog/infrastructure/database/repositories/hours_transactions_repository.py +++ b/src/dutylog/infrastructure/database/repositories/hours_transactions_repository.py @@ -145,6 +145,23 @@ class HoursTransactionsRepository: return await self.transactions_dao.get_by_id(transaction_id) async def delete_transaction(self, transaction_id: int) -> None: + tx = await self.transactions_dao.get_by_id(transaction_id) + if tx: + resident = await self.residents_dao.get_by_id(tx.resident_id) + if resident: + if tx.transaction_type == TransactionType.INCREASE.value: + new_active = max(0, resident.active_hours - tx.amount) + await self.residents_dao.update( + tx.resident_id, active_hours=new_active + ) + elif tx.transaction_type == TransactionType.DECREASE.value: + new_active = resident.active_hours + tx.amount + new_inactive = max(0, resident.inactive_hours - tx.amount) + await self.residents_dao.update( + tx.resident_id, + active_hours=new_active, + inactive_hours=new_inactive, + ) await self.transactions_dao.delete(transaction_id) async def get_by_period(self, start_date, end_date) -> list[HoursTransaction]: