Skip to content

Commit e820452

Browse files
committed
Add "since" parameter to this command
Fixes #25
1 parent f6e1d98 commit e820452

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
# -*- coding: utf-8 -*-
2+
import datetime
3+
import itertools
4+
5+
import dateutil.parser
26
from creditor.models import RecurringTransaction
37
from django.core.management.base import BaseCommand, CommandError
8+
from django.utils import timezone
9+
10+
from asylum.utils import datetime_proxy, months
411

512

613
class Command(BaseCommand):
714
help = 'Gets all RecurringTransactions and runs conditional_add_transaction()'
815

16+
def add_arguments(self, parser):
17+
parser.add_argument('since', type=str, nargs='?', default=datetime_proxy(), help='Run for each month since the date, defaults to yesterday midnight')
18+
919
def handle(self, *args, **options):
20+
since_parsed = timezone.make_aware(dateutil.parser.parse(options['since']))
21+
if options['verbosity'] > 2:
22+
print("Processing since %s" % since_parsed.isoformat())
23+
1024
for t in RecurringTransaction.objects.all():
11-
ret = t.conditional_add_transaction()
12-
if ret:
13-
if options['verbosity'] > 1:
14-
print("Created transaction %s" % ret)
25+
if options['verbosity'] > 2:
26+
print("Processing: %s" % t)
27+
for month in months(since_parsed, timezone.now()):
28+
if options['verbosity'] > 2:
29+
print(" month %s" % month.isoformat())
30+
ret = t.conditional_add_transaction(month)
31+
if ret:
32+
if options['verbosity'] > 1:
33+
print("Created transaction %s" % ret)

0 commit comments

Comments
 (0)