fix: delete button now shows for all transactions; reverse resident hours on transaction deletion

This commit is contained in:
2026-07-15 01:43:17 +03:00
parent f9d65b159a
commit f775a34885
2 changed files with 18 additions and 1 deletions
@@ -230,7 +230,7 @@ transactions_history_window = Window(
) )
transactions_history_detail_window = Window( transactions_history_detail_window = Window(
DynamicMedia("photo_media"), DynamicMedia("photo_media", when=F["photo_media"]),
Format("{detail_content}", when=F["detail_content"]), Format("{detail_content}", when=F["detail_content"]),
Row( Row(
Button( Button(
@@ -145,6 +145,23 @@ class HoursTransactionsRepository:
return await self.transactions_dao.get_by_id(transaction_id) return await self.transactions_dao.get_by_id(transaction_id)
async def delete_transaction(self, transaction_id: int) -> None: 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) await self.transactions_dao.delete(transaction_id)
async def get_by_period(self, start_date, end_date) -> list[HoursTransaction]: async def get_by_period(self, start_date, end_date) -> list[HoursTransaction]: