json creation dates stored in a separate table.

This commit is contained in:
Serghei Mihai 2014-04-14 17:28:06 +02:00
parent 6aab220e20
commit 3abed77214
3 changed files with 15 additions and 7 deletions

View File

@ -1,12 +1,15 @@
from datetime import datetime
import json
import shutil
import os
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
from synchro_orleans.data.models import Facture, InvoiceNotificationEmail
tmp_json_location = settings.INVOICES_MAIL_DIR
json_location = settings.INVOICES_MAIL_LOCATION_PATTERN
class Command(BaseCommand):
@ -19,8 +22,10 @@ class Command(BaseCommand):
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:
with open(os.path.join(tmp_json_location, '%s.json' % 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())
InvoiceNotificationEmail.objects.create(invoice.id)
invoice.save()
shutil.move(tmp_json_location, json_location.format(invoice_id=invoice.id))

View File

@ -370,3 +370,7 @@ class Enfant(models.Model):
def __unicode__(self):
return u'%s %s' % (self.prenom, self.nom)
class InvoiceNotificationEmail(models.Model):
invoice_number = models.CharField(max_length=64)
date_sent = models.DateTimeField(auto_now_add=True)

View File

@ -159,11 +159,10 @@ LOGGING = {
}
}
INVOICES_LOCATION_PATTERN = os.path.join(os.environ.get('INVOICES_DIR', os.path.dirname(__file__)),
'facture_{invoice_id}.pdf')
INVOICES_MAIL_LOCATION_PATTERN = os.path.join(os.environ.get('INVOICES_MAIL_DIR', os.path.dirname(__file__)),
'tipi', 'facture_{invoice_id}.json')
INVOICES_DIR = os.environ.get('INVOICES_DIR', os.path.dirname(__file__))
INVOICES_MAIL_DIR = os.environ.get('INVOICES_MAIL_DIR', os.path.dirname(__file__))
INVOICES_LOCATION_PATTERN = os.path.join(INVOICES_DIR, 'facture_{invoice_id}.pdf')
INVOICES_MAIL_LOCATION_PATTERN = os.path.join(INVOICES_MAIL_DIR, 'tipi', 'facture_{invoice_id}.json')
try:
from local_settings import *