sending invoice notifications after 10 days if still not paid

This commit is contained in:
Serghei Mihai 2014-04-15 17:29:46 +02:00
parent 77327739a1
commit e729f2afe6
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
import json
import shutil
import os
@ -18,11 +18,18 @@ class Command(BaseCommand):
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(),
for invoice in Facture.objects.filter(active=True, date_limite_paie__gte=datetime.now(),
famille__liaisonnameidfamille__isnull=False, paye=False):
try:
notification = InvoiceNotificationEmail.objects.filter(invoice_number=invoice.id).latest()
if notification.date_sent < make_aware(datetime.now(), get_current_timezone()) - timedelta(days=10):
continue
except:
InvoiceNotificationEmaxil.objects.create(invoice_number=invoice.id)
nameid = invoice.famille.liaisonnameidfamille_set.all()[0]
with open(os.path.join(tmp_json_location, '%s.json' % invoice.id), 'w') as json_output:
tmp_json_file = os.path.join(tmp_json_location, '%s.json' % invoice.id)
with open(tmp_json_file, '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)

View File

@ -374,3 +374,6 @@ class Enfant(models.Model):
class InvoiceNotificationEmail(models.Model):
invoice_number = models.CharField(max_length=64)
date_sent = models.DateTimeField(auto_now_add=True)
def Meta:
get_latest_by = 'date_sent'