Skip to content

Commit

Permalink
Merge pull request #12 from EnhancedJax/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
EnhancedJax authored Nov 30, 2024
2 parents ccefe62 + f469040 commit d72d7fb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "Bagels"
version = "0.1.11"
version = "0.1.12"
authors = [
{ name = "Jax", email = "enhancedjax@gmail.com" }
]
Expand Down Expand Up @@ -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",
Expand Down
34 changes: 33 additions & 1 deletion src/bagels/components/modules/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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
Expand All @@ -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 ------------- #

Expand Down Expand Up @@ -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 --------------- #
Expand Down
14 changes: 10 additions & 4 deletions src/bagels/modals/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
),
)
)
Expand Down
6 changes: 1 addition & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d72d7fb

Please sign in to comment.