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.
This commit is contained in:
google-labs-jules[bot] 2025-06-01 08:39:04 +00:00 committed by mohamad
parent 136c4df7ac
commit 3811dc7ee5
2 changed files with 5 additions and 5 deletions

View File

@ -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
# Financials & Cost Splitting specific errors

View File

@ -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