mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-05-19 12:50:11 -05:00
f0b7e7a6df
Scheduled reports (per-salesman, unpaid-only)
- Schedule form: add email distribution (single / SalesmanEmailMapping /
template) and recipient template when "Split by custom field" is on.
- Support {value} and {value_lower} in recipient_email_template
(e.g. {value_lower}@test.de).
- Add use_last_month_dates on ReportEmailSchedule: optional "Use previous
calendar month" for monthly runs; migration 111.
- Override report date range in ScheduledReportService when
cadence=monthly and use_last_month_dates=true.
- Wire use_last_month_dates through schedule form, API, and
create_schedule.
Report Builder
- Add "Unpaid time entries" quick-start (Time Entries + unpaid only +
last 30 days) and applyUnpaidPreset().
- Clarify "Unpaid only" help: "Unpaid = billable, not yet on any invoice."
- Define canvas at top of script so edit-mode IIFE and addDataSourceToCanvas
can use it; fix applyUnpaidPreset/onclick when script failed to parse.
- Click-to-add for Data Sources and Components (in addition to drag-and-drop).
- Set dataTransfer.effectAllowed = 'copy' in dragstart for drop compatibility.
- Fix save-form handler: remove orphan try { with no catch that caused
SyntaxError and prevented applyUnpaidPreset (and rest of script) from loading.
Documentation
- Add docs/reports/UNPAID_BY_SALESMAN_AND_SCHEDULED_REPORTS.md (unpaid
definition, unpaid-by-salesman setup, SalesmanEmailMapping, template use).
53 lines
2.9 KiB
Python
53 lines
2.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
|
|
iterative_report_generation = db.Column(db.Boolean, default=False, nullable=False) # Generate one report per custom field value
|
|
iterative_custom_field_name = db.Column(db.String(50), nullable=True) # Custom field name for iteration (e.g., 'salesman')
|
|
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)
|
|
split_by_salesman = db.Column(db.Boolean, default=False, nullable=False) # Split report by salesman
|
|
salesman_field_name = db.Column(db.String(50), nullable=True) # Custom field name for salesman (default: 'salesman')
|
|
email_distribution_mode = db.Column(db.String(20), nullable=True) # 'mapping', 'template', 'single'
|
|
recipient_email_template = db.Column(db.String(255), nullable=True) # e.g., '{value}@test.de' for template mode
|
|
use_last_month_dates = db.Column(db.Boolean, default=False, nullable=False) # For monthly: use previous calendar month as date range
|
|
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)
|
|
|
|
# Relationships
|
|
saved_view = db.relationship("SavedReportView", backref="schedules")
|
|
creator = db.relationship("User", foreign_keys=[created_by])
|
|
|
|
def __repr__(self):
|
|
return f"<ReportEmailSchedule view={self.saved_view_id} cadence={self.cadence}>"
|