|
| 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