From 272ee657d62ea952899006613d0ab2cbc388f13d Mon Sep 17 00:00:00 2001 From: Jax Date: Fri, 22 Nov 2024 12:09:51 +0800 Subject: [PATCH 1/2] Removed dev depency --- pyproject.toml | 2 -- uv.lock | 4 ---- 2 files changed, 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d079e39..48baa01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,11 +38,9 @@ dependencies = [ "pydantic-settings>=2.6.1", "pydantic==2.9.2", "pygments==2.18.0", - "pytest-textual-snapshot>=1.0.0", "pyyaml==6.0.2", "rich==13.9.3", "sqlalchemy==2.0.36", - "textual-dev==1.6.1", "textual>=0.86.1", "tomli>=2.0.2", "typing-extensions==4.12.2", diff --git a/uv.lock b/uv.lock index aa38986..fe4b789 100644 --- a/uv.lock +++ b/uv.lock @@ -117,12 +117,10 @@ dependencies = [ { name = "pydantic-settings" }, { name = "pydantic-settings-yaml" }, { name = "pygments" }, - { name = "pytest-textual-snapshot" }, { name = "pyyaml" }, { name = "rich" }, { name = "sqlalchemy" }, { name = "textual" }, - { name = "textual-dev" }, { name = "tomli" }, { name = "typing-extensions" }, { name = "uc-micro-py" }, @@ -172,12 +170,10 @@ requires-dist = [ { name = "pydantic-settings", specifier = ">=2.6.1" }, { name = "pydantic-settings-yaml", specifier = ">=0.2.0" }, { name = "pygments", specifier = "==2.18.0" }, - { name = "pytest-textual-snapshot", specifier = ">=1.0.0" }, { name = "pyyaml", specifier = "==6.0.2" }, { name = "rich", specifier = "==13.9.3" }, { name = "sqlalchemy", specifier = "==2.0.36" }, { name = "textual", specifier = ">=0.86.1" }, - { name = "textual-dev", specifier = "==1.6.1" }, { name = "tomli", specifier = ">=2.0.2" }, { name = "typing-extensions", specifier = "==4.12.2" }, { name = "uc-micro-py", specifier = "==1.0.3" }, From f469040e12816580f1a8fbd60cedc6597e2c2648 Mon Sep 17 00:00:00 2001 From: Jax Date: Sat, 30 Nov 2024 21:56:39 +0800 Subject: [PATCH 2/2] 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" },