Merge pull request #134 from levivm/feature/new_digitalglarus

Delete required membership months and fixed some css style.
This commit is contained in:
Levi Velázquez 2016-10-22 23:18:03 -05:00 committed by GitHub
commit 7381928afb
7 changed files with 37 additions and 131 deletions

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-10-23 02:18
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('digitalglarus', '0021_auto_20161017_1958'),
]
operations = [
migrations.RemoveField(
model_name='bookingorder',
name='membership_required_months',
),
migrations.RemoveField(
model_name='bookingorder',
name='membership_required_months_price',
),
]

View file

@ -128,12 +128,7 @@ class MembershipOrder(Ordereable, models.Model):
} }
def get_membership_range_date(self): def get_membership_range_date(self):
start_date = self.created_at return self.start_date, self.end_date
_, days_in_month = calendar.monthrange(start_date.year,
start_date.month)
start_date.replace(day=1)
end_date = start_date + timedelta(days=days_in_month)
return start_date, end_date
@classmethod @classmethod
def create(cls, data): def create(cls, data):
@ -183,18 +178,9 @@ class Booking(models.Model):
total_free_days = months * TWO_DAYS + free_days_this_month total_free_days = months * TWO_DAYS + free_days_this_month
return total_free_days return total_free_days
@staticmethod
def membership_required_booking_months(start_date, end_date):
start_month = start_date.month
end_month = end_date.month
months = abs(start_month - (end_month + 12) if end_month < start_month
else end_month - start_month)
return months
@classmethod @classmethod
def booking_price(cls, user, start_date, end_date): def booking_price(cls, user, start_date, end_date):
TWO_DAYS = 2
MAX_MONTH_PRICE = BookingPrice.objects.last().special_month_price MAX_MONTH_PRICE = BookingPrice.objects.last().special_month_price
MAX_MONTH_DAYS_PROMOTION = 31 MAX_MONTH_DAYS_PROMOTION = 31
MIN_MONTH_DAYS_PROMOTION = 19 MIN_MONTH_DAYS_PROMOTION = 19
@ -209,36 +195,17 @@ class Booking(models.Model):
if remanent_days <= MIN_MONTH_DAYS_PROMOTION else MAX_MONTH_PRICE if remanent_days <= MIN_MONTH_DAYS_PROMOTION else MAX_MONTH_PRICE
normal_price = months_prices + remanent_days_price normal_price = months_prices + remanent_days_price
# Calculating membership required months price for booking
required_membership_months = 0
membership_booking_price = 0.0
# if not BookingOrder.user_has_not_bookings(user):
today = datetime.today().date()
membership_price = MembershipType.objects.get(name=MembershipType.STANDARD).price
required_membership_months = cls.membership_required_booking_months(today, end_date)
membership_booking_price = membership_price * required_membership_months
# TO-DO Fix this, what happens when user has free days from his current membership month
if not required_membership_months:
free_days = cls.get_ramaining_free_days(user, start_date, end_date) free_days = cls.get_ramaining_free_days(user, start_date, end_date)
else:
free_days = required_membership_months * TWO_DAYS
# free_days += free_days_for_required_memberships
final_booking_price = normal_price - (free_days * price_per_day) final_booking_price = normal_price - (free_days * price_per_day)
# Add required membership months to final prices return normal_price, final_booking_price, free_days
final_booking_price += membership_booking_price
return normal_price, final_booking_price, free_days,\
required_membership_months, membership_booking_price
class BookingOrder(Ordereable, models.Model): class BookingOrder(Ordereable, models.Model):
booking = models.OneToOneField(Booking) booking = models.OneToOneField(Booking)
original_price = models.FloatField() original_price = models.FloatField()
special_month_price = models.FloatField() special_month_price = models.FloatField()
membership_required_months = models.IntegerField(default=0)
membership_required_months_price = models.FloatField(default=0)
@classmethod @classmethod
def user_has_not_bookings(cls, user): def user_has_not_bookings(cls, user):

View file

@ -44,21 +44,17 @@
</h2> </h2>
<h2 class="col-xs-6 payment-total text-left">Total days {{booking_days}}</h2> <h2 class="col-xs-6 payment-total text-left">Total days {{booking_days}}</h2>
<h2 class="order-sum">{{original_price|floatformat}}CHF</h2> <h2 class="order-sum">{{original_price|floatformat}}CHF</h2>
{% if membership_required_months and membership_required_months_price %}
<h2 class="col-xs-6 payment-total text-left">Required Membership months: {{membership_required_months}}</h2>
<h2 class="order-sum"><span>{{membership_required_months_price|floatformat}}CHF</span></h2>
{% endif %}
{% if free_days %} {% if free_days %}
<h2 class="col-xs-6 payment-total text-left">Free days {{free_days}} </h2> <h2 class="col-xs-6 payment-total text-left">Free days {{free_days}} </h2>
<h2 class="order-sum">-{{total_discount|floatformat}}CHF</h2> <h2 class="order-sum text-danger">-{{total_discount|floatformat}}CHF</h2>
{% endif %} {% endif %}
<hr class="greyline-long"> <hr class="greyline-long">
<h2 class="col-xs-6 payment-total text-left"> Total</h2> <h2 class="col-xs-6 payment-total text-left"> Total</h2>
<h2 class="order-result">{{final_price|floatformat}}CHF</h2> <h2 class="order-result">{{final_price|floatformat}}CHF</h2>
<br> <br>
<p class="order-bottom-text"> <p class="">
View my bookings <a href="{% url 'digitalglarus:booking_orders_list' %}">Go to my page</a> View my bookings <br/><a class="btn btn-primary btn-sm btn-blck " href="{% url 'digitalglarus:booking_orders_list' %}">Go to my page</a>
</p> </p>
</div> </div>
@ -74,13 +70,9 @@
<h2 class="col-xs-6 payment-total">Total days {{booking_days}}</h2> <h2 class="col-xs-6 payment-total">Total days {{booking_days}}</h2>
<h2 class="order-sum">{{original_price|floatformat}}CHF</h2> <h2 class="order-sum">{{original_price|floatformat}}CHF</h2>
{% if membership_required_months and membership_required_months_price %}
<h2 class="col-xs-6 payment-total">Required Membership months: {{membership_required_months}}</h2>
<h2 class="order-sum"><span>{{membership_required_months_price|floatformat}}CHF</span></h2>
{% endif %}
{% if free_days %} {% if free_days %}
<h2 class="col-xs-6 payment-total">Free days {{free_days}}</h2> <h2 class="col-xs-6 payment-total">Free days {{free_days}}</h2>
<h2 class="order-sum">-{{total_discount|floatformat}}CHF</h2> <h2 class="order-sum text-danger">-{{total_discount|floatformat}}CHF</h2>
{% endif %} {% endif %}
<hr class="greyline"> <hr class="greyline">
<h2 class="col-xs-6 payment-total">Total</h2> <h2 class="col-xs-6 payment-total">Total</h2>

View file

@ -24,7 +24,6 @@
<th>#</th> <th>#</th>
<th>Booking dates</th> <th>Booking dates</th>
<th>Days</th> <th>Days</th>
<th>Membership Required Months</th>
<th>Invoice</th> <th>Invoice</th>
</tr> </tr>
</thead> </thead>
@ -34,7 +33,6 @@
<th scope="row">{{order.id}}</th> <th scope="row">{{order.id}}</th>
<td>{{order.booking.start_date}}-{{order.booking.end_date}}</td> <td>{{order.booking.start_date}}-{{order.booking.end_date}}</td>
<td>{{order.booking_days}}</td> <td>{{order.booking_days}}</td>
<td>{{order.membership_required_months}}</td>
<td><a class="btn btn-xs btn-primary btn-darkgrey" href="{% url 'digitalglarus:booking_orders_detail' order.id %}">View</a></td> <td><a class="btn btn-xs btn-primary btn-darkgrey" href="{% url 'digitalglarus:booking_orders_detail' order.id %}">View</a></td>
</tr> </tr>
{% endfor %} {% endfor %}

View file

@ -151,10 +151,6 @@
<hr class="greyline"> <hr class="greyline">
<h2 class="col-xs-6 payment-total">Total days: {{booking_days}} </h2> <h2 class="col-xs-6 payment-total">Total days: {{booking_days}} </h2>
<h2 class="order-sum">{{original_price|floatformat}}CHF</h2> <h2 class="order-sum">{{original_price|floatformat}}CHF</h2>
{% if membership_required_months and membership_required_months_price %}
<h2 class="col-xs-6 payment-total">Required Membership months: {{membership_required_months}}</h2>
<h2 class="order-sum"><span>{{membership_required_months_price|floatformat}}CHF</span></h2>
{% endif %}
<br/> <br/>
{% if free_days %} {% if free_days %}
<h2 class="col-xs-6 payment-total">Free days: {{free_days}}</h2> <h2 class="col-xs-6 payment-total">Free days: {{free_days}}</h2>

View file

@ -32,6 +32,7 @@
<form method="POST" action=""> <form method="POST" action="">
{% csrf_token %} {% csrf_token %}
<button type="button" class="btn btn-primary btn-blue" data-toggle="modal" data-target="#cancel-subscription-modal">Cancel my Membership</button> <button type="button" class="btn btn-primary btn-blue" data-toggle="modal" data-target="#cancel-subscription-modal">Cancel my Membership</button>
<a class="btn btn-primary btn-blue" href="{{request.META.HTTP_REFERER}}">Go back</a>
@ -59,7 +60,7 @@
</div> </div>
<div class="notice-box text-left"> <div class="notice-box text-left">
<p class="order-bottom-text"> <p class="order-bottom-text">
Your membership wouldn't be automatically renewed each month. <a href="{{request.META.HTTP_REFERER}}">Go back</a> Your membership wouldn't be automatically renewed each month.
</p> </p>
</div> </div>
</div> </div>

View file

@ -109,8 +109,7 @@ class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormVi
price_per_day = BookingPrice.objects.get().price_per_day price_per_day = BookingPrice.objects.get().price_per_day
original_price, final_price, free_days,\ original_price, final_price, free_days = Booking.\
membership_required_months, membership_required_months_price = Booking.\
booking_price(user, start_date, end_date) booking_price(user, start_date, end_date)
total_discount = price_per_day * free_days total_discount = price_per_day * free_days
@ -119,8 +118,6 @@ class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormVi
'original_price': original_price, 'original_price': original_price,
'final_price': final_price, 'final_price': final_price,
'total_discount': total_discount, 'total_discount': total_discount,
'membership_required_months_price': membership_required_months_price,
'membership_required_months': membership_required_months,
'booking_price_per_day': price_per_day, 'booking_price_per_day': price_per_day,
'booking_days': booking_days, 'booking_days': booking_days,
'free_days': free_days, 'free_days': free_days,
@ -137,8 +134,7 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
membership_redirect_url = reverse_lazy('digitalglarus:membership_pricing') membership_redirect_url = reverse_lazy('digitalglarus:membership_pricing')
# success_url = reverse_lazy('digitalglarus:booking_payment') # success_url = reverse_lazy('digitalglarus:booking_payment')
booking_needed_fields = ['original_price', 'final_price', 'booking_days', 'free_days', booking_needed_fields = ['original_price', 'final_price', 'booking_days', 'free_days',
'start_date', 'end_date', 'membership_required_months_price', 'start_date', 'end_date', 'booking_price_per_day',
'membership_required_months', 'booking_price_per_day',
'total_discount', 'is_free'] 'total_discount', 'is_free']
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
@ -179,11 +175,8 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
credit_card_data = last_booking_order.get_booking_cc_data() if last_booking_order \ credit_card_data = last_booking_order.get_booking_cc_data() if last_booking_order \
and last_booking_order.get_booking_cc_data() \ and last_booking_order.get_booking_cc_data() \
else last_membership_order.get_membership_order_cc_data() else last_membership_order.get_membership_order_cc_data()
# booking_price_per_day = BookingPrice.objects.get().price_per_day
# total_discount = booking_price_per_day * booking_data.get('free_days')
booking_data.update({ booking_data.update({
# 'booking_price_per_day': booking_price_per_day,
# 'current_billing_address': self.request.user.billing_addresses.first().to_dict(),
'credit_card_data': credit_card_data if credit_card_data else None, 'credit_card_data': credit_card_data if credit_card_data else None,
'stripe_key': settings.STRIPE_API_PUBLIC_KEY 'stripe_key': settings.STRIPE_API_PUBLIC_KEY
}) })
@ -197,9 +190,9 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
start_date = data.get('start_date') start_date = data.get('start_date')
end_date = data.get('end_date') end_date = data.get('end_date')
is_free = context.get('is_free') is_free = context.get('is_free')
normal_price, final_price, free_days, membership_required_months,\ normal_price, final_price, free_days = Booking.\
membership_required_months_price = Booking.\
booking_price(self.request.user, start_date, end_date) booking_price(self.request.user, start_date, end_date)
charge = None
# if not credit_card_needed: # if not credit_card_needed:
# Get or create stripe customer # Get or create stripe customer
@ -209,44 +202,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
form.add_error("__all__", "Invalid credit card") form.add_error("__all__", "Invalid credit card")
return self.render_to_response(self.get_context_data(form=form)) return self.render_to_response(self.get_context_data(form=form))
# if is_free:
# billing_address = form.save()
# # Create Billing Address for User if he does not have one
# if not customer.user.billing_addresses.count():
# data.update({
# 'user': customer.user.id
# })
# billing_address_user_form = UserBillingAddressForm(data)
# billing_address_user_form.is_valid()
# billing_address_user_form.save()
# # Create membership plan
# booking_data = {
# 'start_date': start_date,
# 'end_date': end_date,
# 'start_date': start_date,
# 'free_days': free_days,
# 'price': normal_price,
# 'final_price': final_price,
# }
# booking = Booking.create(booking_data)
# # Create membership order
# order_data = {
# 'booking': booking,
# 'customer': customer,
# 'billing_address': billing_address,
# 'amount': final_price,
# 'original_price': normal_price,
# 'special_month_price': BookingPrice.objects.last().special_month_price,
# 'membership_required_months': membership_required_months,
# 'membership_required_months_price': membership_required_months_price,
# }
# order = BookingOrder.create(order_data)
# return HttpResponseRedirect(self.get_success_url(order.id))
# If booking is not free, make the stripe charge # If booking is not free, make the stripe charge
if not is_free: if not is_free:
# Make stripe charge to a customer # Make stripe charge to a customer
@ -268,24 +223,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
# Create Billing Address for Membership Order # Create Billing Address for Membership Order
billing_address = form.save() billing_address = form.save()
# Check if user had to pay membership months in advaced
# if membership_required_months:
# # Get current user membership
# membership = Membership.get_by_user(self.request.user)
# # Create membership order
# order_data = {
# 'membership': membership,
# 'customer': customer,
# 'billing_address': billing_address,
# 'amount': membership_required_months_price,
# 'start_date': start_date,
# 'end_date': end_date
# }
# MembershipOrder.create(order_data)
# Create Billing Address for User if he does not have one # Create Billing Address for User if he does not have one
if not customer.user.billing_addresses.count(): if not customer.user.billing_addresses.count():
data.update({ data.update({
@ -315,8 +252,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
'amount': final_price, 'amount': final_price,
'original_price': normal_price, 'original_price': normal_price,
'special_month_price': BookingPrice.objects.last().special_month_price, 'special_month_price': BookingPrice.objects.last().special_month_price,
'membership_required_months': membership_required_months,
'membership_required_months_price': membership_required_months_price,
} }
order = BookingOrder.create(order_data) order = BookingOrder.create(order_data)
@ -607,15 +542,9 @@ class OrdersBookingDetailView(LoginRequiredMixin, DetailView):
original_price = booking.price original_price = booking.price
final_price = booking.final_price final_price = booking.final_price
membership_required_months = bookig_order.membership_required_months
membership_required_months_price = bookig_order.membership_required_months_price
original_price += membership_required_months_price
context.update({ context.update({
'original_price': original_price, 'original_price': original_price,
'total_discount': original_price - final_price, 'total_discount': original_price - final_price,
'membership_required_months': membership_required_months,
'membership_required_months_price': membership_required_months_price,
'final_price': final_price, 'final_price': final_price,
'booking_days': booking_days, 'booking_days': booking_days,
'free_days': free_days, 'free_days': free_days,