Skip to content

Conversation

@Arc891
Copy link
Owner

@Arc891 Arc891 commented Jul 24, 2025

Add Configurable Google Sheets Layout Support

Summary

This PR introduces configurable starting rows for Google Sheets transactions and cleans up the codebase by removing excessive debugging code that was added during troubleshooting.

Key Changes

  • 🔧 Configurable Sheet Layout: Added GSHEET_EXPENSE_START_ROW and GSHEET_INCOME_START_ROW settings to support different sheet structures
  • 🧹 Code Cleanup: Removed excessive logging and debugging code from background upload process
  • 🔗 Centralized Configuration: Moved sheet configuration from constants.py to config_settings.py
  • 🛡️ Input Sanitization: Added quote stripping for sheet names to prevent API errors
  • 🐛 Minor Fixes: Fixed typo in expense categories (ABBONEMENTEN → ABONNEMENTEN)

Configuration

Users can now customize where transaction data starts in their sheets:

GSHEET_EXPENSE_START_ROW = 5  # Start expense transactions at row 5
GSHEET_INCOME_START_ROW = 5   # Start income transactions at row 5

Impact

  • Supports various Google Sheets layouts (headers, instructions, etc.)
  • Cleaner, more maintainable codebase
  • Resolves APIError issues caused by quoted environment variables
  • Better separation of concerns in configuration management

Arc891 added 3 commits July 22, 2025 11:13
- Replace /export command with automatic background uploads
- Transactions now upload to Google Sheets immediately upon categorization
- Remove /export command and related UI completely
- Add robust row detection with safety checks to prevent overwrites
- Enhanced error handling and debug logging for uploads
…oad queue

Major refactoring to introduce comprehensive transaction caching and automatic Google Sheets upload:

🚀 Core Features:
- **Background Upload Queue**: Immediate transaction uploads with rate limiting and safety checks
- **Transaction Caching System**: "Cache for Later" feature with dummy uploads and row reservation
- **Unified Session Management**: Single source of truth for all user state per session file
- **Row Safety Checks**: Prevents data overwrites with collision detection and recovery

🔧 Infrastructure Changes:
- Remove /export command and legacy manual export logic
- Migrate from global sheet_positions.json to per-user session files
- Add robust row detection with empty sheet validation and cached position verification
- Implement immediate row reservation for cached transactions to prevent conflicts

🎯 User Experience:
- New /cached command to view and process deferred transactions
- Automatic transaction processing with smart categorization
- All UI buttons disabled after use to prevent duplicate actions
- Enhanced error handling and user feedback

🐛 Critical Fixes:
- Fix cached transaction replacement using correct reserved rows instead of next available
- Ensure cached transactions are immediately removed from session to prevent duplicates
- Preserve _reserved_row field through entire replacement workflow
- Enhanced logging for debugging cache and row operations

📁 File Changes:
- background_upload.py: Complete rewrite with queue system and safety checks
- session_management.py: Unified state management with caching support
- transaction_prompt.py: Enhanced UI with caching workflow
- cached_transactions_view.py: New dedicated UI for cached transaction management
- bot_commands.py: Add /cached command, remove /export
- constants.py: Add DUMMY_CACHED category for cache placeholders

✅ Tested and deployed successfully with Docker containerization
- Add GSHEET_NAME, GSHEET_TAB, and configurable starting rows to config
- Move sheet configuration from constants.py to config_settings.py
- Implement GSHEET_EXPENSE_START_ROW and GSHEET_INCOME_START_ROW support
- Remove backup files and clean up debugging code
- Fix typo: ABBONEMENTEN -> ABONNEMENTEN in expense categories
- Update session management to use configurable defaults
- Improve error handling in Google Sheets
@Arc891 Arc891 self-assigned this Jul 24, 2025
@Arc891 Arc891 requested a review from Copilot July 24, 2025 16:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive caching system for transaction categorization, allowing users to save transactions with dummy entries for later processing while maintaining their position in Google Sheets. Additionally, it adds configurable starting row positions for Google Sheets to support various sheet layouts.

  • New caching system: Users can cache transactions for later processing with dummy entries
  • Configurable sheet layout: Support for custom starting rows in Google Sheets through environment variables
  • Background upload queue: Automatic transaction uploads with proper rate limiting and row position management

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
transaction_prompt.py Adds cache button, cached transaction processing views, and auto-upload integration
cached_transactions_view.py New UI components for managing cached transactions
session_management.py Extended session data structure with caching and sheet position tracking
google_sheets.py Updated to use configurable sheet names from config instead of constants
background_upload.py New background queue system for automatic Google Sheets uploads with rate limiting
constants.py Fixed typo (ABBONEMENTEN → ABONNEMENTEN) and moved sheet config to config_settings
config_settings.example.py Added new configuration options for sheet layout and names
bot_commands.py Replaced export command with cached command, updated to reflect auto-upload
bot.py Added startup of background upload queue

Arc891 and others added 2 commits July 24, 2025 19:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Arc891 Arc891 merged commit 1d86c70 into main Jul 24, 2025
5 checks passed
@Arc891 Arc891 deleted the feat/auto-upload branch July 24, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants