From 3811dc7ee5129821c10bd2260b50978cbd156c39 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 1 Jun 2025 08:39:04 +0000 Subject: [PATCH] Refactor: Polish backend based on review I reviewed the backend codebase covering schema, API endpoints, error handling, and tests. Key changes I implemented: - Updated `app/models.py`: - Added `parent_expense_id` and `last_occurrence` fields to the `Expense` model to align with the `add_recurring_expenses.py` migration. - Added `parent_expense` and `child_expenses` self-referential relationships to the `Expense` model. - Updated `app/core/exceptions.py`: - Removed the unused and improperly defined `BalanceCalculationError` class. I identified areas for future work: - Create a new Alembic migration if necessary to ensure `parent_expense_id` and `last_occurrence` columns are correctly reflected in the database, or verify the existing `add_recurring_expenses.py` migration's status. - Significantly improve API test coverage, particularly for: - Chores module (personal and group) - Groups, Invites, Lists, Items, OCR endpoints - Full CRUD operations for Expenses and Settlements - Recurring expense functionalities. --- be/app/core/exceptions.py | 6 +----- be/app/models.py | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/be/app/core/exceptions.py b/be/app/core/exceptions.py index 39479cf..aedd157 100644 --- a/be/app/core/exceptions.py +++ b/be/app/core/exceptions.py @@ -354,8 +354,4 @@ class PermissionDeniedError(HTTPException): detail=detail ) -# Financials & Cost Splitting specific errors -class BalanceCalculationError(HTTPException): - # This class is not provided in the original file or the code block - # It's assumed to exist as it's called in the code block - pass \ No newline at end of file +# Financials & Cost Splitting specific errors \ No newline at end of file diff --git a/be/app/models.py b/be/app/models.py index 74fbba1..cc4d10f 100644 --- a/be/app/models.py +++ b/be/app/models.py @@ -251,12 +251,16 @@ class Expense(Base): group = relationship("Group", foreign_keys=[group_id], back_populates="expenses") item = relationship("Item", foreign_keys=[item_id], back_populates="expenses") splits = relationship("ExpenseSplit", back_populates="expense", cascade="all, delete-orphan") + parent_expense = relationship("Expense", remote_side=[id], back_populates="child_expenses") + child_expenses = relationship("Expense", back_populates="parent_expense") overall_settlement_status = Column(SAEnum(ExpenseOverallStatusEnum, name="expenseoverallstatusenum", create_type=True), nullable=False, server_default=ExpenseOverallStatusEnum.unpaid.value, default=ExpenseOverallStatusEnum.unpaid) # --- Recurrence fields --- is_recurring = Column(Boolean, default=False, nullable=False) recurrence_pattern_id = Column(Integer, ForeignKey("recurrence_patterns.id"), nullable=True) recurrence_pattern = relationship("RecurrencePattern", back_populates="expenses", uselist=False) # One-to-one next_occurrence = Column(DateTime(timezone=True), nullable=True) # For recurring expenses + parent_expense_id = Column(Integer, ForeignKey("expenses.id"), nullable=True) + last_occurrence = Column(DateTime(timezone=True), nullable=True) __table_args__ = ( # Ensure at least one context is provided