Add attachment support for fuel and recurring expenses with camera capture
Co-authored-by: aiulian25 <17886483+aiulian25@users.noreply.github.com>
This commit is contained in:
parent
339cd94b26
commit
8a5b916a39
8 changed files with 487 additions and 9 deletions
|
|
@ -505,7 +505,8 @@ def fuel_records(vehicle_id):
|
|||
'distance': r.distance,
|
||||
'fuel_economy': r.fuel_economy,
|
||||
'unit': r.unit,
|
||||
'notes': r.notes
|
||||
'notes': r.notes,
|
||||
'document_path': r.document_path
|
||||
} for r in records]), 200
|
||||
|
||||
elif request.method == 'POST':
|
||||
|
|
@ -625,7 +626,8 @@ def recurring_expenses(vehicle_id):
|
|||
'start_date': e.start_date.isoformat(),
|
||||
'next_due_date': e.next_due_date.isoformat(),
|
||||
'is_active': e.is_active,
|
||||
'notes': e.notes
|
||||
'notes': e.notes,
|
||||
'document_path': e.document_path
|
||||
} for e in expenses]), 200
|
||||
|
||||
elif request.method == 'POST':
|
||||
|
|
@ -651,7 +653,8 @@ def recurring_expenses(vehicle_id):
|
|||
frequency=frequency,
|
||||
start_date=start_date,
|
||||
next_due_date=next_due,
|
||||
notes=data.get('notes')
|
||||
notes=data.get('notes'),
|
||||
document_path=data.get('document_path')
|
||||
)
|
||||
|
||||
db.session.add(expense)
|
||||
|
|
@ -847,7 +850,8 @@ def fuel_record_operations(vehicle_id, record_id):
|
|||
'odometer': record.odometer,
|
||||
'fuel_amount': record.fuel_amount,
|
||||
'cost': record.cost,
|
||||
'notes': record.notes or ''
|
||||
'notes': record.notes or '',
|
||||
'document_path': record.document_path or ''
|
||||
})
|
||||
|
||||
elif request.method == 'PUT':
|
||||
|
|
@ -857,6 +861,7 @@ def fuel_record_operations(vehicle_id, record_id):
|
|||
record.fuel_amount = data.get('fuel_amount', record.fuel_amount)
|
||||
record.cost = data.get('cost', record.cost)
|
||||
record.notes = data.get('notes', record.notes)
|
||||
record.document_path = data.get('document_path', record.document_path)
|
||||
db.session.commit()
|
||||
return jsonify({'message': 'Fuel record updated successfully'})
|
||||
|
||||
|
|
|
|||
75
backend/migrate_attachments.py
Normal file
75
backend/migrate_attachments.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Database migration script to add document_path columns to FuelRecord and RecurringExpense tables.
|
||||
This migration adds support for file attachments to fuel and tax (recurring expense) entries.
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
import sys
|
||||
|
||||
def migrate_database():
|
||||
"""Add document_path columns to FuelRecord and RecurringExpense tables."""
|
||||
# Support both Docker and local paths
|
||||
db_paths = [
|
||||
'/app/data/masina_dock.db',
|
||||
'./data/masina_dock.db',
|
||||
'../data/masina_dock.db'
|
||||
]
|
||||
|
||||
db_path = None
|
||||
for path in db_paths:
|
||||
if os.path.exists(path):
|
||||
db_path = path
|
||||
break
|
||||
|
||||
if not db_path:
|
||||
print("Database does not exist yet. Migration will be applied on first run.")
|
||||
return True
|
||||
|
||||
print(f"Migrating database at: {db_path}")
|
||||
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check FuelRecord table
|
||||
cursor.execute("PRAGMA table_info(fuel_record)")
|
||||
fuel_columns = [column[1] for column in cursor.fetchall()]
|
||||
|
||||
if 'document_path' not in fuel_columns:
|
||||
print("Adding document_path column to fuel_record table...")
|
||||
cursor.execute("ALTER TABLE fuel_record ADD COLUMN document_path VARCHAR(255)")
|
||||
print("✓ Added document_path to fuel_record")
|
||||
else:
|
||||
print("✓ fuel_record.document_path already exists")
|
||||
|
||||
# Check RecurringExpense table
|
||||
cursor.execute("PRAGMA table_info(recurring_expense)")
|
||||
expense_columns = [column[1] for column in cursor.fetchall()]
|
||||
|
||||
if 'document_path' not in expense_columns:
|
||||
print("Adding document_path column to recurring_expense table...")
|
||||
cursor.execute("ALTER TABLE recurring_expense ADD COLUMN document_path VARCHAR(255)")
|
||||
print("✓ Added document_path to recurring_expense")
|
||||
else:
|
||||
print("✓ recurring_expense.document_path already exists")
|
||||
|
||||
conn.commit()
|
||||
print("\n✓ Database migration completed successfully!")
|
||||
return True
|
||||
|
||||
except sqlite3.Error as e:
|
||||
print(f"✗ Migration error: {e}", file=sys.stderr)
|
||||
if conn:
|
||||
conn.rollback()
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"✗ Unexpected error: {e}", file=sys.stderr)
|
||||
return False
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
success = migrate_database()
|
||||
sys.exit(0 if success else 1)
|
||||
|
|
@ -111,6 +111,7 @@ class FuelRecord(db.Model):
|
|||
fuel_economy = db.Column(db.Float)
|
||||
unit = db.Column(db.String(20), default='MPG')
|
||||
notes = db.Column(db.Text)
|
||||
document_path = db.Column(db.String(255))
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
class Reminder(db.Model):
|
||||
|
|
@ -151,3 +152,4 @@ class RecurringExpense(db.Model):
|
|||
is_active = db.Column(db.Boolean, default=True)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
notes = db.Column(db.Text)
|
||||
document_path = db.Column(db.String(255))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue