mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2025-06-29 01:40:55 +02:00
Improve scripts to be run with cron jobs
This commit is contained in:
@ -18,14 +18,20 @@ class Command(BaseCommand):
|
||||
activate('fr')
|
||||
notes = NoteUser.objects.filter(
|
||||
user__memberships__date_end__gte=timezone.now(),
|
||||
user__profile__report_frequency__gt=0,
|
||||
).distinct().all()
|
||||
for note in notes:
|
||||
now = timezone.now()
|
||||
last_week = now - timedelta(days=7)
|
||||
last_report = note.user.profile.last_report
|
||||
delta = now.date() - last_report
|
||||
if delta.days < note.user.profile.report_frequency:
|
||||
continue
|
||||
note.user.profile.last_report = now.date()
|
||||
note.user.profile.save()
|
||||
last_transactions = Transaction.objects.filter(
|
||||
Q(source=note) | Q(destination=note),
|
||||
created_at__gte=last_week,
|
||||
).all()
|
||||
created_at__gte=last_report,
|
||||
).order_by("created_at").all()
|
||||
if not last_transactions.exists():
|
||||
continue
|
||||
|
||||
@ -39,7 +45,7 @@ class Command(BaseCommand):
|
||||
outcoming=outcoming,
|
||||
diff=incoming - outcoming,
|
||||
now=now,
|
||||
last_week=last_week,
|
||||
last_report=last_report,
|
||||
)
|
||||
html = render_to_string("note/mails/weekly_report.html", context)
|
||||
note.user.email_user("[Note Kfet] Rapport de la Note Kfet", html, html_message=html)
|
||||
|
Reference in New Issue
Block a user