46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
# lingo - payment and billing system
|
|
# Copyright (C) 2022 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import datetime
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from lingo.invoicing.utils import generate_invoices
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Generate invoicing for a period'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('date_start')
|
|
parser.add_argument('date_end')
|
|
|
|
def handle(self, *args, **options):
|
|
try:
|
|
date_start = datetime.datetime.fromisoformat(options['date_start']).date()
|
|
except ValueError:
|
|
raise CommandError('Bad value "%s" for date_start' % options['date_start'])
|
|
try:
|
|
date_end = datetime.datetime.fromisoformat(options['date_end']).date()
|
|
except ValueError:
|
|
raise CommandError('Bad value "%s" for date_end' % options['date_end'])
|
|
|
|
generate_invoices(date_start=date_start, date_end=date_end)
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS('Invoicing generation OK (start: %s, end: %s)' % (date_start, date_end))
|
|
)
|