From f469040e12816580f1a8fbd60cedc6597e2c2648 Mon Sep 17 00:00:00 2001 From: Jax Date: Sat, 30 Nov 2024 21:56:39 +0800 Subject: [PATCH] Bump 0.1.12 --- CHANGELOG.md | 5 ++++ pyproject.toml | 2 +- src/bagels/components/modules/records.py | 34 +++++++++++++++++++++++- src/bagels/modals/transfer.py | 14 +++++++--- uv.lock | 2 +- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1423a..023c2ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.1.12 + +- Added total amount in persons view +- Fix: Transfers not using active date + ## 0.1.11 - Add transfers as templates. diff --git a/pyproject.toml b/pyproject.toml index 48baa01..53680ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "Bagels" -version = "0.1.11" +version = "0.1.12" authors = [ { name = "Jax", email = "enhancedjax@gmail.com" } ] diff --git a/src/bagels/components/modules/records.py b/src/bagels/components/modules/records.py index 977d586..f4a2565 100644 --- a/src/bagels/components/modules/records.py +++ b/src/bagels/components/modules/records.py @@ -292,6 +292,7 @@ def _build_person_view(self, table: DataTable, _) -> None: ) # Add splits for this person + total_unpaid = 0 # Initialize total unpaid amount for this person for split in person.splits: record = split.record paid_icon = ( @@ -306,6 +307,14 @@ def _build_person_view(self, table: DataTable, _) -> None: ) record_date = format_date_to_readable(record.date) category = f"[{record.category.color.lower()}]{CONFIG.symbols.category_color}[/{record.category.color.lower()}] {record.category.name}" + + # Calculate amount and update total of unpaid amounts + if not split.isPaid: + split_amount = split.amount + if record.isIncome: + split_amount = -split_amount # Negate income amounts + total_unpaid += split_amount + amount = ( f"[red]{CONFIG.symbols.amount_negative}[/red] {split.amount}" if record.isIncome @@ -323,6 +332,23 @@ def _build_person_view(self, table: DataTable, _) -> None: key=f"s-{split.id}", ) + # Add total row for this person showing unpaid amount. We reverse the color indicator. + if total_unpaid == 0: + total_display = "0.0" + elif total_unpaid < 0: + total_display = f"[green]{abs(total_unpaid)}[/green]" + else: + total_display = f"[red]{abs(total_unpaid)}[/red]" + table.add_row( + " ", + "[bold]Total Unpaid[/bold]", + "", + "", + f"[bold]{total_display}[/bold]", + "", + key=f"t-{str(person.id)}", + ) + # region Helpers # -------------- Helpers ------------- # @@ -615,7 +641,13 @@ def check_result(result) -> None: timeout=3, ) - self.app.push_screen(TransferModal(title="New transfer"), callback=check_result) + self.app.push_screen( + TransferModal( + title="New transfer", + defaultDate=self.page_parent.mode["date"].strftime("%d"), + ), + callback=check_result, + ) # region View # --------------- View --------------- # diff --git a/src/bagels/modals/transfer.py b/src/bagels/modals/transfer.py index bb5613f..3eeb7e2 100644 --- a/src/bagels/modals/transfer.py +++ b/src/bagels/modals/transfer.py @@ -48,7 +48,15 @@ def __init__(self, accounts, initial_id: int = 0, type: str = "", *args, **kwarg class TransferModal(ModalScreen): - def __init__(self, title="", record=None, isTemplate=False, *args, **kwargs): + def __init__( + self, + title="", + record=None, + isTemplate=False, + defaultDate=datetime.now().strftime("%d"), + *args, + **kwargs, + ): super().__init__(classes="modal-screen", *args, **kwargs) self.accounts = get_all_accounts_with_balance(get_hidden=True) self.form = Form( @@ -80,9 +88,7 @@ def __init__(self, title="", record=None, isTemplate=False, *args, **kwargs): type="dateAutoDay", placeholder="dd (mm) (yy)", default_value=( - record.date.strftime("%d") - if record - else datetime.now().strftime("%d") + record.date.strftime("%d") if record else defaultDate ), ) ) diff --git a/uv.lock b/uv.lock index fe4b789..b8acc03 100644 --- a/uv.lock +++ b/uv.lock @@ -86,7 +86,7 @@ wheels = [ [[package]] name = "bagels" -version = "0.1.11" +version = "0.1.12" source = { editable = "." } dependencies = [ { name = "aiohappyeyeballs" },