create json detail files for new invoices
This commit is contained in:
parent
7f209ee341
commit
314862e1cc
|
@ -0,0 +1,27 @@
|
|||
from os import path
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.conf import settings
|
||||
|
||||
from synchro_orleans.data.models import Facture
|
||||
|
||||
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."""
|
||||
|
||||
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()
|
||||
|
|
@ -162,6 +162,9 @@ 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')
|
||||
|
||||
try:
|
||||
from local_settings import *
|
||||
except ImportError:
|
||||
|
|
Reference in New Issue