replace user.next_bill_date() by sub.next_bill_date.strftime("%Y-%m-%d")

This commit is contained in:
Son NK 2020-04-19 10:54:05 +02:00
parent b0118e615a
commit f7f1e7f358
7 changed files with 25 additions and 24 deletions

View File

@ -14,7 +14,7 @@
{% if sub.cancelled %}
<p>
You are on the <b>{{ sub.plan_name() }}</b> plan. <br>
You have canceled your subscription and it will end on {{ current_user.next_bill_date() }}
You have canceled your subscription and it will end on {{ sub.next_bill_date.strftime("%Y-%m-%d") }}
</p>
<hr>

View File

@ -57,13 +57,14 @@
</a>
</div>
{% if current_user.is_cancel() %}
<div class="alert alert-primary" role="alert">
You have an active subscription until {{current_user.next_bill_date()}}. <br>
Please note that if you re-subscribe now, this will be a completely
new subscription and
your payment method will be charged <b>immediately</b>.
</div>
{% set sub = current_user.get_subscription() %}
{% if sub and sub.cancelled %}
<div class="alert alert-primary" role="alert">
You have an active subscription until {{ sub.next_bill_date.strftime("%Y-%m-%d") }}. <br>
Please note that if you re-subscribe now, this will be a completely
new subscription and
your payment method will be charged <b>immediately</b>.
</div>
{% endif %}
<div class="mb-3">

View File

@ -262,16 +262,6 @@ class User(db.Model, ModelMixin, UserMixin):
return True
def next_bill_date(self) -> str:
sub: Subscription = self.get_subscription()
if sub:
return sub.next_bill_date.strftime("%Y-%m-%d")
LOG.error(
f"next_bill_date() should be called only on user with active subscription. User {self}"
)
return ""
def is_cancel(self) -> bool:
"""User has canceled their subscription but the subscription is still active,
i.e. next_bill_date > now"""

12
cron.py
View File

@ -63,8 +63,16 @@ def notify_premium_end():
send_email(
user.email,
f"Your subscription will end soon {user.name}",
render("transactional/subscription-end.txt", user=user),
render("transactional/subscription-end.html", user=user),
render(
"transactional/subscription-end.txt",
user=user,
next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"),
),
render(
"transactional/subscription-end.html",
user=user,
next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"),
),
)

View File

@ -7,7 +7,7 @@
{{ render_text("Hi,") }}
{% endif %}
{{ render_text("Your subscription will end on " + user.next_bill_date() + ".") }}
{{ render_text("Your subscription will end on " + next_bill_date + ".") }}
{{ render_text("When the subscription ends:") }}

View File

@ -1,6 +1,6 @@
Hi {{user.name}}
Your subscription will end on {{ user.next_bill_date() }}.
Your subscription will end on {{ next_bill_date }}.
When the subscription ends:

View File

@ -28,9 +28,11 @@
{% if current_user.in_trial() %}
<small class="text-success d-block mt-1">Trial ends {{ current_user.trial_end|dt }}</small>
{% elif current_user.is_premium() %}
<small class="text-success d-block mt-1">Premium
{% if current_user.is_cancel() %}
until {{ current_user.next_bill_date() }}
{% set sub = current_user.get_subscription() %}
{% if sub and sub.cancelled %}
until {{ sub.next_bill_date.strftime("%Y-%m-%d") }}
{% endif %}
</small>
{% endif %}