Skip to content

Commit

Permalink
Allow quarterly periodicities
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Oct 12, 2018
1 parent b69a536 commit 0bda480
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change log

- Ensured that the username is part of ``search_fields`` for all models
registered with the admin interface.
- Added a new subscription periodicity, ``quarterly``.


`0.3`_ (2018-09-21)
Expand Down
11 changes: 11 additions & 0 deletions tests/testapp/test_subscription_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def test_recurring(self):
],
)

self.assertEqual(
list(islice(recurring(date(2016, 1, 31), "quarterly"), 5)),
[
date(2016, 1, 31),
date(2016, 5, 1),
date(2016, 7, 31),
date(2016, 10, 31),
date(2017, 1, 31),
],
)

self.assertEqual(
list(islice(recurring(date(2016, 1, 31), "monthly"), 5)),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Migration(migrations.Migration):
models.CharField(
choices=[
("yearly", "yearly"),
("quarterly", "quarterly"),
("monthly", "monthly"),
("weekly", "weekly"),
("manually", "manually"),
Expand Down
1 change: 1 addition & 0 deletions user_payments/user_subscriptions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Subscription(models.Model):
max_length=20,
choices=[
("yearly", _("yearly")),
("quarterly", _("quarterly")),
("monthly", _("monthly")),
("weekly", _("weekly")),
("manually", _("manually")),
Expand Down
6 changes: 6 additions & 0 deletions user_payments/user_subscriptions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def recurring(start, periodicity):
for i in itertools.count()
)

elif periodicity == "quarterly":
return ( # pragma: no branch
next_valid_day(start.year, start.month + i * 3, start.day)
for i in itertools.count()
)

elif periodicity == "monthly":
return ( # pragma: no branch
next_valid_day(start.year, start.month + i, start.day)
Expand Down

0 comments on commit 0bda480

Please sign in to comment.