mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-08-08 10:01:14 +03:00
fix: delete button now shows for all transactions; reverse resident hours on transaction deletion
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user