|
@@ -1,4 +1,4 @@
|
|
|
-from django.core.management.base import BaseCommand
|
|
|
+from django.core.management.base import BaseCommand, CommandParser, CommandError
|
|
|
from django.db.models import DecimalField, F, Sum, Func, Q
|
|
|
|
|
|
from decimal import Decimal
|
|
@@ -7,9 +7,32 @@ from services.models import Service, ServiceType
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
- help = 'Bénéfices des services'
|
|
|
+ help = 'Gestion des services'
|
|
|
+
|
|
|
+ def add_arguments(self, parser):
|
|
|
+ cmd = self
|
|
|
+ class SubParser(CommandParser):
|
|
|
+ def __init__(self, **kwargs):
|
|
|
+ super().__init__(cmd, **kwargs)
|
|
|
+ subparsers = parser.add_subparsers(dest='command', parser_class=SubParser)
|
|
|
+ subparsers.required = True
|
|
|
+
|
|
|
+ parser_stats = subparsers.add_parser('stats', help='Afficher les statistiques sur les services')
|
|
|
+
|
|
|
+ parser_add = subparsers.add_parser('add', help='Ajouter un nouveau service')
|
|
|
+
|
|
|
+ parser_change = subparsers.add_parser('change', help='Modifier un service existant')
|
|
|
+ parser_change.add_argument('id', type=int)
|
|
|
+
|
|
|
+ parser_delete = subparsers.add_parser('delete', help='Supprimer un service existant')
|
|
|
+ parser_delete.add_argument('id', type=int)
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
+ cmd = options.pop('command')
|
|
|
+ getattr(self, 'handle_{cmd}'.format(cmd=cmd))(*args, **options)
|
|
|
+
|
|
|
+ def handle_stats(self, *args, **options):
|
|
|
+ # TODO: move this code in utils.py or some file like that
|
|
|
as_float_template = '%(function)s(%(expressions)s AS FLOAT)'
|
|
|
total_income = Decimal(0.0)
|
|
|
lines = []
|
|
@@ -40,3 +63,12 @@ class Command(BaseCommand):
|
|
|
else:
|
|
|
percent = 0
|
|
|
self.stdout.write("%-16s%12d%12d%12d%12.2f%12.1f" % (service_type, npay, ninf, ngra, income, percent))
|
|
|
+
|
|
|
+ def handle_add(self, *args, **options):
|
|
|
+ raise CommandError("Non implémenté")
|
|
|
+
|
|
|
+ def handle_change(self, *args, **options):
|
|
|
+ raise CommandError("Non implémenté")
|
|
|
+
|
|
|
+ def handle_delete(self, *args, **options):
|
|
|
+ raise CommandError("Non implémenté")
|