Skip to content

Commit dcb4038

Browse files
authored
Merge pull request #189 from rambo/rt_update_tool
Tool to update membership fees
2 parents 4807e62 + 88318e5 commit dcb4038

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

project/creditor/management/commands/generate_membershipfees.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class Command(BaseCommand):
11-
help = 'generate randomised (member) tokens'
11+
help = 'Generate membership fee RecurringTransactions for all members'
1212

1313
def add_arguments(self, parser):
1414
parser.add_argument('amount', type=int)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
import datetime
3+
import dateutil.parser
4+
5+
from creditor.models import RecurringTransaction, TransactionTag
6+
from creditor.tests.fixtures.recurring import MembershipfeeFactory
7+
from django.core.management.base import BaseCommand, CommandError
8+
from members.models import Member
9+
10+
11+
class Command(BaseCommand):
12+
help = 'Update membership fee RecurringTransactions'
13+
14+
def add_arguments(self, parser):
15+
parser.add_argument('oldamount', type=int)
16+
parser.add_argument('cutoffdate', type=str)
17+
parser.add_argument('newamount', type=int)
18+
19+
def handle(self, *args, **options):
20+
cutoff_dt = dateutil.parser.parse(options['cutoffdate'])
21+
end_dt = cutoff_dt - datetime.timedelta(minutes=1)
22+
tgt_tag = TransactionTag.objects.get(label='Membership fee', tmatch='1')
23+
for rt in RecurringTransaction.objects.filter(
24+
rtype=RecurringTransaction.YEARLY,
25+
tag=tgt_tag,
26+
end=None,
27+
start__lt=cutoff_dt,
28+
amount=options['oldamount']
29+
):
30+
rt.end = end_dt
31+
rt.save()
32+
newrt = MembershipfeeFactory.create(amount=options['newamount'], start=cutoff_dt, end=None, owner=rt.owner)
33+
if options['verbosity'] > 0:
34+
print("Generated RecurringTransaction %s" % newrt)

0 commit comments

Comments
 (0)