mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-01-25 14:09:16 -06:00
- Add data models: - Reporting: SavedReportView, ReportEmailSchedule - Currency/FX: Currency, ExchangeRate - Tax: TaxRule (flexible rules with date ranges; client/project scoping) - Invoices: InvoiceTemplate, Payment, CreditNote, InvoiceReminderSchedule - Extend Invoice: - Add currency_code and template_id - Add relationships: payments, credits, reminder_schedules - Compute outstanding by subtracting credits; helper to apply matching TaxRule - Register new models in app/models/__init__.py - DB: add Alembic migration 017 to create new tables and alter invoices Notes: - Requires database migration (alembic upgrade head). - Follow-ups: FX fetching + scheduler, report builder UI/CRUD, utilization dashboard, email schedules/reminders, invoice themes in UI, partial payments and credit notes in routes/templates
45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from datetime import datetime
|
|
from app import db
|
|
|
|
|
|
class Currency(db.Model):
|
|
"""Supported currencies and display metadata."""
|
|
|
|
__tablename__ = 'currencies'
|
|
|
|
code = db.Column(db.String(3), primary_key=True) # e.g., EUR, USD
|
|
name = db.Column(db.String(64), nullable=False)
|
|
symbol = db.Column(db.String(8), nullable=True) # e.g., €, $
|
|
decimal_places = db.Column(db.Integer, default=2, nullable=False)
|
|
is_active = db.Column(db.Boolean, default=True, nullable=False)
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
def __repr__(self):
|
|
return f"<Currency {self.code}>"
|
|
|
|
|
|
class ExchangeRate(db.Model):
|
|
"""Daily exchange rates between currency pairs."""
|
|
|
|
__tablename__ = 'exchange_rates'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
base_code = db.Column(db.String(3), db.ForeignKey('currencies.code'), nullable=False, index=True)
|
|
quote_code = db.Column(db.String(3), db.ForeignKey('currencies.code'), nullable=False, index=True)
|
|
rate = db.Column(db.Numeric(18, 8), nullable=False)
|
|
date = db.Column(db.Date, nullable=False, index=True)
|
|
source = db.Column(db.String(50), nullable=True) # e.g., ECB, exchangerate.host
|
|
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint('base_code', 'quote_code', 'date', name='uq_exchange_rate_day'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<ExchangeRate {self.base_code}/{self.quote_code} {self.date} {self.rate}>"
|
|
|
|
|