Refactor domain_utils.py overlap helpers, add ONE_DAY constant, remove inflated comments, and standardize _add_row() calls
This commit is contained in:
@@ -71,6 +71,32 @@ Two sources with shared patterns:
|
||||
- **comdirect**: `ComdirectGiro`, `ComdirectCreditCard`, `ComdirectDepot`, import to `comdirect_giro` table
|
||||
- **unified**: `Transaction`, `TransactionDb` – both ingest pipelines project their staging rows (`import_b4w`, `comdirect_giro`) into one `transactions` table via `src/ingest/transactions.py` (`map_*` mappers + `consolidate_transactions`). Dedup uses a business-key `hash_id` (source + IBAN + value date + amount + text + counterparty) with a UNIQUE constraint and SQLite `INSERT OR IGNORE`, so re-imports are idempotent. Amounts are canonical signed (negative = money out). Depot/credit-card/tagesgeld are not projected yet.
|
||||
|
||||
## Category Budget Management (NEW)
|
||||
|
||||
Budget tracking for categories with time-bounded or unbounded periods:
|
||||
|
||||
```python
|
||||
from src.models.category import Category, CategoryBudget
|
||||
from datetime import date
|
||||
|
||||
cat = Category(name="Lebenshaltung")
|
||||
budget = CategoryBudget(
|
||||
category=cat,
|
||||
amount_eur=150.00,
|
||||
valid_from=date(2026, 10, 1), # Optional: None for unbounded start
|
||||
valid_to=date(2026, 11, 30), # Optional: None for unbounded end
|
||||
)
|
||||
|
||||
# Set/replace budget - handles overlap automatically:
|
||||
from src.domain_utils import set_category_budget
|
||||
set_category_budget(db_session, budget)
|
||||
```
|
||||
|
||||
The `set_category_budget()` function intelligently handles three scenarios:
|
||||
1. **No overlap**: Adds new budget alongside existing ones
|
||||
2. **Partial overlap**: Splits existing budget into non-overlapping parts + adds new budget
|
||||
3. **Full overlap**: Replaces existing budget entirely
|
||||
|
||||
All models inherit from common base in `src/models/common.py`:
|
||||
- `_hash()`: SHA256-based deduplication key
|
||||
- `_parse_date_german()`: Handles "07.09.2026" format and values like "offen", "--"
|
||||
|
||||
Reference in New Issue
Block a user