mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-01-08 04:30:20 -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
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
from datetime import datetime
|
|
from app import db
|
|
|
|
|
|
class SavedReportView(db.Model):
|
|
"""Saved configurations for the custom report builder."""
|
|
|
|
__tablename__ = 'saved_report_views'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(120), nullable=False)
|
|
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)
|
|
scope = db.Column(db.String(20), default='private', nullable=False) # private, team, public
|
|
config_json = db.Column(db.Text, nullable=False) # JSON for filters, columns, groupings
|
|
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"<SavedReportView {self.name} ({self.scope})>"
|
|
|
|
|
|
class ReportEmailSchedule(db.Model):
|
|
"""Schedules to email saved reports on a cadence."""
|
|
|
|
__tablename__ = 'report_email_schedules'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
saved_view_id = db.Column(db.Integer, db.ForeignKey('saved_report_views.id'), nullable=False, index=True)
|
|
recipients = db.Column(db.Text, nullable=False) # comma-separated
|
|
cadence = db.Column(db.String(20), nullable=False) # daily, weekly, monthly, custom-cron
|
|
cron = db.Column(db.String(120), nullable=True)
|
|
timezone = db.Column(db.String(50), nullable=True)
|
|
next_run_at = db.Column(db.DateTime, nullable=True)
|
|
last_run_at = db.Column(db.DateTime, nullable=True)
|
|
active = db.Column(db.Boolean, default=True, nullable=False)
|
|
created_by = db.Column(db.Integer, db.ForeignKey('users.id'), 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"<ReportEmailSchedule view={self.saved_view_id} cadence={self.cadence}>"
|
|
|
|
|