Skip to content

Commit

Permalink
Bump 0.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
EnhancedJax committed Nov 30, 2024
1 parent 272ee65 commit f469040
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 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
2 changes: 1 addition & 1 deletion 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
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
2 changes: 1 addition & 1 deletion uv.lock

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

0 comments on commit f469040

Please sign in to comment.