Add subscription description
This commit is contained in:
parent
df1ce8d265
commit
8af59f231d
18
src/core/migrations/0028_order_subscription_description.py
Normal file
18
src/core/migrations/0028_order_subscription_description.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.0.2 on 2022-12-30 21:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0027_order_subscription'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='subscription_description',
|
||||
field=models.CharField(blank=True, max_length=500),
|
||||
),
|
||||
]
|
||||
@ -389,6 +389,7 @@ class Order(models.Model):
|
||||
null=True,
|
||||
on_delete=models.SET_NULL
|
||||
)
|
||||
subscription_description = models.CharField(max_length=500, blank=True)
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True, editable=False)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
@ -570,6 +571,7 @@ class Subscription(models.Model):
|
||||
for x in data:
|
||||
if 'Coffee' in x['description']:
|
||||
subscription['unit_price'] = self.convert_int_to_decimal(x['price']['unit_amount'])
|
||||
subscription['description'] = x['description']
|
||||
|
||||
if 'Shipping' in x['description']:
|
||||
subscription['shipping_cost'] = self.convert_int_to_decimal(x['amount'])
|
||||
@ -590,7 +592,8 @@ class Subscription(models.Model):
|
||||
shipping_total=subscription['shipping_cost'],
|
||||
total_amount=self.convert_int_to_decimal(data_object['total']),
|
||||
weight=self.total_weight,
|
||||
subscription=self
|
||||
subscription=self,
|
||||
subscription_description=subscription['description']
|
||||
)
|
||||
|
||||
bulk_lines = [OrderLine(
|
||||
|
||||
@ -13,6 +13,11 @@
|
||||
<span class="order__status order__status--{{order.status}}">{{order.get_status_display}} ({{order.total_quantity_fulfilled}} / {{order.total_quantity_ordered}})</span>
|
||||
</div>
|
||||
</header>
|
||||
{% if order.subscription %}
|
||||
<section>
|
||||
<h3>Subscription: {{ order.subscription_description }}</h3><br>
|
||||
</section>
|
||||
{% endif %}
|
||||
<section class="object__list">
|
||||
<div class="object__item panel__header object__item--col5">
|
||||
<span>Product</span>
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
</div>
|
||||
{% for order in order_list %}
|
||||
<a class="object__item object__item--link object__item--col5" href="{% url 'dashboard:order-detail' order.pk %}">
|
||||
<span>#{{order.pk}}</span>
|
||||
<span>#{{order.pk}} {% if order.subscription %}(subscription){% endif %}</span>
|
||||
<span>{{order.created_at|date:"D, M j Y"}}</span>
|
||||
<span>{{order.customer.get_full_name}}</span>
|
||||
<span class="order__status--display">
|
||||
|
||||
@ -63,16 +63,16 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Subscription #</th>
|
||||
<th>Subscription</th>
|
||||
<th colspan="2">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for subscription in subscriptions %}
|
||||
<tr>
|
||||
<td>{{ subscription.id }}</td>
|
||||
<td>#{{ subscription.metadata.subscription_pk }}</td>
|
||||
<td>{{ subscription.status }}</td>
|
||||
<td><a href="https://dashboard.stripe.com/test/subscriptions/{{ subscription.id }}">manage subscription ↗</a></td>
|
||||
<td><a href="https://dashboard.stripe.com/test/subscriptions/{{ subscription.id }}">manage ↗</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@ -95,7 +95,7 @@
|
||||
<tr>
|
||||
<td>#{{order.pk}}</td>
|
||||
<td>{{order.created_at|date:"M j, Y"}}</td>
|
||||
<td>${{order.get_total_price_after_discount}}</td>
|
||||
<td>${{order.total_amount}}</td>
|
||||
<td><a href="{% url 'storefront:order-detail' customer.pk order.pk %}">See details →</a></td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
|
||||
@ -8,6 +8,11 @@
|
||||
<h1>Order #{{order.pk}}</h1>
|
||||
<h3>Placed on {{order.created_at|date:"M j, Y"}}</h3>
|
||||
</header>
|
||||
{% if order.subscription %}
|
||||
<section>
|
||||
<h3>Subscription: {{ order.subscription_description }}</h3><br>
|
||||
</section>
|
||||
{% endif %}
|
||||
<section>
|
||||
<table>
|
||||
<thead>
|
||||
@ -71,7 +76,7 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td>Subtotal</td>
|
||||
<td>${{order.subtotal}}</td>
|
||||
<td>${{order.subtotal_amount}}</td>
|
||||
</tr>
|
||||
{% if order.coupon %}
|
||||
<tr>
|
||||
|
||||
@ -600,57 +600,10 @@ class SubscriptionFormView(FormView):
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class SubscriptionAddAddressView(FormView):
|
||||
class SubscriptionAddAddressView(CheckoutAddressView):
|
||||
template_name = 'storefront/subscription/address.html'
|
||||
form_class = AddressForm
|
||||
success_url = reverse_lazy('storefront:subscription-create')
|
||||
|
||||
def get_initial(self):
|
||||
user = self.request.user
|
||||
initial = None
|
||||
if user.is_authenticated and user.default_shipping_address:
|
||||
address = user.default_shipping_address
|
||||
initial = {
|
||||
'full_name': address.first_name + ' ' + address.last_name,
|
||||
'email': user.email,
|
||||
'street_address_1': address.street_address_1,
|
||||
'street_address_2': address.street_address_2,
|
||||
'city': address.city,
|
||||
'state': address.state,
|
||||
'postal_code': address.postal_code
|
||||
}
|
||||
elif self.request.session.get('shipping_address'):
|
||||
address = self.request.session.get('shipping_address')
|
||||
initial = {
|
||||
'full_name': address['first_name'] + ' ' + address['last_name'],
|
||||
'email': address['email'],
|
||||
'street_address_1': address['street_address_1'],
|
||||
'street_address_2': address['street_address_2'],
|
||||
'city': address['city'],
|
||||
'state': address['state'],
|
||||
'postal_code': address['postal_code']
|
||||
}
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
# save address data to session
|
||||
cleaned_data = form.cleaned_data
|
||||
first_name, last_name = form.process_full_name(
|
||||
cleaned_data.get('full_name')
|
||||
)
|
||||
address = {
|
||||
'first_name': first_name,
|
||||
'last_name': last_name,
|
||||
'email': cleaned_data['email'],
|
||||
'street_address_1': cleaned_data['street_address_1'],
|
||||
'street_address_2': cleaned_data['street_address_2'],
|
||||
'city': cleaned_data['city'],
|
||||
'state': cleaned_data['state'],
|
||||
'postal_code': cleaned_data['postal_code']
|
||||
}
|
||||
self.request.session['shipping_address'] = address
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class SubscriptionCreateView(SuccessMessageMixin, CreateView):
|
||||
model = Subscription
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user