mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-04-27 16:02:42 -05:00
db82068dfd
- 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
62 lines
2.7 KiB
Python
62 lines
2.7 KiB
Python
from datetime import datetime
|
|
from app import db
|
|
|
|
|
|
class Payment(db.Model):
|
|
"""Partial/full payments recorded against invoices."""
|
|
|
|
__tablename__ = 'payments'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
invoice_id = db.Column(db.Integer, db.ForeignKey('invoices.id'), nullable=False, index=True)
|
|
amount = db.Column(db.Numeric(10, 2), nullable=False)
|
|
currency = db.Column(db.String(3), nullable=True) # If multi-currency per payment
|
|
payment_date = db.Column(db.Date, nullable=False, default=datetime.utcnow)
|
|
method = db.Column(db.String(50), nullable=True)
|
|
reference = db.Column(db.String(100), nullable=True)
|
|
notes = db.Column(db.Text, nullable=True)
|
|
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"<Payment {self.amount} for invoice {self.invoice_id}>"
|
|
|
|
|
|
class CreditNote(db.Model):
|
|
"""Credit notes issued to offset invoices."""
|
|
|
|
__tablename__ = 'credit_notes'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
invoice_id = db.Column(db.Integer, db.ForeignKey('invoices.id'), nullable=False, index=True)
|
|
credit_number = db.Column(db.String(50), unique=True, nullable=False, index=True)
|
|
amount = db.Column(db.Numeric(10, 2), nullable=False)
|
|
reason = db.Column(db.Text, nullable=True)
|
|
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"<CreditNote {self.credit_number} for invoice {self.invoice_id}>"
|
|
|
|
|
|
class InvoiceReminderSchedule(db.Model):
|
|
"""Schedules to send invoice reminders before/after due dates."""
|
|
|
|
__tablename__ = 'invoice_reminder_schedules'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
invoice_id = db.Column(db.Integer, db.ForeignKey('invoices.id'), nullable=False, index=True)
|
|
days_offset = db.Column(db.Integer, nullable=False) # negative for before due, positive after
|
|
recipients = db.Column(db.Text, nullable=True) # comma-separated; default to client email if empty
|
|
template_name = db.Column(db.String(100), nullable=True)
|
|
active = db.Column(db.Boolean, default=True, nullable=False)
|
|
last_sent_at = db.Column(db.DateTime, nullable=True)
|
|
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"<InvoiceReminderSchedule inv={self.invoice_id} offset={self.days_offset}>"
|
|
|
|
|