Skip to content

Commit

Permalink
Merge pull request #450 from renderbox:bugfix-billing-dates
Browse files Browse the repository at this point in the history
Bugfix-billing-dates
  • Loading branch information
rhimmelbauer authored Apr 24, 2024
2 parents 7bf9021 + 20667fa commit b76714c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
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]

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]

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)


0 comments on commit b76714c

Please sign in to comment.