emailing command: code fix, taking in account timezone for dates
This commit is contained in:
parent
314862e1cc
commit
6aab220e20
|
@ -1,9 +1,9 @@
|
|||
from os import path
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.conf import settings
|
||||
from django.utils.timezone import make_aware, get_current_timezone
|
||||
|
||||
from synchro_orleans.data.models import Facture
|
||||
|
||||
|
@ -11,17 +11,16 @@ json_location = settings.INVOICES_MAIL_LOCATION_PATTERN
|
|||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = """Synchronizes the invoices state: if a file corresponding to a
|
||||
invoice is present the invoice becomes active and inactive if not."""
|
||||
help = """Checks for new active invoices and creates emails to send to the users"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
for invoice in Facture.objects.filter(active=True, date_envoi_dernier_mail__isnull=True,
|
||||
date_limite_paie__gte=datetime.now(),
|
||||
famille__liaisonnameidfamille__isnull=False, paye=False):
|
||||
nameid = invoice.famille.liaisonnameidfamille_set.all()[0]
|
||||
with open(json_location.format(invoice_id=invoice.id) , 'w') as json_output:
|
||||
json.dump(json_output, {'nameid': nameid, 'invoice_id': invoice.id})
|
||||
invoice.date_envoi_dernier_mail = datetime.now()
|
||||
invoice.save()
|
||||
nameid = invoice.famille.liaisonnameidfamille_set.all()[0]
|
||||
with open(json_location.format(invoice_id=invoice.id) , 'w') as json_output:
|
||||
json.dump({'nameid': nameid.name_id, 'invoice_id': invoice.id}, json_output)
|
||||
invoice.date_envoi_dernier_mail = make_aware(datetime.now(), get_current_timezone())
|
||||
invoice.save()
|
||||
|
||||
|
|
Reference in New Issue