Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix-billing-dates #450

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ universal = true

[project]
name = "django-vendor"
version = "0.4.13"
version = "0.4.14"

authors = [
{ name="Grant Viklund", email="[email protected]" },
Expand Down
22 changes: 20 additions & 2 deletions src/vendor/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,42 @@ def get_active_subscriptions(self):
return self.subscriptions.filter(status=SubscriptionStatus.ACTIVE)

def get_next_billing_date(self):
'''Returns the next billing date for the customers subscriptions'''
next_billing_dates = []

if not self.subscriptions.filter(status=SubscriptionStatus.ACTIVE).count():
return None

next_billing_dates = [subscription.get_next_billing_date() for subscription in self.get_active_subscriptions()]

if not next_billing_dates:
return None

filtered_dates = [date for date in next_billing_dates if date is not None]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the return case come after calculating filtered_dates? what if next_billing_dates == [None]?

if not filtered_dates:
    return None


if not filtered_dates:
return None

return sorted(next_billing_dates)[0]
return sorted(filtered_dates)[0]

def get_last_payment_date(self):
'''Returns the last payment date made form the customer subscriptions'''
last_payment_dates = []

if not self.subscriptions.count():
return None

last_payment_dates = [subscription.get_last_payment_date() for subscription in self.subscriptions.all()]

return sorted(last_payment_dates)[-1]
if not last_payment_dates:
return None

filtered_dates = [date for date in last_payment_dates if date is not None]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same note here


if not filtered_dates:
return None

return sorted(filtered_dates)[-1]

def get_payment_counts(self):
return self.payments.filter(deleted=False, status=PurchaseStatus.SETTLED).count()
Expand Down
20 changes: 18 additions & 2 deletions src/vendor/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,36 @@ def cancel(self):
self.save()

def get_next_billing_date(self):
receipts = self.receipts.filter(Q(deleted=False), Q(end_date__gte=timezone.now()) | Q(end_date=None)).order_by('end_date')
'''Returns the next billing date

Function returns the next billing date which is the last receipt.end_date for the subscription.'''
receipts = self.receipts.filter(Q(deleted=False), Q(end_date__gte=timezone.now())).order_by('end_date')

if not receipts.count():
return None

return receipts.first().end_date

def get_last_payment_date(self):
'''Return the payments related reciept start date.

Instead of returning payments.create DateTime field it return the releated payments reciept.start_date
because that field can be edited to match an actual payment date if necessary.

Returns:
None or DateTime
'''
payment = self.payments.filter(deleted=False, status__lte=PurchaseStatus.SETTLED).order_by('-created').first()

if not payment:
return None

receipt = payment.get_receipt()

if receipt is None or not receipt.start_date:
return None

return payment.get_receipt().start_date
return receipt.start_date

def is_on_trial(self):
if not self.receipts.filter(deleted=False).count():
Expand Down
1 change: 0 additions & 1 deletion src/vendor/processors/authorizenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class AuthorizeNetProcessor(PaymentProcessorBase):
def __str__(self):
return 'Authorize.Net'


def processor_setup(self, site):
"""
Merchant Information needed to aprove the transaction.
Expand Down
2 changes: 0 additions & 2 deletions src/vendor/tests/test_authorizenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,5 +1046,3 @@ def test_update_payment_success(self):

payment.refresh_from_db()
self.assertEqual(payment.status, PurchaseStatus.SETTLED)


Loading