This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
synchro-orleans/synchro_orleans/data/management/commands/invoicestatussync.py

23 lines
687 B
Python

from os import path
from django.core.management.base import BaseCommand, CommandError
from django.db.models import get_model
from django.conf import settings
from synchro_orleans.data.models import Facture
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.all():
active = path.exists(settings.INVOICES_LOCATION_PATTERN.format(invoice_id = invoice.id))
if active != invoice.active:
invoice.active = active
invoice.save()